PHP and MySQL (56 Blogs) Become a Certified Professional

How to run a PHP program in Xampp?

Last updated on Jul 23,2024 265.6K Views

Aayushi Johari
A technophile with a passion for unraveling the intricate tapestry of the... A technophile with a passion for unraveling the intricate tapestry of the tech world. I've spent over a decade exploring the fascinating world of...
How to run a PHP program in Xampp?

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- how to run php program in xampp - EdurekaXampp is the most popular PHP development environment for Windows, OS X, and Linux platforms.

Xampp stands for Cross platform(x), Apache(a), Maria db(m), PHP(p), Pearl(p) which is a software distribution server which makes developer’s work eaiser for testing and deploying by creating a local web server.

 

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.

Xamp - how to run php program - Edureka

Select the installation directory so that all the components that you choose will be installed in this directory.

Xamp Installation - how to run php program - Edureka

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.

case sensitivity in PHP example 1

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.

Hello Anupam!

Let’s consider another example

case sensitivity in PHP example 2

Since variable names are case sensitive.
Therefore, $color, $ColoR, and $COLOR are treated as different variables.
Hence, it throws an error when executed.

variable names

In order to correct this error, you should use the same case for the variable name throughout the script.

correct

Here, the same variable name $color is used throughout the script.

same variable name
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

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!"; ?>

Hello Anupam! code

3. Save the file with .php extension

4. In this case we’re saving it by the name Anupam.php

save by Anupam.php

5. Once XAMPP is installed, we’ll be using it to start/stop the required servers

start/stop the required servers

6. Start the Apache and MySQL servers

Apache and MySQL servers

7. Navigate to the htdocs directory (C:xampphtdocs)

htdocs directory

8. Move the PHP file we’ve created before to the htdocs directory.

PHP file

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.

Demonstration folder

11. Open a browser of your choice like Chrome

browser

12. Navigate to http://localhost to access the localhost dashboard.

localhost

13. Navigating to 127.0.0.1 does the same

127.0.0.1

14. To run your PHP script, search http://localhost/Demonstration/Anupam.php in the address bar.

address bar

15. Wallah! Your script is successfully executed.

script

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. 

Comments
1 Comment

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How to run a PHP program in Xampp?

edureka.co