How to host a Live Server and Website on your Computer Easily

How to Use “Live Server” in VS Code (From Scratch)

If you’re building a website, one of the most useful tools you can have is a “live server.” It opens your project in a browser and automatically refreshes the page every time you save a file. This saves you from having to manually reload the page after every single change.

This guide shows you how to set it all up from scratch using Visual Studio Code (VS Code).


Step 1: Install Visual Studio Code (VS Code)

If you already have VS Code, you can skip to Step 2.

  1. Go to the official website: https://code.visualstudio.com/
  2. The site will automatically detect your operating system (Windows, Mac, etc.) and show a big blue “Download” button. Click it.
  3. Once the download is finished, run the installer. The default options are fine for most users, so you can just click “Next” through the installation steps.

Step 2: Install the “Live Server” Extension

Extensions add new features to VS Code. We’ll add the one that runs our live server.

  1. Open Visual Studio Code.
  2. Look at the vertical toolbar on the far left side of the window. Click the icon that looks like four squares (this is the Extensions view).
  3. A new panel will open with a search bar at the top. Type Live Server into the search bar.
  4. The top result should be named “Live Server” and the author will be Ritwick Dey. This is the one you want!
  5. Click the blue “Install” button next to it. It will install in just a few seconds.

Step 3: Create a Project and Use Live Server

Now let’s see it in action!

  1. Create a Project Folder: On your computer (e.g., on your Desktop), create a new folder. Let’s name it my-test-site.
  2. Create an HTML File: Inside that my-test-site folder, create a new file named index.html. You can add some simple HTML to it, like this:
    <!DOCTYPE html>
    <html>
    <head>
        <title>My Live Server Test</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
    </html>
    
  3. Open the Folder in VS Code:
    • In VS Code, go to the top menu and click File > Open Folder....
    • Navigate to and select the my-test-site folder you just created.
  4. Go Live!
    • Now that your folder is open, look at the very bottom-right corner of the VS Code window. You should see a button that says “Go Live”.
    • Click it!

Your default web browser will automatically open a new tab showing your index.html page.

Step 4: See the Magic!

  1. Arrange your windows so you can see both VS Code and your browser at the same time.
  2. In VS Code, change the text inside the <h1> tag from “Hello, World!” to something else, like “Live Server is awesome!”.
  3. Save the file (press Ctrl+S or Cmd+S).

The moment you save, the web page in your browser will instantly update to show the new text without you having to do anything! This simple feature will save you tons of time and make web development much smoother.


If you have any suggestions or edits, please reply below.

And if you found this helpful, a :+1: would be much appreciated!

6 Likes

Nice! what about for php

2 Issues:

  1. I don’t know PHP
  2. PHP is server-side and HTML Is client side

So I don’t think it will work but I am probably wrong

php can run with local host….

Ai Gave me this but I don't know for sure that its accurate

Guide: How to Create a Live Server for PHP

If you’ve used the popular “Live Server” extension in VS Code for HTML/CSS projects, you might have noticed it doesn’t work for PHP files. You’ll either see the raw PHP code or get a download prompt.

This guide explains why and shows you the best ways to set up a proper local server to run your PHP projects.


Why is PHP Different?

  • HTML/CSS/JavaScript are client-side languages. The browser can read and understand them directly. A simple “live server” just sends these files to your browser as-is.

  • PHP is a server-side language. It’s a set of instructions for the server. The server must execute the PHP code first, which often involves tasks like connecting to a database or processing form data. The server then generates a final HTML document and sends that to the browser.

Because of this, you need more than a simple file server. You need a server environment that includes the PHP interpreter. Here are the two best ways for beginners to set one up.


Option 1: The VS Code Extension Method (Quick & Simple)

This method is the closest you’ll get to the “Go Live” experience and is perfect for testing single files or small projects without a database.

Prerequisite: You must have PHP installed on your computer.

If you don’t have PHP installed, this extension won’t work.

  1. Download PHP: Go to the official PHP download page: https://www.php.net/downloads.php
  2. Install/Extract it: Follow the instructions for your operating system (Windows, Mac, or Linux). For Windows, it’s often easiest to download the Zip file, extract it to a folder like C:\php, and add that folder to your system’s PATH environment variable so you can use it from anywhere.

Steps to Set Up “PHP Server” in VS Code:

  1. Open VS Code.
  2. Go to the Extensions view (the icon with four squares on the left sidebar).
  3. Search for PHP Server. Look for the one by brapifra.
  4. Click “Install”.
  5. Open your PHP project folder in VS Code.
  6. Right-click on your index.php file in the VS Code file explorer.
  7. Select “PHP Server: Serve project”.

A local server will start, and your browser will open with your PHP script running correctly! You’ll see a Server running at http://localhost:3000 message in the VS Code status bar. To stop it, just click that message.

  • Best for: Quick tests, single-file scripts, learning the basics of PHP syntax.

Option 2: The All-in-One Stack Method (Powerful & Complete)

This is the traditional and most robust method for local web development. You’ll install a single software package called XAMPP, which includes the Apache server, PHP, and the MySQL database all pre-configured to work together.

