Contents |
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.
A basic Apache install is very easy:
sudo yum install httpd mod_ssl
Oddly, the server does not start automatically when you install it so you have to do this by hand:
sudo /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”:
sudo 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:
sudo /usr/sbin/apachectl restart
And the warning has gone.
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:
sudo 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
For more information on firewalls and their configuration, it is strongly recommended to read the Firewalls section of our knowledge base.
If you navigate to your Cloud Server IP address:
http://123.45.67.89
You will see the default CentOS Apache welcome screen:

This means the Apache install is a success.
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.
sudo /sbin/chkconfig httpd on
Let's check our work to confirm:
sudo /sbin/chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
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:
sudo /usr/sbin/apachectl restart
The last thing we need to do is configure Apache for our setup so we can host multiple sites. We'll cover that in the next article in this series.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

27 Comments
Your link under "Almost Done"
Darn links
This iptables parameters work
$iptables -I INPUT -p tcp --dport 80 -j ACCEPT
The one posted up there did not.
forgeting to save it means you will need to run it after reboot cos it will all be gone
save it like this
$service iptables save
don't forget to save
Re: saving iptables
I have problem upgrading to php5.2
Re: Upgrading to PHP 5.2
If you are running into problems with the dev repository you could try looking for someone else's RPMs instead. For example, this person created RPMs for PHP 5.3.2 to run on CentOS: http://forum.slicehost.com/comments.php?DiscussionID=4603
php module error
Re: PHP packages
sudo yum install php-mysql php-devel php-gd php-mcrypt php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml
If you're still getting an error, let me know which version of CentOS you're using and we'll see what else we can find out.
php-mcrypt
164.177.158.78 Red Hat Enterprise Linux 6.1
Please help
Re: mcrypt
If you do require php-mcrypt you can install the EPEL repository for yum/rpm and then the package will be available. You can install EPEL by running:
sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
After running that you should be able to "sudo yum install php-mcrypt". It will ask you to accept the GPG key for EPEL if you do - that's normal, and should only happen the one time.
hello,
i tried the last suggestion and got the message below. i am on centos 6 and the reason i am wanting php-mcrypt is that phpMyAdmin shows an error message without it:
The mcrypt extension is missing. Please check your PHP configuration.
[root@**** ~]# sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
Retrieving http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
curl: (6) Couldn't resolve host 'download.fedora.redhat.com'
error: skipping http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm - transfer failed
thank you.
Re: EPEL
You can see [our article on adding EPEL](http://www.rackspace.com/knowledge_center/content/installing-rhel-epel-repo-centos-5x-or-6x) for details, but the download links to the current RPMs are...
CentOS 6:
[http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm](http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm)
CentOS 5:
[http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm](http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm)
hi all,
gradually moving through the error messages on phpmyadmin:
have successfully intsalled EPEL and remi repositories and i think now when i type in basic yum install commands it fetches more recent versions of software which is great. i installed php 5.4 for example by yum install php, and installed standard sql via yum install mysql-server. then had to install php-msqli, php-mcrypt and php-mbstring in the same way as phpmyadmin was recognising that they weren't there. a few little 'conflicts' i am coming across now, one mainly being:
Your PHP MySQL library version 5.5.11 differs from your MySQL server version 5.1.61. This may cause unpredictable behavior.
there's very little on google for this error message, so just wondering if anyone could help me sort this one out!
thanks!
figured it out! woo hoo!
in putty, type:
yum --enablerepo=remi update mysql
then restart apache:
service httpd restart
then (and this is the important part, otherwise the same warning message is displayed):
clear your browser cache!
then the warning message goes away!
(something i did before this step as well was just yum update, and installed everything that was returned, so that was a bit drastic, and people looking for a solution may not want to try that without having backups etc).
hello,
in the tutorial it says that after starting apache you will get this message:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName
however where it says 127.0.0.1 i get my domain ip address - maybe the tutorial should be updated to reflect this? and if it is displaying my domain ip address, does that mean i don't have to change it?
thanks!
Re: displayed IP
You'll still want to set a hostname in apache's config so that it will stop displaying that message when it restarts.
Hi needed to add this line
sudo /usr/sbin/apachectl graceful
Recommend adding to this tutorial. Thanks!
When I try to restart apache
sudo /usr/sbin/apachectl restart
I am getting the following error message:
apachectl: Configuration syntax error, will not run "restart":
httpd: Syntax error on line 104 of /etc/httpd/conf/httpd.conf: <IfModule takes one argument, Container for directives based on existance of specified modules
I'm not sure how to remedy this; any ideas?
Error Establishing Database Connection
Your tutorial is the second one I've come to while trying to install Wordpress on Centos6
Originally, typing in my server's IP in browser would get me no page at all
After following your tutorial, I now get a "Error Establishing Database Connection" error
Any idea how to fix? I'd love to get this working soon, I need to install Wordpress and PHPBB3!
Error Establishing Database Connection
Sorry to hear you are having trouble. When you get the "Error Establishing Database Connection" there can a number of issues however as you referenced this error in the context of setting up Wordpress I will offer the following bits of advice. First ensure your database service is installed and running, this can be done with ps aux | grep <service name>. If your database is up and working correctly, ensure the database and user/password you are including in your wp-config.php exist within the database. If they do not exist in the database, login to the database shell and add these with the CREATE DATABASE and CREATE USER commands. Hope this helps. Remember Rackspace offers 24/7 support toll free at 1-800-961-4454.
Thanks,
Evan
Rackspace Product Evangelist
I'm having trouble installing
re: yum
It's possible there's an old copy of yum still running or that there's a hung process - run "ps -ef | grep yum", and if there's a yum process running, try killing it off. If not, then you might need to just remove the "/var/run/yum.pid" file and see if that lets you run the yum install without issues.
anyone else noticed the 890
just kidding.. thank you so much for this amazingly detailed tutorial :)
re: 890
Glad to hear the article was helpful!
Thank you!
Thanks.
Add new comment