Install Apache

1.  Run the following command:

2.   sudo yum install httpd mod_ssl

3.      Because the server doesn’t start automatically when you install Apache, you must start it manually by using the following command:

4.   sudo /usr/sbin/apachectl start

The following message displays:

  Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

5.      Open the main Apache configuration file by using the following command:

6.   sudo nano /etc/httpd/conf/httpd.conf

7.      Toward the end of the file, locate the code comment that starts with ServerName and provides an example name:

8.   #ServerName www.example.com:80

9.      Enter your Server host name. In the following example, the host name is demo:

10.             ServerName demo

11.  Reload Apache by using the following command:

12.             sudo /usr/sbin/apachectl restart

Open the port to run Apache

Apache runs on port 80. In some versions of CentOS, a firewall that is installed by default blocks access to this port. Perform the following steps to open the port:

1.  Run the following command:

2.   sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

3.      Use the following command to save your firewall rules so that your web server is accessible the next time that you reboot:

4.   sudo service iptables save

Test the Apache installation

 

Configure Apache to run automatically

After Apache is installed and working, use the following steps to set it to start automatically when the server is rebooted:

1.  Run the following command:

2.   sudo /sbin/chkconfig httpd on

3.      Run the following test to confirm that the setting works:

4.   sudo /sbin/chkconfig --list httpd

5.   httpd           0:off        1:off  2:on    3:on    4:on    5:on    6:off

Install PHP and reload Apache

Use the following steps to install PHP and reload Apache:

1.  Run the following command:

2.   sudo yum install php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

3.      Use the following command to reload Apache:

 sudo /usr/sbin/apachectl restart