About PHP

PHP is the most widely used programing language, for the server side, on the web. It started as a project covered by the GNU General Public License (GPL), which allowed it to evolve into what it is today. It is straight forward and simple to learn. Widely supported, with numerous programing examples, and has a good collection of libraries for rapid application development. Most web hosts have it installed already on the servers they rent out. Along with the MYSQL database, which works with it seamlessly for building database driven applications. If you were building a new web project, you may want to consider PHP. Successful online businesses, such as Facebook and Yahoo, have used it to change the world.

Using PHP

PHP helps web developers build dynamic content that query databases. To get started using PHP, you need basic knowledge of the internet, understanding of computer programming, databases and MYSQL. To use PHP you will need other software packages which, when installed along with it, enables a server computer host dynamic applications. The entire group of sotware packages is called the LAMP stack (a suit of open source software with PHP included). Its actually an acronym, which spells out Linux (the operating system), Apache (the web server), MYSQL (the database, currently MariaDB as the open source version) and PHP (the dynamic content processor).

To get up and running, we will need the following prerequisites :

» A linux server plan having CentOS 7

» A non-root user having sudo privileges to gain admin rights.

Step 1: Update the OS

Before commencing the installation, make sure CentOS 7 server is up to date, by executing the following Linux command:

 $ sudo yum update  

Step 2: Install Apache

We will keep using the yum package manager, to install all the software we need on CentOS 7. To install apache run the following command:

 $ sudo yum install httpd  

When the prompt, requests that we confirm the install, press Y and Enter to proceed.

We start the apache service by running the following command :

 $ sudo systemctl start httpd.service 

With the service online, you can access your website using your server's public IP address, to get the default apache page. That shows apache was installed successfully on centOS 7 server.

Next, using the command below, you activate Apache to start during system boot:

 $ sudo systemctl enable httpd.service  

Step 3: Install MySql (MariaDB) database.

MariaDB is a fork in the development lifecycle of MySql, which has remained free under the GNU General Public License (GPL). This was done before MySql was aquired by Oracle.

MariaDB can be installed together with all additional packages needed on our CentOS server, by running the following command below:

 $ sudo yum install mariadb-server mariadb  

When the prompt, requests that we confirm the install, press Y and Enter to proceed.

After MariaDB has been fully installed, run the command below to start the service :

 $ sudo systemctl start mariadb  

Step 4: Securing MariaDB

MariaDB is not secure by default, anonymous user has to be removed and the database tested and configured :

 $ sudo mysql_secure_installation  

The server prompt will request your current root password. Leave this blank by pressing enter, as you wont have a password at this point. The sever prompt will then ask if you want to set a root password, press Y and Enter to proceed as follows :

 $ Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
 ... Success!  

For the remaining part, hit the ENTER key for the remaining part of the installation, to accept the default values. Thi will take away some sample databases and users, disable logins from remote and loads these new rules making the changes permanent :

Now enable MariaDB to start on boot load, with the following command:

 $ sudo systemctl enable mariadb.service  

Step 5: Install PHP

The PHP processor is the part that displays dynamic content, by running scripts, connecting to our MySql databases to get data and hand the interpreted content to our web server to display.

The needed components can once again be installed by yum :

 $ sudo yum install php php-mysql 

To get the software stack working seamlessly, with PHP, we have to restart the Apache server.

 $ sudo systemctl restart httpd.service 

Install PHP modules

To add more functionality to PHP, we need to install some additional modules :

To see the available PHP module and library options type the following command, at your server prompt:

 $ yum search php- 

A display of optional components that can also be installed will be shown

$ php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
. . . 

To learn a little more about a component, type

 $ yum info package_name 

To install a chosen package, type:

 $ sudo yum install package_name 

Test out your PHP Installation

To confirm that our setup is in good condition and working properly, we create a PHP script.

We will call this info.php, for apache to have this file and serve it appropriately , it must be saved to the default web root directory.

In CentOS 7 this directory is located /var/www/html/ We can create the file at the directory by typing the following command:

 $ sudo vi /var/www/html/info.php 

This will launch a blank file, the next step will be to put the following PHP code into the file.

 < ? php php info(); ? > 

Once finnished, save and close the file.

To test the PHP interpreter, visit this page on your web browser:


The display of a well formated PHP version page, about your server, shows that PHP is working.

You equally remove, to avoid disclosing pertinent information about your server, by typing :

 sudo rm /var/www/html/info.php 


With a fully functional LAMP stack installed, you have a runtime environment for numerous web applications, software and web sites that you would like to use.

Phanerus Banner