Ubuntu Gutsy - installing Apache and PHP5

Ubuntu Gutsy comes with Apache v.2.2.4 and PHP v.5.2.3 and they are easily installed via the default Ubuntu Package Manager 'aptitude'.

The advantage of using aptitude is that you will get any security updates from Ubuntu (if and when distributed) and dependencies are automatically taken care of.

Apache Install

A basic Apache install is very easy:

sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert


Towards the end of the install you will see this warning:

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

Although I'll be going into some detail about the options and settings available in the main apache configuration file, let's fix that warning straight away.

Open the main apache config:

sudo nano /etc/apache2/apache2.conf

At the bottom of the file add the following:

ServerName demo

Change the ServerName to your Slice hostname or a FQDN. Once done, save apache2.conf and gracefully restart Apache (this method of restarting won't kill open connections):

sudo apache2ctl graceful

Now the warning has gone. Nice.

Default Page

If you navigate to your Slice IP address:

You will not see a welcome screen as you might expect but rather this: Apache Directory Listing

If you click into the 'apache2-default' directory the welcome screen will be displayed: Apache Welcome Screen

If this concerns you and you would rather see the default 'It works!' screen instead of the directory listing (and I recommend changing it), then open up the default vhost file:

sudo nano /etc/apache2/sites-available/default

and uncomment the following line (remove the #):

RedirectMatch ^/$ /apache2-default/

Reload Apache:

sudo /etc/init.d/apache2 reload

Now when you visit your IP address you are automatically redirected to the 'It works!' screen rather than seeing the directory listing.

PHP5 Install

Let's move on to the PHP5 install. I'm not going to install all the modules available. Just some common ones.

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

sudo aptitude install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd   php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl

Once done, do a quick Apache reload:

sudo /etc/init.d/apache2 reload



Well, almost done.

We do need to configure Apache for our setup so we can host multiple sites and so on.

The next articles will go through the Ubuntu Gutsy Apache layout and configuration as it differs slightly from the 'classic' layout you might expect if you had installed from source.


Article Comments:

rdflowers commented Thu Nov 29 04:52:34 UTC 2007:

Well, I got to this excellent ( installing apache and php ) article from the list of articles. So, it's totally mysterious to me what "The next articles" are -- among the delicious list of apache-related articles.

I don't know next from Denver.

I haven't run into a non-excellent article yet. Your folks were also VERY helpful on irc earlier today.

PickledOnion commented Thu Nov 29 10:36:59 UTC 2007:

Hi rdflowers,

As the article says, the next articles relate to the Apache layout and configuration.

See here for the list

Hope that helps.


Stefan commented Mon Jan 21 21:13:10 UTC 2008:

Thanks for a great tutorial / howto!!

DrewC commented Wed Jan 30 00:52:15 UTC 2008:

Nice tutorial, worked beautifully =)

Hari commented Sat Feb 16 23:14:04 UTC 2008:

Change the ServerName to your Slice hostname or a FQDN. Once done, save apache2.conf and gracefully restart Apache (this method of restarting won't kill open connections):

Where can i find the slice hostname? Do you mean the name of the slice name?

Also can you give an example of a FQDN?

burnthand commented Sun Mar 02 11:11:57 UTC 2008:

i love this service. the quality of the documentation here is superb.

JR Smith commented Wed Apr 16 15:24:22 UTC 2008:

These tutorials are great. I just have one addition to make:

If you're installing Apache and php on a fresh slice, be sure to update your aptitude sources before running that aptitude install command. I went through this yesterday and had a lot of 404 errors on some of those packages before doing:

sudo aptitude update

Michael commented Wed Apr 23 00:26:48 UTC 2008:

Fantastic - all of the tutorials are perfectly written. So very helpful. Thanks very very much.

Radu Cojocaru commented Wed Apr 30 22:17:25 UTC 2008:

I have a slice and i installed apache and php as described above. But i noticed that i can't run php from command line. What do i need to install for that?

Jeff commented Sun May 04 21:20:16 UTC 2008:

I ran this:

sudo apt-get install php5-cli

And that solved the problem.

Bill Snapper commented Tue Sep 16 20:05:38 UTC 2008:

Thanks JR! I too got the 404s and your post made it easy to correct. Much appreciated.

nuks commented Thu Oct 08 10:06:56 UTC 2009:

Two words. Great article!

Scott commented Mon Dec 07 05:56:56 UTC 2009:

I installed a while back on my slice by following this article. How can I upgrade to PHP 5.3+?


yahoo commented Mon Jul 21 12:24:40 UTC 2014:

May I just say what a relief to discover somebody that genuinely understands what they are discussing on the internet. You certainly know how to bring a problem to light and make it important. More and more people should read this and understand this side of your story. I can't believe you're not more popular given that you most certainly possess the gift.

Visit my web site :: yahoo

Want to comment?

(not made public)


(use plain text or Markdown syntax)