Installing LAMP On Ubuntu For Newbies

Want to support HowtoForge? Become a subscriber!
Submitted by Cargoship (Contact Author) (Forums) on Fri, 2007-07-13 15:57. :: Ubuntu

Installing LAMP On Ubuntu For Newbies

In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. The guide is intended to help those who have very little knowlegde of using Linux.


Install Apache

To start off we will install Apache.

1. Open up the Terminal (Applications > Accessories > Terminal).

2. Copy/Paste the following line of code into Terminal and then press enter:

sudo apt-get install apache2

3. The Terminal will then ask you for you're password, type it and then press enter.


Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address:


You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!


Install PHP

In this part we will install PHP 5.

Step 1. Again open up the Terminal (Applications > Accessories > Terminal).

Step 2. Copy/Paste the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart


Test PHP

To ensure there are no issues with PHP let's give it a quick test run.

Step 1. In the terminal copy/paste the following line:

sudo gedit /var/www/testphp.php

This will open up a file called phptest.php.

Step 2. Copy/Paste this line into the phptest file:

<?php phpinfo(); ?>

Step 3. Save and close the file.

Step 4. Now open you're web browser and type the following into the web address:


The page should look like this:

Test PHP Page

Congrats you have now installed both Apache and PHP!


Install MySQL

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

Step 1. Once again open up the amazing Terminal and then copy/paste this line:

sudo apt-get install mysql-server

Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line

bind-address =

And change the to your IP address.

Step 3. This is where things may start to get tricky. Begin by typing the following into Terminal:

mysql -u root

Following that copy/paste this line:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

(Make sure to change yourpassword to a password of your choice.)

Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:

gksudo gedit /etc/php5/apache2/php.ini

Now we are going to have to uncomment the following line by taking out the semicolon (;).

Change this line:


To look like this:

Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart


The End

Quick note to anyone who encountered problems with setting up the MySQL password, please refer to this page: MysqlPasswordReset

I applaud everyone who has taken the time to read this guide. This guide is also my first ever so I would love to hear back from the public on what you guys think! Just don't be too harsh. ;)

If you have questions about installing any part of LAMP just drop them in the comment box and I will do my best to help you out.

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 Jörg (not registered) on Sat, 2011-01-15 17:29.

Very, very helpful.

Thanks a lot!

I only had to find the information regarding to create a symlink otherwise:

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

Then it worked perfect.

Submitted by Philip John (not registered) on Sat, 2011-03-05 17:46.
I did this, which got rid of the 404 for http://localhost/phpmyadmin but I now have a 403 Forbidden in it's place. Any ideas?
Submitted by Misoooo (not registered) on Thu, 2011-01-13 12:11.
very helpfull, thanks
Submitted by Anand (not registered) on Thu, 2011-01-13 11:24.
Perfect...... Hats off to you
Submitted by Shredder (not registered) on Tue, 2011-01-11 15:28.
Good job.
Submitted by Caz_blue (not registered) on Tue, 2011-01-11 13:40.

Thanks for the brilliant tutorial, I would not have gotten this installed without it.


just a small note, step 3 was not needed in the version of Ubuntu I'm using ( I think it's maverick meerkat?) there was a prompt to get through step three that popped up at the end of step two.


After all steps where done (successfully) the landing page was throwing an error, this was needed to fix it.


gksudo gedit /etc/apache2/apache2.conf

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


from this website


thanks again, would not be looking at some cool databases without you!

Submitted by Gulshan (not registered) on Mon, 2011-01-10 13:39.

Thanks a lot !!

I am new with LAMP server and It is  the shortest and easiest way to install and configure LAMP.




Thanks a lot once again


Submitted by neo_aryan (not registered) on Wed, 2011-01-05 11:40.
i tried to follow every step but seems to be prob somewhere.. while installing apache installation of 'start' command failed don know y n so wen i m trying to configure it with sql and php i need to restart apache its not starting but giving ab error msg.. pls somebody help here is the error msg * Restarting web server apache2 (98)Address already in use: make_sock: could not bind to address no listening sockets available, shutting down Unable to open logs Action 'start' failed. The Apache error log may have more information.
Submitted by Akash Panwar (not registered) on Wed, 2011-01-05 11:14.

The tutorial is just perfect for the needs and is too simple for understanding.

Thanks alot.

Submitted by Anonymous (not registered) on Sat, 2011-01-01 12:34.
Really useful tutorial. Thanks very much!
Submitted by George Sedlak (not registered) on Wed, 2010-12-29 22:35.

