Installing & Configuring HTTPD/Apache on CentOS 6.4

HTTPD/Apache is generally recognized as the world’s most popular Web server (HTTP server). Originally designed for Unix environments. The Apache Web server provides a full range of Web server features, including CGI, SSL, and virtual domains. Apache also supports plug-in modules for extensibility. Apache is free software, distributed by the Apache Software Foundation that promotes various free and open source advanced Web technologies.

This time we will divide this tutorial in two parts:

1. IP-based Virtual Hosts

a. One site per IP address

b.Host Header Names – multiple sites per IP address | port combination

2. Name-Based Virtual Hosts

a. NameVirtualHost 192.168.0.10 192.168.0.6

b. Then bind to each virtual host

So lets begin fir IP-Based Virtual Hosts

Apache by default, maintains 2 virtual hosts: TCP:80, TCP:443 determined by : /etc/httpd/conf/httpd.conf

So let’s begin by demonstration how to install and configure HTTPD/Apache

Pathfinder environment for HTTPD are :

“ /etc/httpd “ – this is primary config container

“ /etc/httpd/config/httpd.conf “ – this is primary config file under CentOS also RedHat.

yum install httpd

rpm –qa | grep –I httpd – this will enumerate package that have been installed and the man package is market with Red-X

1

When you install apache , you need to start from files that are located at httpd

Lets navigate to the file and see what we have there

cd /etc/httpd

ls –l  - here you will see the symlink of the httpd –Apache – the

run – directory simply contain a reference

logs – reference simple when you can find apache logs

2

enter command to see if the apache is running

ps –ef | grep –I httpd

pf –ef | grep httpd

service httpd status

Apache is not running yet

3

As mentioned before there are two directory for HTTPD-Apache

Conf – there are main configuration files

Conf.d – in Linux when ever you see .d suffix it means that is container of items that are included for larger configuration

Now  lets start HTTPD and see what will happen

Service httpd start

We have receive and error – this doesn’t mean that Apache is not running this is just DNS resolution problem but we will try to eliminate what kind of error we will receive , that is good for troubleshooting

4

let’s try to fix this:

vi /etc/sysconfig/network – change hostname to your hostname

5

vi /etc/hosts

6

Now type

Hostname yourhostname ( in my case is gnubizz.local) – as you see the error is gone

7

Now let’s continue where we left

netstat – ntl | grep 80 – you can see that the server has started

netstat –ntlp | grep 80 – the program is responsible is httpd

ps –aux | grep httpd – As you see primary apache process starts as root and subsequent processes run as apache(non-privileged users) and its defined on /etc/passwd

8

Now Apache is running lets tray to access the default page of Apache – open your browser and type either localhost or ip of your server

9

Let’s go a little bit deep , let’s change this default page and by default html file is stored on:

cd /var/www/html

vi index.html – close and check with browser

10

Note: Every changes that you made to HTTPD – Apache , issue reload and restart , and delete history and cookies for browser

Service httpd restart

or

!serv – this is a tip for shorts , Linux will remember last commands so than you can use ! and short names or by numbers  to restart the services or execute commands

An example of !

enter history command

ps –aux | grep httpd

11

!548

12

Now check with browser , you should have the same  page as it showing here

13a

Now we need to enable services for multi-user runlevels

chkconfig –list httpd – will show you the list

chkconfig httpd on  – this will enable runlevels

chkconfig –list httpd – do you see the difference

13

We need to check Apache logs, this is important when troubleshooting because apache traps messages between the client and servers and to see access and errors messages

cd /var/logs/httpd – this is default location

Check the access file first you can see how many time we have try to access our created website

watch tail access.log – main time refresh the browser and access again, do not close terminal you will see that again you changes in the terminal

My network has 254 available ip , so by  this l can assign to any pc or server within my house

So the CentOS that l am using has 192.168.0.4 gateway 192.168.0.1 255.255.255.0

First ip that l will assign to virtual interface will be 192.168.0.10 – l hope that is available :)

Ping 192.168.0.10 – l did not receive any replay this is good because l can see that this ip is available

ifconfig eth0:0 192.168.0.10