Steps to Set Up XAMPP:

  1. Download XAMPP: Go to the official Apache Friends website: https://www.apachefriends.org/index.html
  2. Install XAMPP: Run the installer. You can accept the default settings. It will install a complete web server environment on your computer.
  3. Launch the XAMPP Control Panel: After installation, open the XAMPP Control Panel.
  4. Start the Server: You will see a list of modules. Click the “Start” button next to Apache. The module name will turn green, indicating the web server is running.
  5. Find Your Web Root Folder: This is the most important step. XAMPP creates a special folder where all your web projects must be saved. Find your XAMPP installation directory, and inside it, find the folder named htdocs.
    • On Windows, this is usually C:\xampp\htdocs
    • On Mac, it’s /Applications/XAMPP/htdocs
  6. Place Your Project in htdocs: Move your entire project folder (e.g., my-php-site) inside the htdocs folder.
  7. Access Your Site in the Browser:
    • Open your web browser.
    • In the address bar, type localhost/your-project-folder-name/. For example: http://localhost/my-php-site/

Your PHP website will now be running!

  • Best for: Full projects, applications that need a database (MySQL), and simulating a real web hosting environment.

Which One Should I Use?

  • Use PHP Server (Option 1) for a quick and easy way to test a single PHP file without much setup.
  • Use XAMPP (Option 2) when you are building a real project, especially if you plan to use a database or multiple interconnected files. It’s the standard for local PHP development.

there also is a .py option

1 Like
Ai Gave me this Python but I don't know for sure that its accurate

Guide: How to Create a Live Server for Python

So you want to run a Python project on a local server? Unlike static HTML files or even PHP, Python has its own unique and powerful ways of handling this.

This guide will show you two primary methods for creating a live server with Python: one for simply viewing static files (like index.html) and another for running a true Python web application.


Why is Python Different?

Like PHP, Python is a server-side language. Your browser doesn’t understand Python code (.py files). Instead, a server must execute the Python script, which then generates a response (usually HTML) to send back to the browser.

Because of this, you need a process that can interpret and run your Python code. Fortunately, Python comes with tools to do this right out of the box!


Prerequisite: Install Python

Both methods require you to have Python installed on your computer.

  1. Download Python: Go to the official website: https://www.python.org/downloads/
  2. Run the Installer: During installation, there is one very important step: on the first screen, make sure you check the box that says “Add Python to PATH”. This will allow you to run Python from any terminal or command prompt.

Option 1: The Built-in Server (For Static Sites)

This method is the quickest way to serve a folder containing index.html, CSS, and JavaScript files. It’s the Python equivalent of the VS Code “Live Server” extension.

Important: This server does not execute your .py files. It only serves existing files from a directory.

Steps:

  1. Open a Terminal:
    • On Windows, open Command Prompt or PowerShell.
    • On Mac/Linux, open the Terminal app.
    • (Recommended) In VS Code, go to Terminal > New Terminal.
  2. Navigate to Your Project Folder: Use the cd (change directory) command to get into your project folder.
    # Example:
    cd Desktop/my-test-site
    
  3. Run the Server Command: With your terminal in the correct folder, run this simple command:
    python -m http.server
    
    (If you have an older version of Python, you might need python -m SimpleHTTPServer)
  4. Visit Your Site: The terminal will output a message like Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/). Open your web browser and go to:
    • http://localhost:8000

You will now see your index.html page! To stop the server, go back to the terminal and press Ctrl+C.

  • Best for: Quickly previewing a static website that contains an index.html file.

Option 2: The Flask Framework (For True Python Web Apps)

This is the method to use when you want your Python code to generate the website’s content. We’ll use Flask, a very popular and beginner-friendly “micro-framework” for building web applications.

Steps:

  1. Install Flask: Open your terminal and run this command to install the Flask library:

    pip install Flask
    
  2. Create Your Python App File: In your project folder, create a file named app.py (or any name you like). Paste the following “Hello, World!” code into it:

    from flask import Flask
    
    # Create a new Flask web application
    app = Flask(__name__)
    
    # Define a "route" - a URL that will trigger our Python function
    @app.route('/')
    def home():
        # This function runs when someone visits the main page.
        # It returns HTML code as a string.
        return '<h1>Hello from my Python App!</h1>'
    
    # This part runs the development server
    if __name__ == '__main__':
        # debug=True makes the server auto-reload when you save changes!
        app.run(debug=True)
    
  3. Run the Flask Server: In your terminal (make sure you’re in the same folder as your app.py file), run this command:

    python app.py
    
  4. Visit Your App: The terminal will show that the server is running, usually on port 5000. Open your browser and go to:

    • http://localhost:5000

You will see the “Hello from my Python App!” message generated by your Python code! Because we used debug=True, every time you save changes to your app.py file, the server will automatically restart, so you can just refresh your browser to see the updates.

  • Best for: Building actual web applications, creating APIs, and generating dynamic HTML content directly from Python.

Which One Should I Use?

  • Use the Built-in http.server (Option 1) if you just have an index.html file and want to see what it looks like in a browser.
  • Use Flask (Option 2) if your goal is for your .py file to run and create the web page content. This is the foundation for all modern Python web development.