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.
Go to and download the zip file shown .
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.
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.
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.
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
In order to create your first file, let us be in a new folder on your computer. So:
index.php
<!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>
If your browser shows something like: