Linux serverlinux web serverNETWORK ADMINISTRATIONS

WEB SERVER (APACHE) in Linux

WEB SERVER (APACHE):

Steps to Configure a simple web server:
Step1:- Install the package

• The package for apache web server is httpd.
#yum install httpd* -y

Step2:- Navigate to /etc/httpd/conf/httpd.conf and edit it.

• Navigate to the configuration file for http i.e. /etc/httpd/conf/httpd.conf and copy the last 7 lines as shown below
#vim /etc/httpd/conf/httpd.conf

Copy these lines and paste it at the end of the page, then edit it with your preferences.
# A publicly accessible directory, but read only, except for people in
# the “staff” group
; [public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = +staff

Edit the pasted above lines

Step3:- Navigate to the document root folder i.e. /var/www/html/ and create an index.html
file which will be accessed through a web browser
#vim /var/www/html/index.html

Step4:- Restart the Service and enable it in boot configuration

#service httpd restart
#chkconfig httpd on

Step5:- Now open the Firefox web browser and try connecting the web server.

• Open Firefox web browser and type the IP Address of the web server
http://192.168.223.129

• To open the website from command line use the following command

#curl IP/HOSTNAME of web server
#curl 192.168.223.129

Also Try
#elinks –dump 192.168.223.129 and check the output

DNS configuration if you don’t want to use IP address:
• Open the DNS configuration file and add the canonical name as “www”, so that we can
use our domain as full fledge website.

#vim /var/named/kt.rlz

• Restart the DNS services
#service named restart
#!ser

Okay now we are ready just open the web browser like Firefox and this type address as follows
www.kt.com

Note: This will only work in your DNS range, for others in your network use ip address

To create an Alias Web Site:
• Navigate to the document root i.e. /var/www/html/ and create a folder

#cd /var/www/html/
#mkdir vcs
#cd vcs
#vim index.html

Create an index.html

Navigate to configuration file /etc/httpd/conf/httpd.conf and add a line as alias
#vim /etc/httpd/conf/httpd.conf

Restart the services
#service httpd restart

Open the Firefox web browser and type the following url
http://192.168.223.129/vcs

To redirect the website:
• Redirecting means whenever the name of a particular website is given it should take us
on some other website.

• To redirect a website, navigate and open the configuration file of http i.e.
/etc/httpd/conf/httpd.conf and add the following line in it at the end.

#vim /etc/httpd/conf/httpd.conf

Redirect /kt “http://www.arn.com”

Restart the services
#service httpd restart

Open the Firefox browser and type the following website address
http://192.168.223.129/kt and it will take you to Kernel Technologies’ website

Virtual Web hosting:
Virtual hosting is a method for hosting multiple domain names on a server using a single IP
address. This allows one server to share its resources, such as memory and processor cycles, in
order to use its resources more efficiently.

Port based Hosting:
• The default port number for HTTP is 80. However, most web servers can be configured to
operate on almost any port number, provided the port number is not in use by any other
program on the server.

Steps to configure a port based web hosting:
Step1:- Make a directory for port based web hosting in document root i.e. /var/www/ say port.

#mkdir /var/www/port
#cd /var/www
#ls

Step2:- Navigate to port directory and create an index.html file there

Step3:- edit the configuration file i.e. /etc/httpd/conf/httpd.conf add the configuration for port based hosting in configuration file.

#vim /etc/httpd/conf/httpd.conf. Copy the same 7 lines and paste it at end edit it

Also search for the “Listen 80” by using “/” and paste your port under it

Step4:- Restart the service, open web browser and search for your website with port no.

#service httpd restart

Open Firefox and type http://192.168.223.129:8080

Name Based Virtual web Hosting:
• Name-based virtual hosts use multiple host names for the same web server IP address.

Steps to configure name based web hosting:
Step1:- Make a directory in document root i.e. /var/www/ with some name say “ktname”
#mkdir /var/www/ktname

Add an index page in it
#vim /etc/var/www/ktname/index.html

Step2:- Edit the configuration file as shown below
• Open the configuration file and add the name host information , search for NameVirtualHost and your host details

#vim /etc/httpd/conf/httdp.conf

Copy the same VirtualHost 7 lines, paste it at the last of the page and edit it as follows

Step3:- Restart the server and open the web page from Firefox
#service httpd restart

http://192.168.223.129 now it will navigate to our name based web page

source

by ARN Tech Trainings

linux web server