Simple guide to Configure APACHE webserver in RHEL/Centos/Oracle linux(5/6/7) step by step


Simple guide to Configure APACHE webserver in RHEL/Centos/Oracle linux(5/6/7) step  by step

In this tutorial we learn how to configure APACHE webserver in linux(5/6/7) based of different types of hosting. There is two types of hosing . one is IP based hosting  and other is named based hosting. We configure  both types of hosting in this tutorials.

What is APACHE webserver

APACHE web server is an open source most widely used webserver software.67% of the webserver are running on APACHE webserver all over the world. APACHE webserver is very fast,secure and APACHE webserver is highly customizable and fit in different environment.

Pre-requisite of configure APACHE  webserver

To configure APACHE webserver we need to install APACHE webserver package. To install the APACHE webserver packages please follow the below link.

Configure APACHE webserver using IP based hosting

To configure APACHE webserver based on IP ADDRESS we need ipaddresses based on how many websites is going to host. If we have two websites we need two different ip addresses for this.

Lests take an example we have two websites which is example1.com and other is example2.com. For this we have two different ip addresses 192.168.137.3 and 192.168.137.5. we can assign multiple ip address on a single NIC using ip aliasing method.

After meet all pre-requisite we can start the configuration part . For this we need to go and edit  “/etc/httpd/conf/httpd.conf” file and create the VirtualHost .
Before doing this activity we need to take backup the httpd.conf file to execute the below command.

[root@localhost ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
  
After that we create two VirtualHosts , to do this follow the below steps.

<VirtualHost 192.168.137.3:80>
    ServerAdmin webmaster@example1.com
    DocumentRoot /var/www/html/example1.com
    ServerName example1.com
    ErrorLog logs/example1.com
    CustomLog logs/example1.com common
</VirtualHost>

<VirtualHost 192.168.137.5:80>
    ServerAdmin webmaster@example2.com
    DocumentRoot /var/www/html/example2.com
    ServerName example2.com
    ErrorLog logs/example2.com
    CustomLog logs/example2.com common
</VirtualHost>

Now we have to create the Document Root for the both websites. To create the Document Root we need to go “/var/www/html” directory and create two directories one is “example1.com” and other is “example2.com”. and them create index.html file inside the both directories.

[root@localhost ~]# cd /var/www/html
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# mkdir example1.com
[root@localhost html]# mkdir example2.com
[root@localhost html]# cd example1.com/
[root@localhost example1.com]# echo "welcome to example1" > index.html
[root@localhost example1.com]# cd ..
[root@localhost html]# cd example2.com/
[root@localhost example2.com]# echo "welcome to example2" > index.html

After doing the above activity we start the APACHE webserver using the below command.
For linux(5/6)
#service httpd start
For linux7
#systemctl start httpd
  
To verify the service we execute curl command .
[root@localhost ~]# curl http://192.168.137.3
welcome to example1
[root@localhost ~]# curl http://192.168.137.5
welcome to example2

Simple guide to Configure APACHE webserver in linux(5/6/7) step  by step

                       Simple guide to Configure APACHE webserver in linux(5/6/7) step  by step



Configure APACHE webserver using NAMED based hosting

In NAMED based hosting multiple websites can be hosted on a single ip address.
Lets take an example we have two websites example1.com and example2.com which will be hosted on a single ip address which is 192.168.137.3.
To configure this we need to go to the configuration file of the APACHE webserver and create the VIrtualHosts.

<VirtualHost 192.168.137.3:80>
    ServerAdmin webmaster@example1.com
    DocumentRoot /var/www/html/example1.com
    ServerName example1.com
    ErrorLog logs/example1.com
    CustomLog logs/example1.com common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@example2.com
    DocumentRoot /var/www/html/example2.com
    ServerName example2.com
    ErrorLog logs/example2.com
    CustomLog logs/example2.com common
</VirtualHost>

After that search NameVirtualHost  and uncomment the line add the below line

NameVirtualHost 192.168.137.3:80

Now we have to create the Document Root for the both websites. To create the Document Root we need to go “/var/www/html” directory and create two directories one is “example1.com” and other is “example2.com”. and them create index.html file inside the both directories.

[root@localhost ~]# cd /var/www/html
[root@localhost html]# pwd
/var/www/html
[root@localhost html]# mkdir example1.com
[root@localhost html]# mkdir example2.com
[root@localhost html]# cd example1.com/
[root@localhost example1.com]# echo "welcome to example1" > index.html
[root@localhost example1.com]# cd ..
[root@localhost html]# cd example2.com/
[root@localhost example2.com]# echo "welcome to example2" > index.html

Now the start the APACHE web service using the above steps.
Now open the browser and type example1.com and example2.com we will find the different webpages.

That’s it. If this tutorial is helpful please share and subscribe to get the latest update.


 


SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment