Installation Of PHP
Installing
PHP on your computer allows you to safely develop and test a web application
without affecting the live system.
To work
with PHP locally, you need to have the following software AMP
(Apache, MySQL, PHP):
- PHP
- A web server that supports PHP. We’ll use
the Apache
webserver.
- A database server. We’ll use the MySQL
database server.
Typically,
you won’t install all this software separately because connecting them is
tricky and not intended for beginners.
There are many AMP
options available in the market that are given below:
- WAMP for Windows
- LAMP for Linux
- MAMP for Mac
- SAMP for Solaris
- FAMP for FreeBSD
- XAMPP (Cross, Apache, MySQL, PHP, Perl) for Cross Platform: It
includes some other components too such as FileZilla, OpenSSL, Webalizer,
Mercury Mail, etc.
XAMPP is an easy install Apache distribution that contains PHP, MariaDB, and Apache webserver. XAMPP supports Windows, Linux, and macOS.
If you are on Windows and don't want Perl and other features of
XAMPP, you should go for WAMP.
Why Do You Need a Local Server?
PHP needs to be run on a server. Since we are working locally (on your own computer), we need a local server environment like XAMPP, WAMP, or MAMP. These bundles provide everything you need to run PHP, including the Apache web server and MySQL database.
Choosing Between XAMPP, WAMP, and MAMP
XAMPP works on Windows, macOS, and Linux, making it the most versatile choice.
WAMP is designed specifically for Windows users.
MAMP is tailored for macOS users, though it also has a Windows version.
All of these software packages are free and relatively easy to install.
Download XAMPP
To
install XAMPP on windows, you can go to the XAMPP official website and download the suitable version for your
platform.
Install XAMPP on Windows
To
install XAMPP on Windows, you can follow these steps:
Step 1. Start the
installation
Double-click
the downloaded file to start setting up XAMPP:
Step 2. Select components
to install
Select
the components that you want to install. In this step, you can select Apache,
MySQL, PHP, and phpMyAdmin, deselect other components like the following, and
click the Next button to go to the next step.
Step 3. Specifying the
installation folder
Select
a folder to install XAMPP. It’s recommended to install XAMPP in the c:\xampp
folder. Click the Next button to go to the next step.
Step 4. Selecting a language
Select
a language for XAMPP Control Panel. By default, it’s English. And you can
select your preferred language and click the Next button to go to the next
step.
Step 5. Bitnami for XAMPP
Feel
free to skip this step because you don’t need Bitnami for learning PHP. Just
click the Next button to go to the next step.
Step 6. Begin installing
XAMPP
And
you’re now ready to install XAMPP. Click the Next button to start the
installation. It’ll take a few minutes to complete.
Step 7. Completing the
XAMPP setup
Once
completed, the XAMPP setup wizard shows the following screen. You can click the
Finish button to launch the XAMPP Control Panel:
Step 8. Completing the
XAMPP setup
The
XAMPP Control Panel lists installed services. To start a service, you click the
corresponding Start button:
The
following shows the Apache web server and MySQL are up and running. The Apache
web server listens on the ports 80 and 443 while the MySQL listens on port
3306:
Step 9. Launch the XAMPP
Open
the web browser and navigate to the following URL: http://localhost/. If the
installation is completed successfully, you’ll see the welcome screen of the
XAMPP.
Troubleshooting
By default,
Apache uses port 80. However, if port 80 is used by another service, you’ll get
an error like this:
In this case, you need to change the port from 80 to a free one, e.g., 8080. To
do that, you follow these steps:
First,
click the Config button that aligns with the Apache module:
Second,
find the line that has the text Listen 80
and
change the port from 80
to 8080
like this:
Third,
click the Start button to start the Apache service. If the port is free, Apache
should start properly, as shown in the following picture:
Starting XAMPP:
After installation, launch the XAMPP Control Panel.
Click on Start next to Apache (for the server) and MySQL (for the database).
Ensure both services turn green, indicating that they are running.
If the services turn red , indicating that they are not running.
Verify Installation:
Open a web browser and type http://localhost/. If everything is set up correctly, you should see the XAMPP dashboard.