Networking - HTTP

The most common web server used on Linux is Apache which is initiated out of a system’s rc scripts. It is easily configurable. The protocol used to transfer information on the World Wide Web, called HTTP - Hypertext Transfer Protocol. While Apache can be set to listen to many different network ports, the most common port it listens on is port 80.

Installation HTTP Server

1). The package of the HTTP in Linux is called httpd.rpm which comes with Linux installation CD. If the package is already installed then no need to setup this rpm.

[root@localhost RPMS]# rpm -ivh httpd-2.0.49-4.i386.rpm

ð It installs the HTTP.

2). Now we shall setup a host’s name for the system. Let the hostname is www.home.com.

[root@www root]# vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=www.home.com

ð After editing the network file to set the hostname we shall must do restarting the computer.

3). The configuration file of HTTP is httpd.conf which is stored in “/etc/httpd/conf “directory. This file contains many lines. So in below we present few but important lines with line’s number (Some times line number can be different) to configure the server.

[root@www root]# vi /etc/httpd/conf/httpd.conf

… …. … … … …. …. …. …

… …. … … … …. …. …. …

133 # Listen: Allows you to bind Apache to specific IP addresses and/or

134 # ports, in addition to the default. See also the

135 # directive.

136 #

137 # Change this to Listen on specific IP addresses as shown below to

138 # prevent Apache from glomming onto all bound IP addresses (0.0.0.0)

139 #

140 #Listen 12.34.56.78:80

141 Listen 80

… …. … … … …. …. …. …

… …. … … … …. …. …. …

269 # DocumentRoot: The directory out of which you will serve your

270 # documents. By default, all requests are taken from this directory, but

271 # symbolic links and aliases may be used to point to other locations.

272 #

273 DocumentRoot "/var/www/html"

… …. … … … …. …. …. …

… …. … … … …. …. …. …

296 # This should be changed to whatever you set DocumentRoot to.

297 #

298

… …. … … … …. …. …. …

… …. … … … …. …. …. …

1038 # Use name-based virtual hosting.

1039 #

1040 #NameVirtualHost *:80

1041 #

1042 # NOTE: NameVirtualHost cannot be used without a port specifier

1043 # (e.g. :80) if mod_ssl is being used, due to the nature of the

1044 # SSL protocol.

1045 #

1046

1047 #

1048 # VirtualHost example:

1049 # Almost any Apache directive may go into a VirtualHost container.

1050 # The first VirtualHost section is used for requests without a known

1051 # server name.

1052 #

1053 #

1054 # ServerAdmin webmaster@dummy-host.example.com

1055 # DocumentRoot /www/docs/dummy-host.example.com

1056 # ServerName dummy-host.example.com

1057 # ErrorLog logs/dummy-host.example.com-error_log

1058 # CustomLog logs/dummy-host.example.com-access_log common

1059 #

4). At last step we have to start the service. If the service is not initiated properly then some errors have happened may be in configuration files or hostname or hosts file.

[root@www web]# service httpd start

Starting httpd: [ OK ]

ð Now, we can browse the "index.html" file from the directory,"/var/www/html" in Mozilla Web Browser which is a GUI application,

To create own web side

1). First we set the hostname in network file.

[root@www root]# vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=www.home.com

2). Add system’s IP address and hostname in hosts file.

[root@www root]# vi /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

192.168.10.1 www.home.com

3). Let’s create a directory named web in root directory.

[root@www root]# mkdir web

[root@www root]# cd /web

[root@www web]# cat > index.html

Red Hat Linux

Operating System - OS

ð In web directory we create an html file called index.html which file will browse in Mozilla Web Browser.

4). In this step we have to edit two lines of httpd.conf file.

[root@www web]# vi /etc/httpd/conf/httpd.conf

… … … … … … … … … …

… … … … … … … … … …

273 DocumentRoot "/web"

298

… … … … … … … … … …

… … … … … … … … … …

5). Now we shall restart the service.

[root@www root]# service httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

ð Now, we can browse the "index.html" file from the directory,"/var/www/html" in Mozilla Web Browser which is a GUI application,

To create virtual web side

1). First we set the hostname in network file.

[root@www root]# vi /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=www.home.com

2). In hosts file we shall add another hostname called virtual hostname for same IP address. In this way we can create many virtual web sides by using one IP address.

[root@www root]# vi /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

192.168.10.1 www.home.com virtual.home.com

3). Let’s create a directory named virweb in root directory.

[root@www root]# mkdir /virweb

[root@www root]# cd /virweb

[root@www virweb]# cat > index.html

Red Hat Linux Virtual Web Side...

ð In virweb directory we create an html file called index.html which file will be browsed virtually in Mozilla Web Browser.

4). In this step we have to edit few lines of httpd.conf file.

[root@www web]# vi /etc/httpd/conf/httpd.conf

… … … … … … … … … …

… … … … … … … … … …

NameVirtualHost www.home.com:80

… … … … … … … … … …

ServerAdmin root@www.home.com

DocumentRoot /web

ServerName www.home.com

virtual.home.com:80>

ServerAdmin root@www.home.com

DocumentRoot /virweb

ServerName www.home.com

… … … … … … … … … …

… … … … … … … … … …

5). Now we shall restart the service.

[root@www root]# service httpd restart

Stopping httpd: [ OK ]

Starting httpd: [ OK ]

Accessing Graphic Web Browser

There is a package comes with Linux installation CD called Mozilla which is a GUI web browser. The rpm’s name of this package is Mozilla.rpm. Initially we can check whether the package is installed or not by using rpm command with –q option.

[root@www root]# rpm -q mozilla

mozilla-1.6-8

start > Internet > Mozilla Web Browser

Accessing CUI Web Browser

We can also browse web side in CUI. There is a package of CUI web browser comes with Linux Installation CD named lynx. First we have to setup this package.

[root@www RPMS]# rpm -ivh lynx-2.8.5-15.i386.rpm

warning: lynx-2.8.5-15.i386.rpm: V3 DSA signature: NOKEY, key ID 4f2a6fd2

Preparing... ########################################### [100%]

1:lynx ########################################### [100%]

ð Now the package is ready to be accessed for browsing web side in CUI. In below there are few examples given to assist how to use this package.

Example,

[root@www root]# lynx www.home.com

Red Hat Linux Operating System - OS

Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back.

Arrow keys: Up and Down to move. Right to follow a link; Left to go back.

H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list

ð /web/index.html is shown in the page.

Example,

[root@www root]# lynx virtual.home.com

Red Hat Linux Virtual Web Side...

Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back.

Arrow keys: Up and Down to move. Right to follow a link; Left to go back.

H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list

ð /virweb/index.html is shown in the page.

Example,

[root@www root]# lynx 127.0.0.1

Red Hat Linux Operating System - OS

Commands: Use arrow keys to move, '?' for help, 'q' to quit, '<-' to go back.

Arrow keys: Up and Down to move. Right to follow a link; Left to go back.

H)elp O)ptions P)rint G)o M)ain screen Q)uit /=search [delete]=history list

ð /web/index.html is shown in the page.