How to Install and configure Apache on Red Hat/Centos 6.x
Apache is the most used web server on the Internet. It is
reliable, fast, easy to set up, relatively secure and the Apache Foundation is
on top of patches.
I thought you might want to see how easy and nice it is
to work with it, so I decided to write a post.
I’ll show you how to get it installed, configured and set
up a Name Based Virtual Host.
Packages Dependencies
·
httpd.x86_64
·
apr.x86_64
·
apr-util.x86_64
·
apr-util-ldap.x86_64
·
httpd-tools.x86_64
·
mailcap.noarch
Install all packages
[root@centos63 dhcp]# yum install httpd.x86_64 apr.x86_64
apr-util.x86_64 apr-util-ldap.x86_64 httpd-tools.x86_64 mailcap.noarch –y
Once all the packages above have been installed, we can
start configuring Apache.
Apache Configuration File
Apache
main configuration files, reside on /etc/httpd/conf.
On
Red Hat based distributions, Apache is named ‘httpd’,
and its configuration files are located on /etc/httpd, its
logs are stored on /var/log/httpd and the actual content or
the root directory is located on /var/www/html.
Let’s explore it
[root@centos63
dhcp]# cd /etc/httpd/conf
[root@centos63
conf]# ls -l
-rw-r--r--
1 root root 34418 Dec 5 08:59 httpd.conf
[root@centos63 conf]# vi httpd.conf
Note: Apache config file is very extensive; it has directives
for many things. I’ll show you how to get it up and running quickly. I’ll show
you more complex things on other posts i.e. mod proxy and mod rewrite which are
quite useful, I think.
Directives to set
Email
ServerAdmin root@localhost
Change it to your email address, for example:
ServerAdmin linux-up@ntlworld.com
Server
Name
#ServerName www.example.com:80
Uncomment the line above and change it to your Server’s
name. For example:
ServerName www.renpippa.co.uk
That is how easy it is to get it up and running.
Setting up a virtual
host
If you have multiple websites being hosted on the same server
and the server only has a single public IP address, virtual hosts will help you
immensely. This is also called ‘Named-Based Virtual Hosts’
[root@centos63 etc]# vi /etc/hosts
192.168.1.34 centos63 centos63.adlinux.int www.centos63.co.uk www.renpippa.co.uk
[root@centos63]# mkdir /var/www/www.centos63.co.uk
[root@centos63]# touch /var/www/www.centos63.co.uk/index.html
[root@centos63]# echo “Welcome to WWW.CENTOS63.CO.UK”
> /var/www/www.centos63.co.uk/index.html
Note: Replace the names above with your Virtual Hosts Names,
the name of the domains you with to host.
[root@centos63 conf]# vi /etc/httpd/conf/httpd.conf
Add the lines below to the bottom of the httpd.conf file, save and quit.
# Virtual Hosts Configuration
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@www.centos63.co.ukDocumentRoot /var/www/www.centos63.co.uk
ServerName www.centos63.co.uk
ErrorLog logs/www.centos63.co.uk-error_log
CustomLog logs/www.centos63.co.uk-access_log common
</VirtualHost>
Restart Apache
[root@centos63]# service httpd restart
Open your browser and test teh configuration. If you are using a different PC, you need to add the Domain name to your DNS, or edit your hosts file. If your PC is Linux, all you need is to edit /etc/hosts. If your PC is Windows based, you need to edit c:\windows\system32\drivers\etc\hosts.
By Renato de Oliveira
No comments:
Post a Comment