New to Ubuntu and after trying other ways to load php/apache just gave up. Your tutorial took 2 minutes and everything is up and running, bless you, well done.




Submitted by Jason F. Grissom (not registered) on Tue, 2010-12-28 07:12.


Great how-to!

 As of 10.04 mysql.ini can be found at "/etc/php5/apache2/conf.d/mysql.ini".

Thanks for saving me so much time!
Submitted by Anonymous (not registered) on Wed, 2010-12-22 17:36.


 when i type it in my browser i dont get the page which you said. Can you please help me.

Submitted by nitai (not registered) on Wed, 2010-12-22 08:29.

excellent guide.

Thank you.

Submitted by Axel van Moorsel (not registered) on Sat, 2010-12-18 13:46.

After 3 years it still can be used. I miss only 2 little things which would make it complete for the real newbies.

  1. How to exit the MySql Shell (by typing 'exit' or 'quit').
  2. How to start PhpMyAdmin (http://localhost/phpmyadmin), although you could argue that this belongs in a PhpMytAdmin tutorial.
Nevertheless: great article.
Submitted by GoodSandlap (not registered) on Sat, 2010-12-18 01:55.

You, in a single tutorial, have enabled me to finally make the transition overnight. Going to a real server platform has always been an overwhelming nemesis that I have deferred due to my lack of know-how and intelligence. I am now migrating as we speak to Ubuntu.


I thank you

I thank you

I thank you!



Submitted by rudy (not registered) on Wed, 2010-12-01 05:22.
2 :thumbsup:
Submitted by Orijit (not registered) on Tue, 2010-11-30 13:09.


I installed ubuntu one today as a plan to shift from windows to a linux system for my development purpose and was looking to setup AMP on it.

 I can safely tell you that the article is neat. Serves its purpose. Easy to understand. keep up the good work and keep me posted.

thanks and regards (no hard words here ;)


Submitted by Alan (not registered) on Wed, 2010-11-24 22:38.
Fantastic guide, really well written, informative and useful. Bookmarked for future builds :D
Submitted by rafatmb (registered user) on Wed, 2010-11-24 19:47.

Greate work: clear and complete.

Thanks a lot.

Rafael Marangoni

BRLink Servidor Linux Team

Submitted by Beppe (not registered) on Wed, 2010-11-24 12:46.
Thanks a lot.
After been wasting a lot of my time on windows platforms I've migrated on Ubuntu, especially for production environments.
Submitted by Alvaro (not registered) on Fri, 2010-11-19 03:03.
Great Tutorial! More to come I hope? Thanks a lot.
Submitted by Sean (not registered) on Mon, 2010-11-15 01:03.
Seriously...awesome tutorial, thank you very much! I am a complete Linux newbie and I am now up and running with LAMP. 
Submitted by Anonymous (not registered) on Wed, 2010-11-10 05:56.

This is a really well written tutorial I would like to see it go just a little bit farther and explain how to get a page set up that says something more than "it works".



Submitted by GP Das (not registered) on Mon, 2010-11-08 13:57.
The tutorial is excellent. I would like to install PHP5 with FTP and Socket. Pl tell me the command to do this. Thanks in advance.
Submitted by Ricardo (not registered) on Sun, 2010-11-07 13:08.

This is an excellent working guide. I installed on an Ubuntu 10. This is what users look for. Congratulations and thank you.


Submitted by Anonymous (not registered) on Sat, 2010-10-30 09:06.
Thanks a lot! It works perfectly! I tried to make it work on Windows for forever but it never worked, now on Linux with your tutorial I tried it for the first time and it instantly worked! Thank you!
Submitted by Anonymous (not registered) on Thu, 2010-10-28 14:50.

it's just great!!!

i'm new to ubuntu and this tutorial helpt me a lot!

just btw: if u install the latest mysql you can set the password at installation

Submitted by anshul (not registered) on Mon, 2010-10-25 08:05.
this is an excellent tutorial i found it very easy. Just remember to use mysql -u root -p if u have used a password for sql root. thanks
Submitted by Web design for ... (not registered) on Sat, 2010-10-23 17:24.

This is an excellent tutorial. I totally messed up my Ubuntu 9.04 installation by getting it all wrong and I can see where I went wrong now. I now have a fresh clean install of 10.04 and the correct way of installing LAMP. Fantastic...thank you.


Submitted by Anonymous (not registered) on Thu, 2010-10-21 18:50.

This is an amazingly accurate step by step tutorial.  It was very clear and accurate!!  I just follow the instructions here and everything worked fine (apache and php).  During the install, I was prompted with few additional y/n prompts and different prompts for passwords not mentioned in the tutorial.  But I am very familiar with WAMP (Windows rather than Linux) setup, so slight differences didn't throw me off though.

 I am a bit confused about the reference to "" though.  My php.ini file contains that, but one of the comments says it should be "". ???

 You have a talent for this, please keep doing it!

Submitted by gholton (not registered) on Wed, 2010-10-20 06:49.

I tried a few other help me pages for LAMP. I ended up blowing up my system twice and trying again. Then I found your document and it worked like a breeze.

The "" really needing to be "" should be added but luckily a fellow poster had it covered.

Again excellent assist here. Thanks!

Submitted by Anonymous (not registered) on Tue, 2010-10-19 02:38.

Installations are perfect . Php runs with apache2 web server but Mysql is constantly giving access denied .How to get Mysqlworking as a database and php is also unable to connect to database .

Submitted by B-rad (not registered) on Sat, 2010-10-16 22:17.

Wow finally somebody that knows what they are doing but is clear and concise. I literally have visited like 10-20 other sites trying to get this working and they all have gotten me confused or haven't been thorough and complete.


Keep it up.

Submitted by Dr. Robert F. S... (not registered) on Fri, 2010-10-08 20:11.

Thanks for taking the time to write this tutorial.  I just installed Ubuntu 10.04 -- my first new Linux since Slackware.  I found a few of the details were slightly different from your post, but it got the job done painlessly.


Submitted by Asfand (not registered) on Sat, 2010-10-02 07:48.
Thanks, gr8 and on the target work..
Submitted by Anonymous (not registered) on Fri, 2010-10-01 08:10.
Thanks! It was a great help in getting LAMP installed on my ubuntu machine.. 
Submitted by Juraj (not registered) on Thu, 2010-09-30 16:56.
It works, thanks!
Submitted by Anonymous (not registered) on Tue, 2010-09-28 21:25.
Thank you for this great article!
Submitted by Anonymous (not registered) on Tue, 2010-09-21 20:44.
thanx man.... it is great....
Submitted by newuser (not registered) on Fri, 2010-09-17 10:34.

Thanks. followed the guide to step 3 w/o any problems, but at step 3 I get the following message in the terminal:       ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)



