How To Run PHP File On Localhost
Most articles and tutorials are written about advanced subjects. Maybe they try to be interesting but what’s popular doesn’t always mean it’s helpful.
Learning to code? 👇
Please Subscribe To My Coding Channel on YouTube.
(Publishing new tutorials almost daily.)
Every day someone new is learning how to run PHP in a browser on localhost. So I wrote this tutorial that goes over the process.
how to run php on localhost video tutorial
How To Run PHP File on Localhost In Chrome, Firefox or Another Browser (your local PC home address without having to upload files via FTP.)
- 0:00 How to run PHP on localhost on my computer / PC
- 0:08 Make sure XAmpp server is installed and already running on your PC
- 0:30 Go to C:\xampp\htdocs folder (Xampp’s localhost root folder)
- 1:05 Open index.php file you just created in VSCode (Visual Studio Code)
- 1:54 Open PHP script file in Chrome browser running on localhost
Running PHP files on localhost in address bar
If you are running PHP on a localhost server, the main index.php file will be located in the root folder. This is typically the htdocs folder in XAMPP. If you are running PHP on a remote server, the location of the index.php file will vary depending on your hosting provider.
To run a PHP script file on localhost, you will need to have a server installed. XAMPP is a popular option for this. Once XAMPP is installed, you can start the server and then navigate to the file in your web browser.
The file should have a .php extension. If it does not, you can rename it or save it as a .php file. When you access the file in your browser, the server will run the php code and display the results.
This process can be used to run php files on your local machine for testing and development purposes. It is important to note that you should not use this method for running php files on a production server. Production servers should be configured to run PHP files using the proper methods.
Running PHP scripts from Terminal (or command line)
There are a few things to keep in mind when running PHP files from the terminal or command line. First, you need to make sure that the server is running. Second, you need to know the location of the file. And third, you need to specify the path to the php interpreter.
To run a php file from the terminal or command line, you can use the following syntax:
php /path/to/file.php
This will run the php code in the file and display the results. You can also pass arguments to the php file using this syntax:
php /path/to/file.php arg1 arg2 arg3 …
You can use any number of arguments you want. Just make sure to separate them with spaces.
Oh, and one last thing…
Learning to code? 👇
Please Subscribe To My Coding Channel on YouTube.
(Publishing new tutorials almost daily.)