In this tutorial, I'm going to show you how to run your website locally with XAMPP. This is especially useful when writing PHP since you will be able to test your site without putting it on a web server!
The first thing you'll need to do is install PHP. My preferred way of doing that is by installing XAMPP from https://www.apachefriends.org.
Click the download button for your operating system to get the latest version.
Once it's finished installing, you should be able to access all of the PHP features from your command line.
Open a command prompt in your working directory
You'll need to open a command prompt in the directory containing your root directory or index file.
There are a few ways to do that on Windows:
Open a File Explorer to the directory and click on the bar containing the path
Enter "cmd" in the bar and press enter.
Open a command prompt by searching for the application "Command Prompt" or "Terminal".
Run the "change directory" command by typing
cd followed by the path of your project.
If you have Visual Studio Code installed, you can press Ctrl + ` to open a terminal within the editor.
Running your code on localhost
Type the command
php -S localhost:8000 to run your site on port 8000.
Note: If you get an error that 'php' is not recognized, you likely will need to add it to your path manually. To do that, locate
php.exe(for me it is in the directory
C:\xampp\php\). Search for "Edit system environment variables", at the bottom of the window that comes up, click "Environment variables", then click the row for "Path" and click the "Edit..." button. Add a row containing the directory you found earlier (ex.
See your site live!
Go to http://localhost:8000/ in your browser to see your site live!
Make sure to keep the command prompt open while you want your site to stay live!
If you found this useful, consider leaving a like and subscribing to my YouTube channel! 😎
- Jonah Lawrence
Top comments (0)