To run a simple PHP file, we need to set up a server because of PHP is a backend language. It also needs to set up a database/FTP clients if its a PHP project.
Running a PHP file/application on the Windows operating system is much simpler using XAMPP. It contains an apache server, Mysql database, FTP, etc.
Here we are going to discuss the steps of installation of XAMPP on Windows 10 and running a simple PHP file using it.
1. INSTALL XAMPP
XAMPP is the most popular PHP development environment.XAMPP is a completely free, easy to install Apache distribution containing MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use.
XAMPP can be easily installed using the link below.
Download the latest version (7.3.3/PHP 7.3.3).
Screenshots of the installation steps are shown below.
Now start the Apache and MySQL.
2. CREATING DATABASE (IF OUR PHP APP NEEDS A DATABASE)
This is an optional step and only need if our PHP project needs a database. Creating a MySQL database can be easily done using phpMyAdmin.
- Open the link below.
- Now Enter username and password(As a default, the username will be root password will be empty).
- Click on the New tab
- Enter a database name
It also needs to configure the database details in our PHP project.
3. PASTE/CLONE OUR PHP FILE/PROJECT TO HTDOCS DIRECTORY
htdocs is the directory that the Apache web server looks for files to serve on our domain by default. This location can be changed later to whatever value we want. But now, we have to paste/clone our PHP file or project to this directory. Default htdocs directory location is shown below.
4. RUNNING OUR PHP FILE/ PROJECT
Now its time to run our PHP file. https://localhost direct to our apache2 home page http://localhost/MyApp.php runs the MyApp.php file inside htdocs directory.
Note: As an example, I have chosen MyApp.php as a sample PHP file and MyPHPProject as a sample PHP project.
If it’s a PHP project inside a directory, change the URL path.
If our PHP project contains an index.php file in its root, It does not need to enter the file name. The below URL runs our PHP project.
Have a nice code !