Running Simple PHP File on Localhost (XAMPP)
How to run PHP on Localhost or in Terminal
If you want to run PHP files on your local machine, you will need to set up a local server environment. One of the most popular ways to do this is by using XAMPP.
XAMPP is a free and open source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB, and interpreters for scripts written in the PHP and Perl programming languages.
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.
Here's how you can run PHP files on localhost using XAMPP:
- Download and install XAMPP on your computer.
- Start the Apache server and MySQL database from the XAMPP control panel.
- Create a new folder inside the 'htdocs' folder (usually located at
C:\xampp\htdocs
). This is where you will save your PHP files. - Open a text editor (like Notepad++) and create a new file with the '.php' extension inside the new folder.
- Copy and paste the following code into the file:
<?php
echo "Hello, world!";
?>
- Save the file as
file-name.php
(usuallyindex.php
) and open it in your web browser by typinglocalhost/index.php
into the address bar. You should see the words 'Hello, world!' appear on the screen.
Congratulations! You've successfully run a PHP file on localhost using XAMPP.
How To Run PHP On Localhost (on YouTube)
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 File on localhost in Chrome browser 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