======How-to: Install, Configure and Troubleshoot Apache HTTP 2.2.3 on CentOS 5======
This may be applicable to all Apache 2 versions.
=====To install Apache Server on CentOS 5:=====
Apache is installed with CentOS 5 by default.
To check if the Apache Server is installed
# rpm -q httpd
Or (with yum, you need to be on line)
# yum groupinfo "Web Server"
If not installed, then install it with:
# yum install "Web Server"
To install the text-based browser:
# yum install elinks
To use elinks:
# elinks 127.0.0.1
To access Apache Server on CentOS 5:
Open a browser and enter:
http://localhost
=====To configure Apache Server on CentOS 5.=====
You do not need to do any thing to the default configuration httpd.conf file to get your Apache Server running.
All you need is to write your index.html and your web pages and place them in /var/www/html.
The default DocumentRoot is located in /var/www/html.
The default home page is located in /usr/share/doc/HTML/index.html.
The default ServerRoot in httpd.conf is ServerRoot “/etc/httpd”.
Make sure the firewall does not block access to port 80 by running:
# system-config-securitylevel
Allow WWW(HTTP) as "Trusted Services"
# apachectl start
Configure Apache service to start when the system is rebooted.
# chkconfig httpd on
Configure Apache Server to restart on CentOS 5
# apachectl restart
=====Example=====
- Back up your /etc/httpd/conf/httpd.conf file.
- Run from the command line:
# system-config-securitylevel
-
check WWW(HTTP) as Trusted services
-
# mkdir /var/www/html/test/
-
# cd /var/www/html/test/
-
# vi index.html
- insert(type i) the following:======Hello======
- Save(press Esc then type :wq) the file
-
# apachectl restart
-
# chkconfig httpd on
-
# chcon -R -u system_u /var/www/html/test/
-
# chcon -R -t httpd_sys_content_t /var/www/html/test/
- Browse
http://127.0.0.1/test
====Configuring user based security====
To allow only authorized users who have passwords, add the following lines to /etc/httpd/conf/httpd.conf.
Just before the commented option for the UserDir directive:
AuthType Basic
AuthName "Test Passwords"
AuthUserFile /etc/httpd/passdb
Require user user1
Test the syntax with one of the followings:
# httpd -t
# httpd -S
Restart Apache
# apachectl restart
====Configuring Passwords====
To create the passwords database passdb in /etc/httpd and add user1 to it run the following command:
# htpasswd -c /etc/httpd/passdb user1
To add another user, run the following command without the -c switch(which creates the database):
# htpasswd /etc/httpd/passdb user2
====Configuring host based security====
Add the following to the Directory if you want to allow access only to your network. If your network for example is 192.168.1.0:
# vi /etc/httpd/conf/httpd.conf
Order allow,deny
Allow from 192.168.1.0/255.255.255.0
=====Apache Troubleshooting=====
Backup the httpd.conf configuration file.
Make sure Apache is running:
# service httpd status
If not running, start apache with one of the followings:
# apachectl start
# service httpd start
Make sure Apache is running during the boot process with this command:
# chkconfig httpd on
Test the syntax with one of the followings:
# httpd -t
# httpd -S
To view error log file run the following command:
# tail /var/log/httpd/error_log
To view Access log file run:
# tail /var/log/httpd/access_log
To restar Apache with out disconnecting the users run :
# service httpd reload
If you want stop Apache:
# apachectl stop
\\ \\ \\