PHP Installation
September 19, 2018
We’re finally here!
But first, let us tell you what PHP is. PHP stands for Hypertext Preprocessor (no, the acronym doesn’t follow the name!). It is an open source, server-side, scripting language used for the development of web applications.
Let’s see what each of these terms mean:
- Open source: PHP is open source, that is, the software source code is made freely available to everyone. Moreover, anyone is allowed to create their own modified versions or redistribute the software.
- Server-side: PHP is primarily used in web applications, where server-side is the owner of the website and client-side is the user who is accessing the website. For example, if you’re on facebook.com, the servers are computers owned by Facebook, and the client is your browser (Chrome / Firefox / etc). PHP is a server-side language means if Facebook has PHP on their site, you can’t see the PHP code. The code executes on Facebook’s servers, and the client (you) only sees the result after the code has run.
PHP is powerful enough to be at the core of the biggest blogging system on the web (Wordpress) and run the largest social network (Facebook)! It is also easy to learn and you will be able to start coding in PHP in no time.
PHP installation
Let’s start by installing PHP! We need 3 things in order to start using PHP:
- Apache Web Server
- PHP 7
- MySQL
Luckily, we can use XAMPP, which is an open source package that will install all of these with just a single setup. Below, you can find the installation instructions for Windows, Mac and Linux.
Windows
You can download the XAMPP package for Windows from the website: XAMPP Installers and Downloads for Apache Friends
Installing XAMPP
Run the installer. The installation is fairly straightforward. Make sure to select Apache, MySQL, PHP and phpMyAdmin as shown. Other components are optional and can be installed later on as well. (You can uncheck the “Learn more about BitNami for XAMPP” if you’re not interested in it.)
Running the Server and MySQL
After the installation, browse to the path where XAMPP was installed (By default located in C:\xampp\
) and double-click on xampp-control.exe
. Start the Apache and MySQL services.
Verifying the Set-up
To verify if the that the installation was successful, open a web browser (such as Google Chrome / Firefox / etc) and go to http://localhost/
. If you see a XAMPP Welcome page similar to the one below, then everything has been installed successfully.
Mac OS / OS X
You can download the XAMPP package for OS X from the website: XAMPP Installers and Downloads for Apache Friends
Installing XAMPP
Double click on the installer to run it. Make sure ‘XAMPP Developer Files’ in the Select Components window’ is checked and complete the installation process. You can leave all of the options at their default settings. (You can uncheck the “Learn more about BitNami for XAMPP” if you’re not interested in it.)
Running the Server and MySQL
After the installation, browse to the path where XAMPP was installed (By default located in /Applications/XAMPP/
) and double-click on it. (Note: For many people, typing XAMPP in the LaunchPad doesn’t work. You’ll need to go to Applications
and then double click XAMPP
. From the second time onwards, you can use the LaunchPad).
In the General
tab, click on the Start
button.
It might take a couple of minutes for the XAMPP stack to start. You can check the Log
tab to see the status. Once the XAMPP stack is successfully started, go the the Services
tab and start MySQL
and Apache
.
Again, check the Log
tab if all the services have started successfully.
Now go the Volumes
tab and click on Mount
.
Open Finder. See the IP address in the Sidebar below Shared
(in this case 192.168.64.2
). Click on it and you will find the lampp
folder. This is the folder where the files are stored. In particular, locate the htdocs
folder (you’ll need it once you start writing code).
Verifying the Set-up
To verify if the that the installation was successful, open a web browser (such as Google Chrome / Firefox / etc) and go to http://192.168.64.2/
(if your IP address was different, the replace it with the one you got).
Then, go to http://192.168.64.2/phpmyadmin/
(again, if your IP address was different, the replace it with the one you got). You should see a page similar to the following:
If you see a XAMPP Welcome page and the phpMyAdmin page similar to the ones above, then everything has been installed successfully. Your setup is complete. You can proceed to the next tutorial and start learning PHP.
If instead you see an error saying:
New XAMPP security concept:
Access to the requested object is only available from the local network.
This setting can be configured in the file "httpd-xampp.conf".
then follow the steps below.
Granting access to phpMyAdmin
To enable access from non-localhost, open the lampp/etc/extra/httpd-xampp.conf
file. In the file, you will see these lines somewhere in the middle of the file:
LoadModule perl_module modules/mod_perl.so
Alias /phpmyadmin "/opt/lampp/phpmyadmin"
# since XAMPP 1.4.3
<Directory "/opt/lampp/phpmyadmin">
AllowOverride AuthConfig Limit
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Comment the LoadModule perl_module
line (add #
to the beginning of the line). Also comment the Require local
line, and add the following lines above it:
Order allow,deny
Allow from all
Require all granted
After all the changes, this is what the lines should look like:
# LoadModule perl_module modules/mod_perl.so
Alias /phpmyadmin "/opt/lampp/phpmyadmin"
# since XAMPP 1.4.3
<Directory "/opt/lampp/phpmyadmin">
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all
Require all granted
# Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Save the file. Then, restart your XAMPP server. That is, to go the General
tab on XAMPP and click Stop
. Then, press Start
, go to the Services
tab, and Start
all three services, and finally go to the Volumes
tab and Mount
the volume.
Verify phpMyAdmin loads
Again, go to http://192.168.64.2/phpmyadmin/
(if your IP address was different, the replace it with the one you got). You should see a page similar to the following:
You will see a phpMyAdmin page similar to the one above. Your setup is complete. You can proceed to the next tutorial and start learning PHP.
Linux
You can download the XAMPP package for Linux from the website: XAMPP Installers and Downloads for Apache Friends.
Installing XAMPP
Choose your flavor for your linux OS, the 32-bit (use x86
) or 64-bit (user x64
) version. Open the terminal and change the permissions to the installer:
chmod 755 xampp-linux-*-installer.run
Here, replace *
with x86
or x64
depending on the version you downloaded. Run the installer:
sudo ./xampp-linux-*-installer.run
That’s all. XAMPP is now installed below the /opt/lampp
directory.
Running the Server and MySQL
Start the XAMPP service from the terminal by using the command:
sudo /opt/lampp/lampp start
You should now see something like this on your screen:
Starting XAMPP 1.8.2...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.
Ready. Apache and MySQL are running.
Also, note that there is a graphical tool that you can use to manage your servers easily. You can start this tool with the following commands:
cd /opt/lampp
sudo ./manager-linux.run (or manager-linux-x64.run)
To set XAMPP to start when Linux boots,
- Open the terminal and type
sudo gedit /etc/rc.local
- Add this line before exit 0.
/opt/lampp/lampp/start
- Save and close the
rc.local
file.
Verifying the Set-up
To verify if the XAMPP installation was successful on your operating system, open a web browser (such as Google Chrome / Firefox / etc) and go to http://localhost/
. If you see a XAMPP Welcome page similar to the one below, then everything has been installed successfully.
Congratulations!
Now we can finally start with PHP programming! Congratulations!