There is a new version of this tutorial available for Ubuntu 22.04 (Jammy Jellyfish).

Installing Apache2 With PHP5 And MySQL Support On Ubuntu 11.04 (LAMP)

Version 1.0
Author: Falko Timme
Follow me on Twitter

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on an Ubuntu 11.04 server with PHP5 support (mod_php) and MySQL support.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

In this tutorial I use the hostname with the IP address These settings might differ for you, so you have to replace them where appropriate.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su


2 Installing MySQL 5

First we install MySQL 5 like this:

apt-get install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user [email protected] as well as [email protected], so we don't have to specify a MySQL root password manually later on:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword


3 Installing Apache2

Apache2 is available as an Ubuntu package, therefore we can install it like this:

apt-get install apache2

Now direct your browser to, and you should see the Apache2 placeholder page (It works!):

Apache's default document root is /var/www on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d.


4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

apt-get install php5 libapache2-mod-php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart


5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php

Now we call that file in a browser (e.g.

As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.


6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

apt-cache search php5

Pick the ones you need and install them like this:

apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Now restart Apache2:

/etc/init.d/apache2 restart

Now reload in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:


7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It's a good idea to install it:

apt-get install phpmyadmin

You will see the following questions:

Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common? <-- No

Afterwards, you can access phpMyAdmin under


Share this page:

Suggested articles

36 Comment(s)

Add comment


By: Anonymous

If it's ubuntu server :

sudo tasksel and then choose Lamp server


sudo apt-get install lamp-server^ (^is needed) .

If it's a non server version:

sudo apt-get install lamp-server^

or sudo

apt-get install tasksel  

sudo tasksel and choose Lamp server

By: smagic39
By: Alderin

I used tasksel on the advice of another forum to uninstall and re-install apache because something I did in trying to get apache to do virtual hosts completely failed, and I wanted to get back to defaults.

 I don't know why, but tasksel uninstalled not only apache, but also java, eclipse, most of my other development tools, and something else that prevented my desktop from running.

And THAT is why I'd rather use apt-get: it does what you tell it to, and asks before doing more.

By: Mark Reyer

Can I assume that this will work with Ubuntu 11.04 desktop?  Or is this just for Ubuntu Server edition?

By: Anonymous

I just followed these instructions for a fresh LAMP install on Ubuntu 11.04 Desktop that I use for web development...

By: Anonymous

Why not just use "sudo tasksel install lamp-server" to install LAMP?

By: Fabrizio Malta

all steps was ok, but phpmyadmin I only installed when I used the synaptic package manager.


By: Anonymous

I found this very useful, however I ran into a problem at step 3 where instead of showing me the default page, it was giving me an "ERROR 403: Forbidden." After hours (and I mean HOURS) of research (and yes, I am a complete Linux newbie), I finally found the solution: "chmod -R 0755 /var/www".

 Not sure if your guide is intended for newbies or not, but if it is, letting others know of this step would be very useful. I know I could have used it.

Great guide, by the way. apart from my permissions issues, everything was right on and easy to follow. thank you.

By: Anonymous

Hi I also got the same problem, but solution didn't work for me, when I am trying this url I am not getting It Works! page. Please help. Thanks in advance. I am a newbie.

By: Karti

Try rather than the

That may help




By: Shane

On some systems it's

By: Anonymous

Why use XAMPP--which is crap--when you've got this guy?! Awesome job, friend; thank you very very much! Regards,

By: Anonymous

for windows?

By: Matheus Ramos

thanks, was very helpful

By: farook

This is very helpful to me but the last step on the install phpmyadmin
when I type this into my address bar
it is show the list of directory it is because phpmyadmin is in /usr/share/

I've fixed this by in the Terminal type :-
mv /usr/share/phpmyadmin /var/www/phpmyadmin
so now it come up very well now..

By: Anonymous

thanks farook..! :)

By: Adam

It may be better to create a link rather than moving the directory:

# ln -s /usr/share/phpmyadmin /var/www

By: chuck norris

link did the trick, thanks. 

By: zalias

To set up under Apache all you need to do is include the following line in /etc/apache2/apache2.conf, first type the following command to open up this file:
gksudo gedit /etc/apache2/apache2.conf

Add the following line of code inside apache2.conf:
Include /etc/phpmyadmin/apache.conf

Now restart Apache:
sudo /etc/init.d/apache2 restart

 Find this in

By: Anonymous

use the following command for restarting apache

/etc/init.d/apache2 restart

By: RustanTech

This tutorial helps a lot! thanks dude! Also thanks for those who comments the problem on phpmyadmin! Works great!

By: Anonymous

this worked until "info.php" i cold not creat(/delete) files in var/www i tried Left click(properties->permissions) on www folder But all was gray i can not change the permissions..

 I looked at chmod command but it looks like i only can change filepermissions not the folderpermissions.

Can someone give me a command to
change the permissions on var/www to write by user-root ?? Please!

By: cotsweb

sudo chmod 777 /var/www

worked for me.

Thanks for a great article, and to the follow up posts too.

I  followed the original article but needed the "chmod" as above so I could save files in the /var/www directory and the "ln" to get phpMyAdmin working properly.

The IP for my server was

By: Charles Calvert

cotsweb wrote:

> sudo chmod 777 /var/www

No! That is a huge security hole.  You just gave all users on the system (including users created to run other applications) complete access to your document root.  The permissions for /var/www should be 600 unless you have a compelling reason to change them, and this isn't a compelling reason.

The most likely reason that the grandparent couldn't write a file to that directory was because he didn't do it using the sudo command:

sudo nano /var/www/info.php

By: kjeldsteen

hey i can't get the myadmin to work. will some one pleace help me. :D


By: Naphlin

This article made me feel like a pro, great article buddy...thnx alot

By: Invisiblestupid

Thank you Falko for the fantastic write-up.  I couldn't have done it without this.  And thank you all for your comments...I still couldn't have done it without all of you either!

By: Omar

Thank you, thank you, thank you!  This post was a great help.  No errors, no misses.  Just perfect!

By: Anonymous

 This is old but charles is right! also what you can do is:

sudo chown -R :www-data /var/www

to change the group to the apache2 user www-data

and go with

sudo chmod -R 775 /var/www

 this helps if you need apache to write to files in your web dir

By: kalpa

thank u vary much. this is a grate job.thanx again



Thank you Adam for advising 'ln -s /usr/share/phpmyadmin /var/www'. That solved my problem. I was then able to connect to phpMyAdmin sign-in page using A very well written tutorial. Thank you.

By: peeela

The symlink worked for me too - thanks for posting this!

By: NikIvRu

Thank you very much!

By: oweceej

I followed all your steps and it worked first time for me perfectly.

Many thanks to you for taking the time to post this and sharing it.

By: Keli

Your guide worked fine but I was looking for something a bit more in depth, 

I found this I don't know if anyone else is new to this stuff but it helped to see "screenshots" as I didn't feel like I had to guess through anything!

phpMyAdmin =

Maybe I just love screenshots, thanks though.

By: brojob

The IP you type into your browser to load the default apache2 server webpage is NOT NECESSARILY ! ! !

On linux, for example, use the command ifconfig to figure out your localhost IP.