About Apache

Apache is the first HTTP server software to serve 100 million websites. It currently serves up to 39% of web sites on the internet. It has a modular structure for its functionality, with each part that describes an individual site called a virtual host. Virtual hosts makes it possible for one apache server to host several domains or pages.

The server works by serving files from a directory configured for each domain name. Such that site visitors have the contents of this directory presented to them, through a parallel process that serves the same for every domain on the server. This can be done for as many domains as needed, depending on the server's resource limits and computing power.

Here we will go through, how to set up Apache virtual hosts for CentOS 7.


Setting up Apache

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.

To install apache, use yum with the following commands.

 sudo yum -y install httpd 

Then set up apache to work as a service in CentOS and work by it self after system reboot.

 sudo systemctl enable httpd.service 

Step 1: Setting up the directory

The document root for all the web files in each virtual host is set up at:


Within the document root we create sub folders each representing a domain and then a public_html directory within each domain directory, that will hold the application files.

We can create this nested directories with the command mkdir -p

sudo mkdir -p /var/www/site.com/public_html
sudo mkdir -p /var/www/site2.com/public_html

Step 2: Giving them permissions

Now we change the file permissions for the directories, so they are owned by the regular user and not root. This is done with the chown command, enabling the user to change files in his own web directories.

sudo chown -R $USER:$USER /var/www/site.com/public_html
sudo chown -R $USER:$USER /var/www/site2.com/public_html

The $USER being the user name with which you are currently logged in. This makes the regular user now own the public_html directories where its web content would be stored.

The document root's permissions are also amended to have the appropriate read, write and excute permissions.

sudo chmod -R 755 /var/www

Step 3:Setting up sample pages for each Virtual Host

Phanerus Banner