Running Simple PHP File on Localhost (XAMPP)

Running Simple PHP File on Localhost (XAMPP)

How to run PHP on Localhost or in Terminal

·

2 min read

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:

  1. Download and install XAMPP on your computer.
  2. Start the Apache server and MySQL database from the XAMPP control panel.
  3. Create a new folder inside the 'htdocs' folder (usually located at C:\xampp\htdocs). This is where you will save your PHP files.
  4. Open a text editor (like Notepad++) and create a new file with the '.php' extension inside the new folder.
  5. Copy and paste the following code into the file:
<?php 
echo "Hello, world!"; 
?>
  1. Save the file as file-name.php (usually index.php) and open it in your web browser by typing localhost/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.)

how to run PHP script on localhost