14

To have our website files in one place we need to create folders and give a name of our website

In my case l called my website site1.gnubizz.local ( your site you  can call as you wish )

mkdir /home/site1

mkdir /home/site1/www

cd /home/site1/www

vi index.html

15

Save and close

ls -l /home/site1 – to see who own the file , is owned by root , no need to owned by Apache , just read and write by apache that’s good

Capt

Now add a site1 and we need to be sure that Apache listens to 192.168.0.10:80

cd /etc/httpd/conf

vi site1.gnubizz.local.conf

16

save and close

Now navigate to :

vi /etc/httpd/conf/httpd.conf

As you can see here it’s already listen to port 80 , it tells here that it bind to all ip address

17

So we don’t want to bind to all ip addresses , we want to bind only to a specified ip address so that’s why we need to change

18

make symlink for site1

cd /etc/httpd/conf.d

ln –s ../conf site1.gnubizz.local.conf

service httpd restart

Note: incase you are facing problem accessing webpage you might check SElinux , pose problem when serving web content from: $HOME – so for temporary we need to disable

sestatus – check is Selinux is enabled

setenforce permissive

now point the browser with ip 192.168.0.10 – you should see this

19

So that’s it , you can add another site if you want just follow same steps ( site2, site3 )

cp site1.gnubizz.local.conf site2.gnubizz.local.conf

vi site2.gnubizz.local replace 1 with 2

cp -apvf /home/site1/www/index.html  /home/site2/www/index.html

ls -l /home/site2

modify vi /home/site2/www/index.html

than modify the /httpd.conf and add ip address ( 192.168.x.x )

cd /etc/httpd/conf.d

ln -s ../conf/site2.gnubizz.local.conf

browse new site called site2

So that’s it IP-Based Virtual Host

##########################################################################

Now lets begin with:

2. Name-Based Virtual Hosts

a. NameVirtualHost 192.168.0.10 192.168.0.6 – we have already configured

b. Then bind to each virtual host –  we have already configured

Add a second Virtual interface

20

We need to modify httpd.conf file

vi /etc/httpd/conf/httpd.conf – this time we will allow  to bind and listen in port 80

21

Save and close

Go to site1

vi /etc/httpd/conf.d/site1.gnubizz.local.conf – make the following changes

22

Save and close

Modify site2

vi /etc/httpd/conf.d/site2.gnubizz.local.conf

23

Save and close

Add this two virtual host to :

vi /etc/hosts

24

Check the status/names of virtualhosts

httpd –S – you can see that 192.168.0.10:80 is NameVirtualHost

Ca

Now try to access on browser by site name

Site1

25

Site2

26

Apache SSL | TLS with Self-Signet Certs – is ideal for intranet usage and default configuration includes self-signet certificates

yum install mod_ssl

yum install crypto-utils – check

we will generate a genkey for the host not for the website , l think is more appropriate for the defaults_:433   SSL site

type in terminal:

genkey gnubizz.local

click next

Capture

Select  2048 than Next – you have to wait sometime till the process finish

01-Capture

Click NO

02-Capture

We will not select this because every time any process that apache uses will require always  to be there and provide the password , it’s very secure of protecting your private key

03-Capture

Add information according your requirement

04-Capture

enter command to check who own the site1 directory

ls –l /home/site1

Capt

enter command to check site’s name and ssl.conf certificate

Ca

Make the changes on:

vi /etc/httpd/conf.d/ssl.conf

05

Now open the browser and check – you should have similar as shows in the pic

Select “ l Understand the Risks

06

Click on view

07

certificate has been issued

08

Note: The real key for this tutorial is  that you can issue your own self-cert or generate request via CA

So this is all , see you next time :)

4 Responses to Installing & Configuring HTTPD/Apache on CentOS 6.4

  1. anne0001 says:

    Whoooow! That’s to difficult to me at this moment but you have done this very well. Did you do that without any investigation or search the web? Your explanation is clear enough for people like me. The history ! trick was a nice one. Super :-)

  2. lulzimveliu says:

    Thanks Anne , not much :)

  3. justinmp says:

    This is Good..easy to understand.:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: