Debian Lenny - installing Apache2 and PHP5

At the time of writing, Debian Lenny comes with Apache v.2.2.9-10 and PHP v.5.2.6 and they are easily installed via the default Debian Package Manager 'aptitude'.

The advantage of using aptitude is that you will get any security updates from Debian (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 (remember this demo Slice has a hostname of 'demo').

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 see the default 'It works!' screen:

Apache Welcome Screen

Now we have the base Apache install completed, we can move onto installing PHP. If you don't require PHP then please feel free to skip the next section.

PHP5 Install

In this example, I'm not going to install all the modules available. Just some common ones.

To see what modules are available try a:

sudo aptitude search php5-

Note the '-' at the end of 'php5'. This will show any packages that start with 'php5-' and shows the available modules.

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

PHP Test

Before we go any further, it is always a good idea to test your setup and make sure that everything we've already done is working as we expect.

We can test that Apache and PHP are playing nicely together very easily by creating a simple php file with a call to the phpinfo method and then loading it in our web browser.

Let's create the file:

sudo nano -w /var/www/test.php

Now we will add some basic HTML and a call to the phpinfo method to the file:

<title> PHP Test Script </title>
phpinfo( );

Great, now we should be able to load that script in our web browser using your Slice IP address:

If everything is installed properly, you should see a PHP generated page that displays all sorts of information about your PHP installation: PHP Info Screen

Great! No need to worry about what all that means for now. We just wanted to verify that PHP was working.

Now that we know it is, let's go ahead and remove that test script, we don't need the whole world knowing about our PHP installation.

sudo rm /var/www/test.php



Well, almost done.

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

The next article will go through the Debian Lenny Apache layout as it differs slightly from the 'classic' layout you might expect if you had installed from source.


Ben B.

Article Comments:

hhhh commented Sun Apr 19 15:24:57 UTC 2009:

waiting for the debian lenny drupal clean url tut!

Muun Daveeds commented Sat May 23 14:33:18 UTC 2009:

Thanks you. I upgrade my box of etch to lenny but then my amp was not function. So you instruction work. Not though ServerName mybox for the warn no VirtualHosts.

Steven Degutis commented Sun May 24 16:23:01 UTC 2009:

Thank you for an amazingly simple and straight-forward set of guides! You cannot understand how much time you've saved me. And you did it for free, on your own time, which says a whole hell of a lot about you, so kudos! If I had money, or beer, I would be donating one of them right now ;)

Ken Y. commented Wed May 27 08:27:35 UTC 2009:

I echo Steven's sentiments! These tutorials are written in a very down-to-earth, professional and easy-to-understand way. The only tutorial I had any trouble understanding was the first (on securing your Debian Lenny server) - and even that was easy, once I got it down, and remembered to reload my configurations! A La AC/DC - "Have a drink on me!"

chillipepper commented Wed May 27 16:16:42 UTC 2009:

I installed PHP5 ...and the PHP Test didn't work for me, after I followed the instructions for creating /var/www/test.php I hit http://localhost/test.php and instead of loading the page it prompts me to 'Save' the file test.php.

what am I missing here?

Adam commented Sun Jun 28 15:19:43 UTC 2009:

@chillipepper I ran into the same issue. Although I remember doing it the first time, just an Apache reload fixed it for me.

Jeremy commented Sun Aug 16 16:41:19 UTC 2009:

FYI...I just purchased a slicehost, started to run through this tutorial and received errors.

After running a "sudo aptitude update", i was able to successfully install apache and php.

Paul Roger commented Sat Oct 10 12:30:41 UTC 2009:

Thanks a bundle for your guides. Clearly written, so easy to understand. Yet writing guides like this is anything but easy...fantastic effort.

johntr7 commented Sun Nov 15 12:55:22 UTC 2009:

great stuff - nicely written :)

Milan Andric commented Tue Nov 24 05:20:30 UTC 2009:

Probably obvious to most but if you don't run aptitude update before you try the first install command you will get a bunch of 404 errors from lenny.

gintare commented Sat Jan 09 12:08:08 UTC 2010:

What do you mean by "Change the ServerName to your Slice hostname" (after 4th black). It seems very good tutorial, nevertheless it is not clear for somebody who never used Apache or worked with servers before. Besides, in many cases, is not clear to which files the lines in examples has to be added, nor reason why they have to be added. For the begginner sentence "navigate to your Slice IP address" means nothing - it is so easy to write clearly "copy and paste to browsers(Mozilla, Konqueror..) address part" .

Jorge F. Aguilera commented Sun Jun 06 01:46:28 UTC 2010:

Simply it works. Thanks a lot Ben for your guide.

Apachez commented Thu Oct 21 04:44:31 UTC 2010:

"ServerName demo" means I need to replace "demo" with my hostname? If it is, I still can't see my <hostname> home page. It doesnt load the page

Jered commented Mon Oct 25 16:25:02 UTC 2010:

Apachez, you might need to check the DNS settings for your domain. Make sure it points to the slice. If you're getting a connection refused or the like, then either apache isn't running or DNS is directing users to the wrong place. If you see a page on your slice but it's not the one that you wanted to appear for this domain, then it may be a matter of configuring the virtual host (which is covered later in this series).

divya commented Sun May 08 17:21:14 UTC 2011:

we have installed php and mysql and we got that phpinfopage also.....but we got the following error while trying to access mysql CALL TO UNDEFINED FUNCTION MYSQLCONNECT()

Jered commented Wed May 11 14:58:49 UTC 2011:

Divya, make sure you have the package "php5-mysql" installed, since that should provide the connector PHP needs to talk to MySQL.

payday loans commented Sat Jul 12 15:07:10 UTC 2014:

I just like the helpful information you supply on your articles. I will bookmark your weblog and check once more here frequently. I'm quite sure I'll be informed plenty of new stuff right here! Good luck for the next!

quick money commented Mon Aug 11 19:17:24 UTC 2014:

Yourr style is really unique compared to other people I've read stuff from. Many thanks for postingg when you've got the opportunity, Guess I will just bookmark this page.

Here is my webpage: quick money

Want to comment?

(not made public)


(use plain text or Markdown syntax)