Complete: HTTPD+ PHP +MYSQL tutorial CENT OS 7

This how to will focus on the steps required to hosting multiple full domains or hosts on a web-server. This could be a virtual domain implementation for your corporate or home network. Maybe you’ve wanted to run web-packages and apply extra security on the applications and its sub-directories


  • Define packages required
  • Explain the steps of installation
  • Explain mode of security aspects.


Apache: an open source implementation distributed freely under the GPL that will serve our web-pages

PHP: An opensource ,powerful, yet easy to use scripting language tool, that is extremely easy to setup

MySQL: An open source relational Database management system

we will start by installing Apache and PHP with appropriate PHP, MySQL dependencies.

USE your favorite yum utility to  setup a virtual host, with username serv1. As our example access the file /etc/hosts using an editor maybe vi and add the following line: 

to make your website functional at this point, you should find at least find the following data and insert your domain as you wish in this case let us say serv:

<VirtualHost *:80>
        DocumentRoot  /var/www/html/

once the apache minimal setting is available then you can now create symbolic links:

ln -s /etc/httpd/sites-available/serv.conf /etc/httpd/sites-enabled/serv.conf

List virtual hosts available  with

# httpd -t -D DUMP_VHOSTS
VirtualHost configuration:
*:80                   is a NameVirtualHost

reload configuration of your web server:

systemctl restart httpd

If you are running a firewall, add the following commands allow HTTP and HTTPS traffic. This will make apache work seamlessly work with PHP and its components:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can repeat these steps if you need to add other websites, though this may depend on the location of your website files are stored. If it’s outside the web tree  or /var/www/, or …/htdocs, the owners of the folders should have read/write permissions. Anonymous apache users like wheel, www-data, nobody, (depending on the web-server release) should not be allowed permission of the process for security reasons well documented. You should create new users and give permissions for example: create two users to maintain the virtual domain and further give them read/write access to the folders.

Create two users under a group called SERV

First create group:

 groupadd SERV

Then create users that will maintain the website if any

usermod -a -G serv charles

usermod -a -G serv bob

chgrp -R SERV

chown -R charles

chown -R bob

chmod -R 755

chmod g+s

Install PHP and MySQL

Use the yum command to install the MySQL libraries required to provide for separate environments and languages

$ yum install mysql mysql-server mysql-libs mysql-server

You may need to edit  the /etc/my.cnf

To start out the MySQL server use service:

$ service mysqld start

use chkconfig:

$ chkconfig --levels 235 mysqld on

Set the root user password for all local/virtual domains

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new-password');

SET PASSWORD FOR 'root'@'' = PASSWORD('new-password');

SET PASSWORD FOR 'root'@'' = PASSWORD('new-password');

Use yum system to install our PHP and its components. We’re going to include the php-mysql package as well:

sudo yum install php php-mysql 

restart the Apache web server in order for PHP to work without problems. You can do this by typing this:

sudo systemctl restart httpd.service

Install PHP Modules

To get advanced functionality of PHP, optionally we can install some additional modules. but that is beyond the discussion for this how to;

yum search php-*

The results are all optional components that you can install.

sudo yum install php-fpm

Testing PHP

open a blank file and put this valid php code.
sudo vi /var/www/html/info.php

<?php phpinfo(); ?>

Once you are done , via your browser’s URI type the below command

The page should look something like this:

Now you are ready to unpack your website into your virtual domain and apache is ready to serve its pages.

%d bloggers like this: