Step by Step guide to configure APACHE server
It is the most widely used web server in the world. Almost 65%-70% of the world’s web server use apache server. Reason it is famous is because its open source (so money saved), highly secure, very fast & very reliable. It can be customized to meet our needs with the help of using various modules & extensions.
To define it in a bit more technical terms, It is a modular, process based web server that creates a new thread everytime a new connection is made.
Apache is also has a major advantage, that it can support multiple website hosting on a single server. There are actually two types of hosting :-
1- IP address based hosting– For IP based hosting, we need to have a different IP for every website that we are hosting. These IPs are then attached to a single or multiple NICs.
2- Name based Virtual hosting– Name based hosting is used to host multiple virtual websites using a single IP address.
In this tutorial, we are going to learn to configure Apache server & host both IP address based websites & name based websites but before we do that, we are going to install apache on our server.
(Recommended Read: Redirect http to https: Apache Server)
There are three different ways in which we can install apache on our RHEL/CentOS machines
1- Using RPM – We need rpm package for it. Once you obtain the rpm package for apache, we can install it using the following command (Learn more about RPM HERE)
2- Using YUM– Yum is the easiest way to install apache on your system. We don’t need to download any package when using yum, just use the following (Learn more about YUM HERE)
3- Using source package– This process is a bit complex but provide us with various options to modify our apache installation as we are using source packages to compile & install the apache package. Firstly we need to download source package (Download from here), we will then extract it, compile it & then install it,
This way we will install apache from source, alternatively you can also build a rpm package from source package
& then install it using the rpm command, as we did above.
Now we have our apache server ready & will now configure configure to host websites.
Configure Apache server
Name Based hosting
We will first configure 2 websites (test1.com & test2.com) using the name based hosting. Firstly open the apache configuration file which is /etc/httpd/conf/httpd.conf & add the following lines to the bottom of file,
CustomLog logs/www.test1.com-access_log common
CustomLog logs/www.test2.com-access_log common
Next, search for the “NameVirtualHost” in the same file & uncomment it by removing ‘#’ from the starting of the line & add the IP of the server, so it should look like
Now save the file & exit.
We will now create ‘index.html’ file for both the websites but we will firstly create a directory for both the websites,
Now add some content to index.html to identify both the sites,
<title>This is test1.com</title>
& do the same for test2.com
<title>This is test2.com</title>
You can also type ‘this is test1.com or test2.com ‘ without using html tags. We now have our apache server ready with name based hosting. We will now restart our server to implement changes & will then check our sites
Now, open your browser & enter the website url
You should now see two different webpages with their unique contents.
IP based hosting
We need 2 different IPs assigned to our single NIC or 2 different NICs with different IPs to achieve IP based hosting. We are going to use a single NIC card with different IPs assigned to it. if you don’t know how to do it, read our tutorial here.
After we have configured our IP addresses (192.168.0.120 , 192.168.0.125), we will start our configuration by editing ‘/etc/httpd/conf/httpd.conf’
& search for ‘Listen 80’ . Next uncomment it & add IP address, so it should look like
& add the following server configurations to the bottom of the same file i.e. httpd.conf
Create index.html for both websites in their respective folders & write content to it , as we did above & lastly restart your apache service for changes to take effect.
Open your browser & access your websites, either using name or IP address.
That’s it guys, we have successfully created installed & configure apache server . Please leave your queries/comments below in our comment section.