Submitted by Anonymous (not registered) on Wed, 2010-09-22 06:51.

I got the same, but realized it was because I already set up the root user and password on install. Just use

>mysql u- root -p

to get in and set up any other users for your new database.


Submitted by Jashley6369 (not registered) on Wed, 2010-09-15 21:03.
Thanks for taking the time to write your article on installing lamp. I'm new to Ubuntu and know next to nothing about it. Your article helped me walk through the process with ease.
Submitted by Anonymous (not registered) on Mon, 2010-09-13 17:15.
Excellent.. thank you
Submitted by tototo (not registered) on Wed, 2010-09-08 06:42.

Genial, Genius............

Worksssssssssssssssssssssssssssssssssssssssssss Great!


Submitted by Varghese (not registered) on Tue, 2010-09-07 14:33.
Most possibly the simplest Howto.....Thanks a lot.
Submitted by Anonymous (not registered) on Fri, 2010-09-03 12:43.
i am a newbie and your TUT help me to enjoy the Ubuntu 10.04. now i want to now that how can i start the apache sever automatically? i have created a luncher in my desktop and set this command: sudo /etc/init.d/apache2 start i don't know how can i make it all automatically. Best Regards, Mohammad
Submitted by Anonymous (not registered) on Tue, 2010-08-31 06:58.

This is a very good tutorial but i failed to find ';' in the php.ini file instead i found ';' and changed it to by adding 'y'.

Submitted by Cid Visious (not registered) on Sat, 2010-09-11 04:31.

The name is

just take out the ; infront of to make it look like this

then restart the server. 

Submitted by jetti (not registered) on Fri, 2010-08-27 10:00.


1. if the command not works mysql -u root just use this one mysql -u root -p

 2. similarlly for sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin use sudo apt-get install libapache2-mod-auth-mysql php5-mysql

Submitted by steven (not registered) on Sun, 2011-06-05 23:24.
this is good advice.  post should be updated
Submitted by Arvind Kumar Chaubey (not registered) on Wed, 2010-08-25 13:18.


Really it is a very good helping guide for newbie of Lamp.

by using this i did my full installation in ubuntu.

once again  a lot of thanks for writing this article. and hoping the same for others   . Please keep it up.


