PHP is the most popular web backend programming language. A PHP code will run as a web server module or as a command-line interface. To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL. There are various web servers for running PHP programs like WAMP & XAMPP. WAMP server is supported in windows and XAMP is supported in both Windows and Linux. In this article, you will learn how to run PHP program in Xampp server.
Below topics are covered in this article:
Let’s get started.
What is Xampp and why it is used?
Xampp is the most popular PHP development environment for Windows, OS X, and Linux platforms.
How to install Xampp?
It is completely free and easy to install Apache distribution containing MySQL, PHP, and Perl. First, download XAMP from https://www.apachefriends.org/download.html. In the first page, select the components you want to install.
Select the installation directory so that all the components that you choose will be installed in this directory.
XAMP also allows you to easily install PHP based applications. Bitnami module provides the easiest way to install WordPress, Drupal or Joomla among others on top of your XAMP after the installation you will see the control panel.
PHP Case Sensitivity
PHP is a case sensitive language and it might be confusing for some of you.
Variable names are case sensitive whereas Function names, Class names and Keywords (e.g., if, else, while, echo, etc) are not case sensitive in PHP.
Let’s discuss the case sensitivity in PHP with some examples.
Consider the following example.
Since, the echo statement is not case-sensitive.
Therefore, echo, ECHO, and EcHo have the same functionality.
Hence, they print Hello Anupam! three times without throwing any error.
Let’s consider another example
Since variable names are case sensitive.
Therefore, $color, $ColoR, and $COLOR are treated as different variables.
Hence, it throws an error when executed.
In order to correct this error, you should use the same case for the variable name throughout the script.
Here, the same variable name $color is used throughout the script.
Hence, it will print the desired output successfully.
How to run PHP program in Xampp step-by-step?
1. Open a text editor like Notepad
2. Write your PHP script in the notepad.
For reference you can use the below script or use your own PHP script as well.
<?php echo "Hello Anupam!"; ?>
3. Save the file with .php extension
4. In this case we’re saving it by the name Anupam.php
5. Once XAMPP is installed, we’ll be using it to start/stop the required servers
6. Start the Apache and MySQL servers
7. Navigate to the htdocs directory (C:xampphtdocs)
8. Move the PHP file we’ve created before to the htdocs directory.
9. You can also create new folders inside the htdocs directory to organize your code in a better way.
10. In this case we’re creating a new folder named Demonstration and will be moving the Anupam.php script inside this folder.
11. Open a browser of your choice like Chrome
12. Navigate to http://localhost to access the localhost dashboard.
13. Navigating to 127.0.0.1 does the same
14. To run your PHP script, search http://localhost/Demonstration/Anupam.php in the address bar.
15. Wallah! Your script is successfully executed.
This concludes this article. I hope you have learned about XAMP, how to install it, and how to run a PHP program in Xampp.
FAQs
1. How to run PHP code?
Save your PHP code in a file with .php extension and run/host it on localhost using web servers like Apache. The PHP CLI can also be used for the same.
2. How to run PHP with command?
We can use the php command followed by the file name to run the PHP script on command line.
php <file_name.php>
3. How to run PHP in Chrome?
Use local web servers to host the PHP file. It can be accessed using http://localhost/<file_name.php> on the Chrome browser. Examples of local web servers are XAMPP or WAMP.
4. What can I use to run PHP?
Use web servers with a PHP interpreter. XAMPP, WAMP, and MAMP can be used, as they include both the web server and PHP. The PHP CLI can also be used for the same.
If you want to start a career in the Node JS Field then check out the Node JS Online Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.
Got a question for us? Please mention it in the comments section of ”how to run a php program in xampp” and I will get back to you.
so good my bro i am so grateful