Apache Http Server Configuration Example

1. Check package
# rpm -qa | grep -i httpd
httpd-2.2.15-15.el6_2.1.x86_64

 ( If httpd package is not installed, run: 
   
    # yum install httpd 
 )
2. Identify httpd directory
# ls -al /etc/httpd
drwxr-xr-x.   4 root root  4096 2016-11-04 12:44 .
drwxr-xr-x. 121 root root 12288 2017-09-13 08:15 ..
drwxr-xr-x.   2 root root  4096 2017-06-27 17:06 conf
drwxr-xr-x.   2 root root  4096 2017-04-13 13:13 conf.d
lrwxrwxrwx    1 root root    19 2016-11-04 12:44 logs -> ../../var/log/httpd
lrwxrwxrwx    1 root root    29 2016-11-04 12:44 modules -> ../../usr/lib64/httpd/modules
lrwxrwxrwx    1 root root    19 2016-11-04 12:44 run -> ../../var/run/httpd
3. Identify user, group, /etc/hosts
# cat /etc/passwd | grep apa
apache:x:48:48:Apache:/var/www:/sbin/nologin
# 

# grep apache /etc/group
apache:x:48:
#


#cat /etc/hosts
192.168.25.50  monitor 
4. Modify httpd.conf and Check the parameter
# vi  /etc/httpd/conf/httpd.conf

(remove "#"  and add IP )
#ServerName www.example.com:80     
        ---> ServerName 192.168.25.50:80


(Don't set 'AddDefaultCharset' parameter, add "#" )  
AddDefaultCharset UTF-8 
       ---->  #AddDefaultCharset 

DocumentRoot "/var/www/html"

User apache
Group apache
5. Start HTTP daemon
[root@monitor]# ps -ef | grep httpd
root      6965  6735  0 19:48 pts/0    00:00:00 grep httpd
[root@monitor]# 
[root@monitor]# apachectl start
[root@monitor]# ps -ef | grep httpd
root      6970     1  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6972  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6973  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6974  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6975  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6976  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6977  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6978  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
apache    6979  6970  0 19:48 ?        00:00:00 /usr/sbin/httpd -k start
6. Check apach http service

# vi /var/www/html/testwebpage.html


            <html>
              <head>
                 <title> 
                    TEST
                 </title>
              </head>

              <body>
                    TEST
              </body>
            <html>


# chmod 755 /var/www/html/testwebpage.html



In yor browser (client pc) 
http://192.168.25.50/testwebpage.html

( you can check access log :  tail -f  /etc/httpd/logs/access_log   
  if error is occur, please check firewall 
) 
7. Check Firewall (cenos 6.x )
# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#
#
# iptables -L  | grep http
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http     
8. Check Firewall (cenos 7.x )
# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)


#systemctl list-unit-files --type=service | grep firewall
firewalld.service                           enabled
#
#firewall-cmd --permanent --zone=public --add-port=80/tcp
#firewall-cmd --reload         
9. Stop HTTP daemon and check Error Log
[root@monitor]# apachectl stop

[root@monitor]# ps -ef | grep http
root      7066  6735  0 19:56 pts/0    00:00:00 grep http

[root@monitor]# cat /etc/httpd/logs/error_log

Other Tutorials

Zamong Setup
Installation and Configuration of Mariadb or Mysql
Installation and Configuration of PHP