Comprehensive guide to creating an APACHE Web server
Apache web server is the most popular & widely used web server. It is open source software that is maintained by apache foundation & according to a data , it is being used on two-third (almost 67%) of total web servers to host websites.
It is very fast, reliable & secure web server. And one major advantage of using apache is that it is highly customizable. With the help various add-ons & modules, we can customize apache to suit our environment & as we see fit. It can be used on MAC, Unix & Windows along Linux.
Other features include the ability to support multiple programming languages, server side scripting, an authentication mechanism and database support.
Now let’s move onto types of webhosting that apache supports. Apache supports 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.
For the purpose of this tutorial, we are going to discuss both types of webhosting with an example.
Apache can installed with three different methods, mentioned below-
1- YUM– Easiest way to install apache on the server is through yum. To install apache via yum, run
|$ yum install httpd
2- RPM – Apache can also be installed through rpm but for that we need a rpm file, which can downloaded from Official Apache website. Once package has bee downloaded, run the following command to install apache,
|$ rpm –ivh httpd-2.4.x-1.x86_64.rpm
3- Using Source package– It is the most complex method among these three methods. For this we will need a source package, which can be obtained from Official Apache website. The advantage of using this method is that we can customize the installation i.e. modify installation directory, enable/disable modules etc. To install apache from source, process is as follows,
|$ tar–xvf httpd-2.4.6.tar.gz
$ cd httpd-2.4.6
$./configure –prefix=PREFIX (enter custom directory location for apache installation)
$ make install
Now that we have installed apache, we will move onto webhosting part.
IP Address based hosting
For accomplishing IP based hosting, we will need individual IPs for every website that we host. For this tutorial, we will be hosting two websites & will assign two IPs to our server. After we have configured our IP addresses (192.168.1.100 , 192.168.1.110), open /etc/hosts file for making an entry for the website
|$ vi /etc/hosts
Next create directories for both the websites for placing documets/website files,
|$ mkdir /var/www/html/exampleweb1.com
$ mkdir /var/www/html/exampleweb2.com
Then, we will configure websites by editing ‘/etc/httpd/conf/httpd.conf’
|$ vi /etc/httpd/conf/httpd.conf
& search for ‘Listen 80’ . Next uncomment it & add IP address, so it should look like
Next add the server configurations to httpd.conf,
Lastly create an index.html for exampleweb1.com
|$ echo “This is exampleweb1.com” > /var/www/html/exampleweb1
Similarly, create an index.html page for exampleweb2.com as well. After both the pages have been created, restart apache services to implement the changes.
|$ systemctl restart httpd.service
|$ service httpd restart
Open your browser & access your websites, either using name or IP address.
Name Based hosting
To configure name based hosting, open the apache configuration file ‘/etc/httpd/conf/httpd.conf’ & add the following lines to the file,
|$ vi /etc/httpd/conf/httpd.conf
CustomLog logs/www.exampleweb1.com-access_log common
CustomLog logs/www.exampleweb2.com-access_log common
Nextly, search for the “NameVirtualHost” in the httpd.conf & uncomment it by removing ‘#’ from the starting of the line & add the IP of the server, so it should look like
Save the file & exit. Now create ‘index.html’ file for both the websites as we did above & restart the apache services. Now, open your browser & enter the website url i.e.
We will see two different webpages with their unique contents.
This concludes our tutorial, please leave your questions/queries in the comment box below.