CentOS 6 - Apache and PHP Install Print

  • 1

CentOS comes with Apache v.2.2.3 and PHP v.5.1.6 and they are easily installed via the default CentOS Package Manager, yum.

The advantage of using yum (as opposed to installing via source code) is that you will get any security updates (if and when distributed) and dependencies are automatically taken care of.

Apache Install

A basic Apache install is very easy:

 
[root@valuehosted ~]# yum install httpd mod_ssl

Oddly, the server does not start automatically when you install it so you have to do this by hand:

 
[root@valuehosted ~]# /usr/sbin/apachectl start

The first thing you will see is this error:

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

As you can see, the address 127.0.0.1 (or whatever address you see there, usually your main IP address) is used as the server name by default. It's a good idea to set the ServerName for the next time the server is started.

Open the main Apache “config”:

 
[root@valuehosted ~]# nano /etc/httpd/conf/httpd.conf

Towards the end of the file you'll find a section that starts with ServerName and gives the example:

 
#ServerName www.example.com:80

All you need to do is enter your Cloud Server host name or a fully-qualified domain name:

 
ServerName demo

Note that my Cloud Server host name is “demo”.

Now just reload Apache:

 
[root@valuehosted ~]# /usr/sbin/apachectl restart

And the warning has gone.

Firewall

Notice that in some versions of CentOS, a firewall is installed by default which will block access to port 80, on which Apache runs. The following command will open this port:

 
[root@valuehosted ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

Remember to save your firewall rules after adding that instruction so your web server will be accessible the next time you reboot:

 
sudo service iptables save

Default Page

If you navigate to your Cloud Server IP address:

http://192.168.1.98

You will see the default CentOS Apache welcome screen:

 

This means the Apache install is a success.

Chkconfig

Now that we have Apache installed and working properly, we need to make sure that it's set to start automatically when the Cloud Server is rebooted.

 
[root@valuehosted ~]# /sbin/chkconfig httpd on

Let's check our work to confirm:

 
[root@valuehosted ~]# /sbin/chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

The setting works.

PHP5 Install

Let's move on to the PHP5 install. I'm not going to install all the modules available, just a few common ones so you get the idea.

As before, due to using yum to install PHP5, any dependencies are taken care of:

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

Once done, reload Apache:

 
[root@valuehosted ~]# /usr/sbin/apachectl restart

Was this answer helpful?

« Back