How to run PHP programs ?
Last Updated : 14 Apr, 2025
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.
Setting Up the Environment to Run PHP
Step 1: Download the XAMPP
Go to the official website of XAMPP and install it - XAMPP.
Step 2: Start the XAMPP Program Control Panel.
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.
XAMPPStep 3: Create the PHP File
- Place your PHP files in the "htdocs" folder located under the "XAMPP" folder on your drive.
- The initial path is "your_drive_letter:\xampp\htdocs" for your Web server.
- Make sure that your PHP files are saved as a ".php" file extension.
Now, create the file index.php inside the htdocs folder and write your below given PHP code in it.
PHP <?php echo "Hello, World!"; ?>
Open your terminal and write the below code in the terminal to run the PHP program.
php index.php
Output:
Hello World PHPRunning PHP on Local Web Server
For running the PHP on local web sever follow the below given command:
- Open XAMPP and start the Apache server.
- Write the below code in your index.php file.
PHP <?php echo "Hello geeksforgeeks"; ?>
In your browser, go to:
http://localhost/index.php
This will run your PHP script through the local server and display the output in the browser.
Output
How to run PHP programs ?Conclusion
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.
Similar Reads
How To Execute HTML Program? HTML (HyperText Markup Language) is the standard language used to create web pages. Executing an HTML program is the process of rendering the code in the browser to display a web page. There are several approaches to running HTML code each suitable for the different environments and use cases. we wi
2 min read
How to Run Process with Realtime Output in PHP? Running a process with real-time output in PHP involves using the "proc_open" function. This function provides control over the process, allowing interaction and capturing live output and errors. It's particularly useful for executing long-running tasks where immediate feedback is necessary.prerequi
1 min read
Hello World Program in Perl Perl programming language is exclusively designed for text processing purposes. Its abbreviation denotes Practical Extraction and Report Language. It is compatible on various platforms, such as Windows, Mac OS, and almost all versions of UNIX. Hello World! program in every programming language gives
3 min read
Top PHP Projects with Source Code The term PHP is an acronym for â Hypertext Preprocessor. PHP is a server-side scripting language designed specifically for web development. It is open-source which means it is free to download and use. It is very simple to learn and use. The file extension of PHP is â.phpâ. PHP was introduced by Ras
3 min read
How to run PHP code in Brackets ? Brackets is a platform where HTML, CSS, JavaScript coding can be done. Editing these types of codes is very easy in Brackets. Pre-requisite for implementing PHP codes in Brackets: Install any local server in your machine like - Wamp, Xampp, or Mamp.Install Brackets. Features: It is platform-independ
2 min read
How to Install PHP on Ubuntu? If you're working with web development on Linux, knowing how to install PHP on Ubuntu is essential. PHP is a popular server-side scripting language used to build dynamic websites, and setting it up on your Ubuntu system is simple. In this guide, we'll walk you through the steps to PHP installation o
5 min read