Submitted by BentFranklin (not registered) on Fri, 2010-08-20 03:34.
Very good, thank you!  Also great comments, people!  Reading the latest 50 or so really helped.
Submitted by JB (not registered) on Thu, 2010-08-19 12:37.
Excellent guide for newbies! Followed instructions as mentioned and voila... its working! Thanks a lot
Submitted by Anonymous (not registered) on Sun, 2010-08-15 06:22.


 The best and simplest post. Works perfect!!! Always find working in linux better than windows. LAMP is yet another instance 2 prove it :)


Submitted by Ruwan Wickramar... (not registered) on Sat, 2010-08-14 17:37.

This is really valuable post on installing and configuring LAMP on ubuntu environment.I would like to add one more thing that i have faced in my ubuntu 10.04 installation(also on 9.10).

when i was trying to restart apache server soon after  i installed it i got the following error:

* Restarting web server apache2                                                

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

this might be happened due to missing statement in your httpd.conf file. (default configuration file for apache server)

this can be solved as follows =>

1) open your httpd.conf file :

sudo gedit /etc/apache2/httpd.conf

2) then insert this entry into your httpd.conf file and save it.

ServerName localhost

3) restart apache server :

sudo /etc/init.d/apache2 restart

I hope this might be helpful to those who have this problem.

Again thanks a lot for these instructions on LAMP installation


Ruwan Wickramarachchi.

Submitted by jesse (not registered) on Fri, 2011-01-07 21:22.


  I do not know if this is the case, but you might have gotten the error you had because you were using the IP address ""  That is not the "loop-back" address, the correct IP address for working on "localhost" is "". I believe the reason that editing your config file worked was because the "localhost" setting uses as its IP address.

  As the expression goes, "the devil is in the details".  Hopefully this will also help any others who might have had an issue like this.



Submitted by Matt (not registered) on Wed, 2010-08-11 19:13.
Good tutorial. I want to note that changing the bind address is a rather terrible idea. MySQL should only be available from the local machine. There is generally no need to access if from other hosts, and it is a bad idea to make this change without addressing the security concerns.
Submitted by Minez (not registered) on Sat, 2010-08-07 23:46.

Nice info and run perfectly....!! thanks....

Submitted by Steve Webb (not registered) on Fri, 2010-08-06 10:37.

This is an excellent help page and guide.  Thank you.

Given PHP in your instructions does not include PHP with GD support (security issues so I am told) I was wondering if you could give the user the option to install PHP with GD support with the command line:

sudo apt-get install php5-gd

Which ever way, thanks for the excellent support.


Submitted by Anonymous (not registered) on Tue, 2010-08-03 08:47.

Thanks man! You're the best!!

 was really helpful.

 just one thing: in the php.ini, it seems like the '' changed to '' for some reason O_o

Submitted by Angel A. Moncada (not registered) on Sun, 2010-08-01 05:40.
I thank you for all your help, you did a great job for those of us that have no experience with LAMP servers. this was great. Thank you again in Jesus Name
Submitted by JJP (not registered) on Sat, 2010-07-31 01:27.
Linear, clear and simple! You did an excellent job. You are fine man with great karma. Bravo. Laurel garland and glory.
Submitted by Anonymous (not registered) on Thu, 2010-07-29 15:48.
Fantastic! Thanx a lot!
Submitted by Anonymous (not registered) on Wed, 2010-07-28 16:48.

You should also add there may be a misspelling in the php.ini file:

Initially it shows:

But it should be corrected to show:


I also added another line :


Thanks for the tutorial!

Submitted by Kantha (not registered) on Mon, 2010-07-26 04:08.
Thanks for the information.
Submitted by shiva shampoo (not registered) on Wed, 2010-07-21 18:40.
Thank you so much for the great instructions. Everything is working now :)
Submitted by Anonymous (not registered) on Fri, 2010-07-09 16:14.
Great tutorial.
Submitted by Raju Aryan (not registered) on Sun, 2010-07-18 06:09.

This is the simplest tutorial i ever met on the internet about installing LAMP. Believe me users it's the gud one.


One more thing don't forget to run this command after installing phpmyadmin

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

otherwise u will get a 404 not found error. Actually this command let the browser know the phpmyadmin folder to be in var folder, thought not actually. just link that is much fine..have great development guys.take care.

raju aryan

Submitted by Goli (registered user) on Sat, 2012-08-18 18:34.
Thank U.
Submitted by Sandip karande (not registered) on Sun, 2010-08-29 15:08.

I added below lines in apache.conf, file 

# Include phpmyadmin configuration
Include /etc/phpmyadmin/apache.conf

# Remove the useless apache warning while startup


