The most widely used web backend programming language is PHP. A PHP script can be executed through a web server module. Installing a web server like Apache and a database server like MySQL is required to execute PHP for the web. Linux and Windows OS may use XAMPP server to run PHP code as localhost.
You will discover how to launch a PHP program on the XAMPP Server in this article.
What is XAMPP, and Why is it used?
XAMPP is an open-source web server solution package. It is the most popular PHP development environment for Windows and Linux OS platforms. It is mainly used for web application testing on a localhost web server.
XAMPP stands for:
X = Cross-Platform.
A = Apache Server.
M = MariaDB.
P = PHP.
P= Perl.
Now that you better understand the XAMPP Software, let's move on to installation.
Let's start with installing XAMPP and running the first PHP program using the XAMPP server on localhost.
Download and install XAMPP
Download and install XAMPP from the Apache friends website (https://www.apachefriends.org/index.html). Choose the appropriate version for your operating system.
Select XAMPP for Windows -> It will download automatically after few seconds.
Once completing the download of the setup file, begin the installation process and, in the "Select Components" section, select all the required components. -> Click next.
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.
Now that the installation is completed let's see how to run a PHP script.
Create a new project in XAMPP
Go to the htdocs folder in the XAMPP folder and create your project folder (C:/Program Files/XAMPP/htdocs).
or
You can copy your php project to htdocs folder (C:/Program Files/XAMPP/htdocs).
Inside the demo folder, Create a new file with a .php
extension. You can use any text editor, such as Notepad or Sublime Text. For example, create a file named kisorjandemo.php
(The file name created is an example only; you can create the file name as per your preference).
Write PHP code
Open the hello.php file and add the following PHP code:
Open XAMPP and run your first PHP program
Go to the start button, and type Xampp Server to open it.
This will open Xampp Server- Control Panel. After opening it, just click Start on Apache to start the server:
Access the PHP file
Open your web browser and navigate to http://localhost/kisorjanphpproject/kisorjandemo.php. This URL corresponds to the htdocs directory of your XAMPP installation. If everything is set up correctly, you should see the output "Hello, Kisorjan!Welcome to the World!" on the webpage.
That's it! You have successfully run your first PHP program using XAMPP Server on localhost. You can continue writing more complex PHP code and accessing it through the http://localhost URL.
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.
If you have any questions regarding the "PHP using XAMPP" tutorial, please ask away in the comments section of this article, and I'll answer them for you.
Happy Learning!