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

Want to support HowtoForge? Become a subscriber!
Submitted by falko (Contact Author) (Forums) on Sun, 2011-05-15 19:56. :: Ubuntu | Web Server | Apache | MySQL | PHP

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

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 05/05/2011

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 root@localhost as well as, 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


8 Links

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Keli (not registered) on Wed, 2013-05-01 03:17.
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.
Submitted by oweceej (not registered) on Fri, 2012-12-07 21:15.

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.

Submitted by NikIvRu (not registered) on Sun, 2012-04-15 18:16.
Thank you very much!
Submitted by gdawg (registered user) on Tue, 2012-03-20 18:21.
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.
Submitted by peeela (not registered) on Wed, 2013-06-19 05:48.
The symlink worked for me too - thanks for posting this!
Submitted by kalpa (not registered) on Sun, 2011-11-27 15:51.

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


Submitted by Anonymous (not registered) on Thu, 2011-10-13 21:04.

use the following command for restarting apache

/etc/init.d/apache2 restart

Submitted by RustanTech (not registered) on Wed, 2011-10-12 12:49.
This tutorial helps a lot! thanks dude! Also thanks for those who comments the problem on phpmyadmin! Works great!
Submitted by Omar (not registered) on Sat, 2011-10-08 19:56.
Thank you, thank you, thank you!  This post was a great help.  No errors, no misses.  Just perfect!
Submitted by Naphlin (not registered) on Thu, 2011-10-06 16:51.
This article made me feel like a pro, great article buddy...thnx alot
Submitted by Invisiblestupid (not registered) on Thu, 2011-10-06 06:10.

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!

Submitted by kjeldsteen (not registered) on Fri, 2011-09-30 17:28.

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


Submitted by Anonymous (not registered) on Sat, 2011-09-24 00:12.

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!

Submitted by cotsweb (not registered) on Fri, 2011-09-30 18:32.

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

Submitted by Charles Calvert (not registered) on Thu, 2011-12-08 18:51.

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
Submitted by Anonymous (not registered) on Fri, 2012-02-17 00:22.

 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

Submitted by farook (not registered) on Sat, 2011-08-20 17:33.
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..
Submitted by zalias (not registered) on Thu, 2011-11-10 14:03.

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

Submitted by Adam (not registered) on Sat, 2011-09-10 15:03.

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

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

Submitted by chuck norris (not registered) on Sat, 2011-11-05 06:45.
link did the trick, thanks. 
Submitted by Anonymous (not registered) on Sun, 2011-08-28 23:28.
thanks farook..! :)
Submitted by Anonymous (not registered) on Tue, 2011-08-02 03:21.

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.

Submitted by Anonymous (not registered) on Sat, 2011-08-20 15:26.

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.

Submitted by Karti (not registered) on Wed, 2011-08-24 21:19.

Try rather than the

That may help




Submitted by Shane (not registered) on Sat, 2011-08-27 10:16.
On some systems it's
Submitted by Anonymous (not registered) on Wed, 2011-07-20 03:07.
Why use XAMPP--which is crap--when you've got this guy?! Awesome job, friend; thank you very very much! Regards,
Submitted by Anonymous (not registered) on Fri, 2011-09-23 02:50.
for windows?
Submitted by Matheus Ramos (not registered) on Mon, 2011-07-18 18:56.
thanks, was very helpful
Submitted by Fabrizio Malta (not registered) on Sun, 2011-06-05 04:45.
all steps was ok, but phpmyadmin I only installed when I used the synaptic package manager.

Submitted by Anonymous (not registered) on Wed, 2011-05-18 00:59.
Why not just use "sudo tasksel install lamp-server" to install LAMP?
Submitted by Mark Reyer (not registered) on Tue, 2011-05-17 19:43.
Can I assume that this will work with Ubuntu 11.04 desktop?  Or is this just for Ubuntu Server edition?
Submitted by Anonymous (not registered) on Sat, 2011-05-21 22:52.
I just followed these instructions for a fresh LAMP install on Ubuntu 11.04 Desktop that I use for web development...
Submitted by Anonymous (not registered) on Tue, 2011-05-17 19:02.

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

Submitted by Alderin (not registered) on Sun, 2011-07-31 18:18.

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.

Submitted by smagic39 (not registered) on Wed, 2011-06-15 11:32.