404 error fixed.. now I can access http://localhost/phpmyadmin

Submitted by Anonymous (not registered) on Wed, 2010-08-04 04:51.

Hei All,

Raju's final "ln" command is crucial.

Ubuntu 10.04 usually by default installs LAMP already

Was scratching me head where to invoke phpmyadmin..


Submitted by beruh (not registered) on Wed, 2010-12-01 09:54.
Really perfect guide; everything worked just as described. But this phpmyadmin issue should be included in the initial tutorial, just to make it more perfect. Regardless, thanks a lot and keep it up!
Submitted by Yene (not registered) on Fri, 2010-07-09 15:39.
to the point love it
Submitted by Anonymous (not registered) on Sun, 2010-07-04 12:48.

very clear and simple tut.

it worked perfectly.

Submitted by bakry salih (not registered) on Wed, 2010-06-30 08:56.
Thanks!!! clear and useful tutorial. it woked with no problems in ubuntu 10.4.
Submitted by greg (not registered) on Mon, 2010-06-28 08:27.
Hi, I found your tutorial to be very clear and helpful. However, I believe it is now dated. I followed your directions to a T, I have Ubuntu Lucid Lynx 10.04 and upon installing mysql a semi graphical interface popped up asking for the root password. The same type of graphical interface happened with phpmyadmin when I was installing that as well. I am unable to view phpmyadmin at http://localhost/phpmyadmin/. I apologize, I am very new to linux/ubuntu but I definitely enjoyed your guide up until I encountered discrepancies with the tutorial.
Submitted by Omkar Khair (not registered) on Mon, 2010-06-28 05:51.
An easy drive thru, for Ubuntu newbies. Thanks, and keep such posts coming :)
Submitted by Daniel (not registered) on Sun, 2010-06-27 17:44.

Everything I was looking for and nothing more, everything worked within minutes on Ubuntu 10.04. Thanks!

Submitted by vipul (not registered) on Sun, 2010-06-27 14:54.

hats off to you sir.. very helping guide..

Submitted by david owen (not registered) on Wed, 2010-06-23 18:17.

excellent tutorial, simple, valid, easy to follow.

 I seem to recall there was a way to install all the components in one go, as "lamp" but I was unable to find a reference for the apt-get install command to do that.

Submitted by D' (not registered) on Fri, 2010-07-09 15:24.

There is a way from the synaptic package manager that allows you to install the lamp server as follows:

open synaptic > edit > Mark package by task > on the new windows scroll down to "LAMP Server" and apply.

Submitted by Hummad (not registered) on Tue, 2010-06-22 08:24.
Thanks a lot for your details help and assistance. Worked very well.
Submitted by Anas (not registered) on Tue, 2010-06-15 12:32.

Thanx buddy i'm writing this without even completing my installation of mysql.


Submitted by Jesse Andersson (not registered) on Mon, 2010-06-14 15:43.

This is by far the best, most effective and friendly and easy to use guide I have ever read or used. I read the whole thing. It was so good and rich with usefulness that I didn't want to skim through it, I wanted to savor it. If only the endless man pages and example scripts and online documentation I went through could have been half as perfect and helpful. I am extremely impressed and grateful. If I wasn't already in a committed relationship I would ask you to marry me :) Thanks again. If you ever need anything, like my first born or what not, just say the word. Wow, I mean, seriously, please do more. If you don't mind. Maybe configuring drupal, or cake_PHP (I don't know if I'm even into cake...if you do more guides do what ever you like. I'm sure it will be great and I will find it useful no matter what the subject matter.) You know what? For all I know, you may have done lots more already. I'm going to look. But not while I'm writing this. So, see you around, or you handiwork at least, I hope.

Submitted by v twom (not registered) on Tue, 2010-06-01 21:05.
Excellent! I was able to set it up in no time. Many Thanks!
Submitted by Hamed Rajabi Va... (not registered) on Mon, 2010-05-31 12:05.
Your guide was so easy & helpful, just please add to them MysqlPasswordReset in details. Thank you!
Submitted by Tharindu (not registered) on Thu, 2010-05-20 12:50.

Great work buddy Really useful for me each time I'm upgrading my system


Submitted by Karira (not registered) on Mon, 2010-05-17 02:06.

Thank you

I'm new user  

Submitted by JENISHA (not registered) on Fri, 2010-04-30 17:52.

Hello there

   Instruction given for installing LAMP is very useful for beginners. Saved time and my health by providing simple step by step procedure. Great work. Thankyou so much for posting.

first page
previous page
next page
last page