![]() |
VOOZH | about |
PHP (Hypertext Preprocessor) is a popular server-side scripting language primarily used for web development. It is designed to generate dynamic web pages and interact with databases. Running PHP programs involves setting up a development environment, whether locally or on a live server.
In this article, we'll discuss how to run PHP programs on your local machine and on a web server.
Step 1: Download the XAMPP
Go to the official website of XAMPP and install it - XAMPP.
Click on the "Start" button next to the "Apache" to start your Apache Web Server. Also, start "MySQL" if your PHP programs depend on a MySQL database to run.
Now, create the file index.php inside the htdocs folder and write your below given PHP code in it.
Open your terminal and write the below code in the terminal to run the PHP program.
php index.phpOutput:
For running the PHP on local web sever follow the below given command:
In your browser, go to:
http://localhost/index.phpThis will run your PHP script through the local server and display the output in the browser.
Output
To run PHP programs, you need to set up a suitable environment, either locally or on a live web server. For local development, you can install server packages like XAMPP, WAMP, or MAMP, which provide PHP, Apache, and MySQL in one installation. Once set up, you can create PHP files with a .php extension and place them in the server's root directory (e.g., htdocs for XAMPP). After starting the server, you can access the PHP file in your browser using http://localhost/filename.php.