How to Run a PHP Using XAMPP | Simplilearn (2024)

PHP is the most popular and widely-used server-side scripting language for web development. However, it requires a webserver to run even a locally developed webpage. There are various web server software for setting up our local webserver. Amongst them, PHP XAMPP and WampServer are the most popular. While WampServer is only available for the Windows platform, XAMPP is a cross-platform application that can run on Windows, Linux, and macOS. Hence, in this tutorial, you will learn PHP using XAMPP.

What Is PHP?

PHP (Hypertext Protocol) is Open Source Programming Language used to make web pages. PHP language can run on various platforms and is compatible with almost all servers. PHP files use .php as their extension. PHP can perform functions, like from files on a system it can create, open, read, write, and close them. You can add, delete, and modify elements within your database with the help of PHP. You can restrict users from accessing some pages of your website using PHP. PHP can encrypt data too.

Get the Coding Skills You Need to Succeed

Full Stack Developer - MERN StackExplore Program

How to Run a PHP Using XAMPP | Simplilearn (1)

Advantages Of PHP

Web-Developers use many other languages, but most prefer using PHP because of its advantages. Some advantages of PHP are:

  1. Simple and easy to learn - PHP is known as the easiest Scripting language as it doesn't have intensive studying. Commands are very easy to understand for new learners and developers too.
  2. Compatible - PHP language is compatible because it can run on many operating systems. It can easily run on platforms like Windows, LINUX, and UNIX.
  3. Flexibility - PHP language is very flexible for developers because it allows you to change the existing or completed project.
  4. Less Costly - As PHP is an open-source language, you can download it for free. You don't have to purchase any license or software.
  5. MVC Pattern - Model-View-Controller Pattern in PHP helps you organize codes.
  6. Loading Time - PHP is faster than other programming languages. It can be loaded when your network connection is slow.
  7. Library Support - PHP also has a collection of many, many advanced written codes that you can use repeatedly. And also use it whenever you want to run a program.

How to Set Up and Install PHP for Your Project?

Step 1: Find a web server that supports PHP and MYSQL.

Step 2: Then install PHP from its website.

Step 3: Then install MYSQL DB on your PC.

What is XAMPP?

XAMPP is an open-source web server solution package. It is mainly used for web application testing on a local host webserver.

XAMPP stands for:

X = Cross-platform

A = Apache Server

M = MariaDB

P = PHP

P = Perl

Now that you have a better understanding of the XAMPP software, let us move on to its installation.

Why Do You Need XAMPP?

To run any PHP program, you will need Apache or MYSQL databases, both supported by XAMPP. XAMPP helps you to run your program smoothly.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program

How to Run a PHP Using XAMPP | Simplilearn (2)

How to Install XAMPP?

Apache friends developed XAMPP, and it is available for everyone free of cost.

You can download XAMPP through the official website, https://www.apachefriends.org/download.html.

On completing the download of the setup file, begin the installation process and, in the “Select Components” section, select all the required components.

How to Run a PHP Using XAMPP | Simplilearn (3)

Next, select the directory where you want the software to be installed. It is recommended that you keep the default directory “C:\xampp” and click on “next” to complete the installation.

How to Run a PHP Using XAMPP | Simplilearn (4)

Now that the installation is complete, let’s move ahead to see how to run a PHP script using the same.

How to Start a New PHP Project in XAMPP?

  • Before you run or start writing any program in PHP, you should start Apache and MYSQL.
  • After starting both servers, you have to write a program in Notepad.
  • After writing it, save that file as "program.php".
  • Then copy that file program.php to C:/Program Files/XAMPP/htdocs.
  • Open the browser and type http://localhost.
  • Now run your code in that browser.

Preparing Your Blockchain Career for 2024

Free Webinar | 5 Dec, Tuesday | 9 PM ISTRegister Now

How to Run a PHP Using XAMPP | Simplilearn (5)

How to Run a PHP Code Using XAMPP?

Before running a PHP script, you must know where to write it.

In the XAMPP directory, there exists a folder called “htdocs”. This is where all the programs for the web pages will be stored.

Now, to run a PHP script:

1. Go to “C:\xampp\htdocs” and inside it, create a folder. Let’s call it “demo”. It’s considered good practice to create a new folder for every project you work on.

How to Run a PHP Using XAMPP | Simplilearn (6)

2. Inside the demo folder, create a new text file and name it “index.php” and write the following script.

How to Run a PHP Using XAMPP | Simplilearn (7)

3. Now, to see the script output, open the XAMPP control panel and start Apache to host the local webserver, where our script will be running.

How to Run a PHP Using XAMPP | Simplilearn (8)

4. Now navigate to your browser and type in “localhost/demo/” in the address bar to view the output.

How to Run a PHP Using XAMPP | Simplilearn (9)

Congratulations, with this, you have created a PHP file and also executed the program successfully.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program

How to Run a PHP Using XAMPP | Simplilearn (10)

Conclusion

This concludes the tutorial. In this “PHP using XAMPP” tutorial, you looked into why you need XAMPP, what XAMPP is, how to install XAMPP, and finally, how to run your first PHP script on it.

Are you planning to take the plunge and do a course on PHP? In that case, Simplilearn’s PHP course would be an excellent choice. The Post Graduate Program in Full Stack Web Development covers all the fundamental and advanced concepts, making your journey towards learning PHP an easy one.

