This article shows you how to install Apache and PHP on CentOS 6. CentOS 6 comes with Apache 2.2.3 and PHP 5.1.6, which you can install using the default CentOS Package Manager yum
. yum
The advantage of using (instead of using source code for installation) is that you can obtain any security updates (when distributed), and dependencies are automatically processed.
Installing Apache
- Run the following command:
sudo yum install httpd mod_ssl
- Because the server does not start automatically when you install Apache, you must start it manually.
Sudo/usr/sbin/apachectl start
The following message is displayed:
not reliably determine the server'sfully qualified domain name, using 127.0.0.1 for ServerName
- Open the master configuration file for Apache.
sudo nano/etc/httpd/conf/httpd.conf
to the end of the file, find the beginning part ServerName
and give an example.
# ServerName www.example.com:80
- Enter your cloud server host name or fully qualified domain name. in the following example, the host name is
demo
. ServerName Demo
Reload Apache.
Sudo/usr/sbin/apachectl restart
Open Port Run Apache
Apache runs on port 80. In some versions of CentOS, firewalls that are installed by default block access to port 80. Perform the following steps to open the port.
- Run the following command:
sudo iptables-i input-p tcp--dport 80-j ACCEPT
After you add the directive, save the firewall rules so that you can access the Web server the next time you restart.
sudo service iptables Save
Test Apache Installation
Browse to your cloud Server IP address (for example http://123.45.67.89
).
if the default CentOS Apache Welcome screen is displayed, the installation succeeds. If you have any questions, please contact Rackspace.
Configure Apache to run automatically
Apache is now installed and working, and is set to start automatically when the server is restarted.
Run the following command:
Sudo/sbin/chkconfig httpd on
Test to confirm that the settings are correct.
Sudo/sbin/chkconfig--list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:o Ff
Install PHP
Run the following command:
sudo yum install php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml
The above command will not install all available modules, just some of the most commonly used modules.
2. Reload Apache.
Sudo/usr/sbin/apachectl restart
Installing Apache and PHP on CentOS 6