Getting VS Code ready for PHP

The following steps will walk the learner through how to setup VS Code to work with PHP scripting. Follow the steps closely as you are dependant on them to work.

Step 1 - Install PHP

Go to and download the zip file shown .
PHP Download link

Then upzip the package to a location you know. A good example of a location would be c:\php8 or d:\libraries\php8.
It is not recommended to do this in "My Documents" or the Desktop as they have certain properties which may prevent PHP from running today, or may break it in the future.

Setup the Environment Variables

The environment variables on your system are like constants in your code, but for windows in this case. It tells windows the values to use when doing things, like the path to certain programs when you run them etc.

  1. copy the path to the clipboard, where you extracted the PHP downloaded files.
     
  2. from the start menu, type "path" and then select "Edit the System Environment Variables"
     
  3. click on the "environment variables" button near the bottom.
     
  4. Under the variables section, find the record called "path" and choose to edit it.
     
  5. Windows 10 only
    - at the end of any existing path, paste the clipboard path
     
    Windows 11 only
    - click the "New" button and paste the path stored in the clipboard.
     
  6. Click "OK" twice to exit the environment variables screens.
     

Note: You may have to reboot your computer for the new path to take effect. If things do not work, rebooting your computer is your first troubleshooting task.

Step 3 - Install VS Code Extensions

Make sure you close all running copies of VS Code and reload one before proceeding. VS Code will not find PHP until you restart it.

In VS Code, under the extensions area, search for "Code Runner" and find the extension of the same name by Jun Han and install it.

also install the following extensions:

PHP Server by bapifra

PHP Intelephense by Ben Mewburn

Step 4 - Create your first PHP file.

In order to create your first file, let us be in a new folder on your computer. So:

  1. open an empty folder in VS Code.
  2. create a new file called index.php
  3. add the following code and save it:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Test PHP File</title>
    </head>
    <body>
        <-- this is server-side script -->
        <h1>Hello: <?php echo "Hello World! Clint"; ?></h1>
        <p>Math: 4 * 5 is <?php echo 4 * 5; ?> </p>
    
        <-- this is client-side script -->
        <h1 style="color: green;" 
            onmouseover="style.color='red'"
            onmouseout="style.color='blue'">
            Test Mouse Over
        </h1>
    </body>
    </html>
                        
  4. Once you save your php file, right click on the code and choose: "PHP Server: Server Project"
    Server Project

If your browser shows something like:
Test Screen Shot

PHP is now installed and ready to run on your computer.