If you have any questions regarding the “PHP using XAMPP” tutorial, please ask away in the comments section of this article, and we’ll have our experts answer them for you.

Happy Learning!

FAQs

1. How to run a PHP file in localhost XAMPP?

Create any project, for e.g., <?php

echo 'Hello, this is PHP.'

?>

Then run it at http://localhost.

2. Can we run PHP in XAMPP?

Yes, you can run PHP in XAMPP. First, start the XAMPP server, create a program you want to and run it at http://localhost.

3. How do I run my PHP file?

PHP files are saved in C:/Program Files/XAMPP/htdocs. You have to open it, click on the program, and it will automatically run on localhost.

4. How to run PHP files in phpMyAdmin?

  • Login into PHPMyAdmin, then click on the import tab.
  • Browse the file with a .sql extension.
  • Keep in mind to check and uncheck some options.
  • Choose SQL format and click on Go.
How to Run a PHP Using XAMPP | Simplilearn (2024)

FAQs

How to Run a PHP Using XAMPP | Simplilearn? ›

Generally, a PHP file contains HTML tags and some PHP scripting code. It is very easy to create a simple PHP example. To do so, create a file and write HTML tags + PHP code and save this file with .php extension.

How to run a PHP program with XAMPP? ›

Generally, a PHP file contains HTML tags and some PHP scripting code. It is very easy to create a simple PHP example. To do so, create a file and write HTML tags + PHP code and save this file with .php extension.

How to run a PHP file using localhost? ›

If you create a specific folder then you need to use the address as “localhost/foldername” to open them in your browser. Example: The “demo.php” file is placed inside the “gfgdemo” folder. Enter “localhost/gfgdemo/demo.php” in your browser and press enter, your program will be run.

How to run simple PHP? ›

Running a PHP File in Visual Studio Code
  1. Step 1: Install a Local Server. Before running a file in Visual Studio Code, it's essential to have a server for PHP development to simulate a web server environment. ...
  2. Step 2: Start the Server. ...
  3. Step 3: Open the PHP File in VS Code. ...
  4. Step 4: Run the File. ...
  5. Step 5: View Output.
Feb 14, 2024

How to execute a PHP file? ›

Executing PHP files ¶
  1. Tell PHP to execute a certain file. $ php my_script.php $ php -f my_script.php. ...
  2. Pass the PHP code to execute directly on the command line. $ php -r 'print_r(get_defined_constants());' ...
  3. Provide the PHP code to execute via standard input ( stdin ).

How to run PHP code in browser? ›

Navigate to "localhost:8888" in your browser's address bar. The address bar is where you normally see "https://www." To do this, type "localhost:8888" and press ↵ Enter (Windows) or ⏎ Return (Mac). You'll see a directory of your PHP files displayed on the page. Click the PHP file to run the script in your browser.

How to run a PHP server? ›

Starting a PHP Server
  1. Install PHP on Your Computer. If you haven't already, download and install PHP on your computer. ...
  2. Create a PHP File. Create a new file with the . ...
  3. Open a Command Prompt. ...
  4. Navigate to the Directory With the PHP File. ...
  5. Start the PHP Server. ...
  6. Test the Server. ...
  7. Stop the Server.
Mar 18, 2024

How to open a PHP file in a browser with XAMPP? ›

  1. Save the PHP File: Save the PHP file in the directory inside the XAMPP installation folder. ...
  2. Access the PHP File: Open your web browser and enter the following URL: ', where ' is the name of your PHP file. ...
  3. View Output: The PHP file will be executed, and you will see the output in your web browser.
Oct 13, 2023

What can I use to run PHP? ›

To run PHP for the web, you will need to install a web server like Apache and a database like MySQL – and both are supported by XAMPP. XAMPP is a local server that can run smoothly on our personal computer, and is accepted in both Windows and Linux.

Does PHP run in browser? ›

You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming.

How to open Xampp in browser? ›

You have an 'Admin' option located on the Control Panel for every module in your XAMPP. Click on the Admin button of your Apache server to go to the web address of your web server. The Control Panel will now start in your standard browser, and you'll be led to the dashboard of your XAMPP's local host.

How to run a PHP HTML file? ›

You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <? php and the PHP end tag ?>. The code wrapped between these two tags is considered to be PHP code, and it will be executed on the server side before the requested file is sent to the client browser.

How to run a PHP program in terminal? ›

You just follow the steps to run PHP program using command line.
  1. Open terminal or command line window.
  2. Goto the specified folder or directory where php files are present.
  3. Then we can run php code using the following command: php file_name.php.
Mar 7, 2024

How to login PHP using XAMPP? ›

How to run the login form?
  1. To run the login form, open the xampp control panel and run the apache server and PHP.
  2. Now, type localhost/xampp/folder name/file name in the browser and press Enter key.
  3. All setup is done now. Enter the username and password in the login form and click the login button.

How to use XAMPP control panel for PHP? ›

The user can initiate or halt discrete modules by operating upon the buttons below the "Actions" column. Control panels efficiently manage all the components of the XAMPP package. Go to All Programs → Apache Friends → XAMPP → XAMPP Control Panel. In case it's already in running state, you will receive an Error!

Top Articles
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 5888

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.