How to run an HTML/PHP website on Localhost

How to run an HTML/PHP website on Localhost

ยท

3 min read

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!

Installation

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.

image

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:

Method 1

Open a File Explorer to the directory and click on the bar containing the path

image

Enter "cmd" in the bar and press enter.

image

Method 2

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.

image

Method 3

If you have Visual Studio Code installed, you can press Ctrl + ` to open a terminal within the editor.

image

Running your code on localhost

Type the command php -S localhost:8000 to run your site on port 8000.

image

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. C:\xampp\php\).

See your site live!

Go to localhost:8000 in your browser to see your site live!

image

Make sure to keep the command prompt open while you want your site to stay live!

Conclusion

If you found this useful, consider leaving a like and subscribing to my YouTube channel! ๐Ÿ˜Ž

- Jonah Lawrence

๐Ÿฆ @DenverCoder1

๐Ÿ“บ Jonah Lawrence โ€ข Dev Pro Tips