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 Vikram TV (not registered) on Thu, 2009-10-15 12:25.

Thanks a lot.. I have been trying to configure my lamp server and succeeded now.. Nice explanation..



Submitted by OFF732 (not registered) on Sun, 2009-11-08 09:32.
I had that same problem and found out that I had not restarted apache. Once I... sudo /etc/init.d/apache2 restart it worked great
Submitted by mik047 (not registered) on Sat, 2009-10-10 10:02.

while testing for php, the browser asks me to download that file...

 Is my installation for php is correct?

 It does not show the content shown in your tutorial... It directly asks me to download the file... :(

Submitted by Anonymous (not registered) on Fri, 2009-10-09 19:36.
Thank you so much.  This makes installing LAMP easy, especially since I am fairly new to linux.  I am no longer a windows user, thank god, and this takes minutes compared to hours trying to set up on a windows box.  There were a few extra steps, but most of it was prompt based.  But I'm up and running and excited to learn VIM.
Submitted by Anonymous (not registered) on Thu, 2009-10-08 07:25.
This is a tutorial, how tutorials should be!!!
Submitted by Steffen (not registered) on Tue, 2009-10-06 20:40.

Thanks a lot for this tutorial, I followed it and it did exactly what I expected it to do (installing LAMP on Ubuntu 9.04 Desktop on a G4 Apple Mac).



Submitted by Pooja (not registered) on Tue, 2009-10-06 15:12.

Thanks a lot !!!!!!!!!!

It is the simplest and easiest tutorial I've ever a terrific help for the beginners....

thanx again n keep helping us!!

Submitted by Kavi (not registered) on Sun, 2009-10-04 07:15.

This tutorial has really been of great help to me. It was straight and forward for a newbie in Ubuntu.

 Thanks again.

Submitted by afal (not registered) on Thu, 2009-10-01 17:51.


an excellent article. everything worked well all the way through.

I have encountered one last problem, on the last step of restarting apache

after i typed      sudo /etc/init.d/apache2 restart

 i get the following error:

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

 i have changed that ip address to my computer's ip address as shown in your article

many thanks

Submitted by Anonymous (not registered) on Mon, 2009-09-21 22:29.
Thanks for the guide, It has been very usefull to me. Thinks like this guide and people like you make great Internet!
Submitted by Chris P (not registered) on Fri, 2009-09-04 06:25.
Thank you for the simple to follow article.  I was able to get a web server, database, and admin tools up and running in under an hour.  Amazing!
Submitted by Anonymous (not registered) on Wed, 2009-08-26 23:45.
This is the quickest that I've ever setup a LAMP server thanks to your guide. You da man! :)
Submitted by marsty5 (not registered) on Wed, 2009-08-26 20:31.
the best guide i've ever read!! Thank you sooo much!
Submitted by Pieter den Toom (not registered) on Wed, 2009-08-19 18:38.
Worked like a charm, thanks
Submitted by Anonymous (not registered) on Sat, 2009-08-15 17:59.
This article is accurate and helpful. It is this type of articles that makes the Internet a worthy place to search for answers. Thanks!
Submitted by golnaz (not registered) on Thu, 2009-08-13 18:26.
easy and helpful,thanks
Submitted by lostutopian (not registered) on Sun, 2009-08-09 12:33.
installing phpmyadmin requires a little more instruction to point the phpmyadmin folder from /var/www to /var/www/phpmyadmin

you would need to:

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

I'm a newbie and i was trying to figure out what/where i went wrong with you instructions.

thanks by the way to the instructions above! :)

Submitted by Anonymous (not registered) on Thu, 2009-10-29 14:49.

Nice one. Sorted.


BTW Life is easier when you use a password with MySQL (PHPMyAdmin doesn't like root user without passwords it seems)

Submitted by ErikB (not registered) on Tue, 2009-10-20 17:57.
Great instructions, thanks. I also had to add the above.
Submitted by Deepak (not registered) on Sun, 2009-08-09 01:39.

Thanks for this good clear post.  It made my install very straight forward.  I have one request though... are there any tests that could be added to confirm that the install is doing all the things it should be doing?



Submitted by Ajay Singh (not registered) on Sun, 2009-08-09 00:23.

Thank you.

This worked perfectly on Mint 6 and I could install Apache, PHP, MySQL with phpMyAdmin.

During installation of MySQL, it asked to set root password. After setting root password MySQL password setup step was not required.

During installation of phpMyAdmin, it asked for default web server, and after selecting apache2, it configured phpMyAdmin.

Thanks again. 

Submitted by Bruce Edgar (not registered) on Sat, 2009-08-08 19:42.

These instructions are fantastic. You have a real knack for breaking complex instructions down to their basic form.



Submitted by Sinan Saricinar (not registered) on Mon, 2009-08-03 18:06.

Best tutorial ever...

Submitted by Jonathan Kramer (not registered) on Sun, 2009-07-26 21:26.

Your guide was an excellent source to walk me through what I thought would be a difficult exercise for this newbie!   I just used this guide to install AMP and PHPMYSQL on a new install of Ubuntu 9.0.4.

Many thanks.

Jonathan Kramer
Kramer Telecom Law Firm, PC
Los Angeles, CA

Submitted by zackgigz (not registered) on Thu, 2009-07-09 06:36.

1st problem

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


2nd problem

[Thu Jul 09 13:05:17 2009] [warn] NameVirtualHost *:0 has no VirtualHosts
 ... waiting [Thu Jul 09 13:05:19 2009] [warn] NameVirtualHost *:0 has no VirtualHosts
it is ok?

3rd problem

mysql> SET PASSWORD FOR root@'localhost'=PASSWORD('abc123');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement


then i read explainaition in

but still i can't understand me


Submitted by Jeff Long (not registered) on Sat, 2009-08-08 20:36.

I am not familiar with your third problem, but your first problem is that his tutorial does not include the specifying of the mysql password that you previously set.  So if that password was say "linuxrules" then you would run mysql with

 mysql -u root -p linuxrules

 I believe your second problem is no big deal, and just telling you you don't have any entries in the Virtual Host file.

 Hope that helps.


Submitted by notinterested (not registered) on Wed, 2009-07-08 23:12.

Followed the guide completely but as soon as i restart mysql will not start again unless reinstalled completely.


Whats the deal?

Submitted by Akila (not registered) on Sat, 2009-07-04 11:13.

Thanks this is one of the simplest tutorial I found. Thank you very much. Worked on Ubuntu 9.04

Submitted by Ryan (not registered) on Mon, 2009-06-29 02:43.

That was the easiest setup that I have gone through. Now I just have to setup a page.


Submitted by Alex(Kiev) (not registered) on Sun, 2009-06-28 14:46.

Thanks a lot!

It's very helpful tutorial!!


Submitted by Anonymous (not registered) on Sun, 2009-06-28 05:36.

Great guide!

Keep it up!


Submitted by William (not registered) on Mon, 2009-06-22 23:07.

Excelent tutorial :)

It works on Ubuntu Netbook Remix.

Submitted by Anonymous (not registered) on Sun, 2009-06-21 22:43.
I was very new to the ubuntu and i was always afraid of using linux commands but after reading your steps to install LAMP on ubuntu, i tried installing it and i did it successfully. I can say that i cannnot find any thing better then the steps you have given to install LAMP on ubuntu. Thanks for such Precise and clean steps.
Submitted by Unknown Hero (not registered) on Sat, 2009-06-20 21:48.

Thank you very much for this guide!


Works like a charm!

Submitted by Micha (not registered) on Fri, 2009-06-19 21:05.
Great guide, thanks!
Submitted by dinesh (not registered) on Thu, 2009-06-18 20:17.
thanks dear.this guide became v usefull to me.thanks a lot.
Submitted by thameera (not registered) on Thu, 2009-06-18 14:54.
It was one of the best guides I've ever read! Works perfectly in Ubuntu 9.04. Thanks a lot! Good luck!
Submitted by Alpha (not registered) on Wed, 2009-06-17 21:50.
Thanks, this LAMP instruction really help. Great help.
Submitted by Kalpesh (not registered) on Sun, 2009-06-14 18:51.
Thank you very much. This is a great tutorial on installing LAMP on Ubuntu.
Submitted by Jeroen de Ruiter (not registered) on Sat, 2009-06-06 20:22.
Thanks for such an easy step by step tutorial. Installing LAMP this way was even easier than installing WAMP on my XP machine.
Submitted by Kamal Nandan (not registered) on Sat, 2009-06-06 15:19.

very useful article..though had got stuck in between while using "mysql -u root", but made do with "mysql -p". Thanks a ton...:-)




Submitted by Dinu (not registered) on Fri, 2009-06-05 17:32.
ya i installed successfully thanks man.but i was confused slightly in middle and in last.anyone i manage it. thanks a lot.
Submitted by Cata (not registered) on Fri, 2009-06-05 04:07.

Simple and at object. It was very helpfully for me.Thank you

Submitted by Jim (not registered) on Thu, 2009-06-04 22:07.
Thanks, this was great!  Worked on the latest Ubuntu.
Submitted by Jiao.Zhang (not registered) on Thu, 2009-06-04 16:27.
Thanks for the clear tutorial, I had no trouble when installing LAMP in Ubuntu9.04 following the instructions.
Submitted by Totte (not registered) on Wed, 2010-01-13 20:31.
Great guide, was really looking for a good one and just checked this out. Thanks a lot!
Submitted by Wouter (not registered) on Sun, 2009-05-31 05:42.

Dear Sir,

Happy to inform you your How-to works with Ubuntu 9.04.

A good and easy to follow how-to. Tanks a lot.



Submitted by Jeremy (not registered) on Thu, 2009-05-28 12:52.

Thanks for the guide, I used it to manualy install LAMP on Ubuntu 9.04 Jaunty Server. If anyone is reading this and wants to install manualy as I have done simply follow the guide as written above replacing all references that contain

 sudo gedit <command here>


 gksudo gedit <command here>


 sudo pico <command here>

Submitted by Anonymous (not registered) on Tue, 2009-05-26 17:58.
Very useful tutorial, thanks for writing it.
Submitted by Anonymous (not registered) on Fri, 2009-05-22 23:46.
Submitted by jgalapatt (not registered) on Wed, 2009-05-20 16:20.
The step by step instructions were very helpful. Thank You
Submitted by Rajat (not registered) on Mon, 2009-05-11 17:19.
Great work man. material really helped.
Submitted by nguy (not registered) on Fri, 2009-05-08 15:24.
Great Help
Submitted by Parag (not registered) on Sat, 2009-05-02 21:06.

Thank you, very good tutorial, now I have LAMP set up on Ubuntu 9.



Submitted by Laurence (not registered) on Sat, 2009-05-02 07:42.

Great guides. Used it for Ubuntu 8.1 desktop.

 couple of slight differences:

1. It will auto ask you for a password for the mySQL database - so you dont need to manually enter the commands

2. the ";" section isnt needed - because it now starts as ""

 HOWEVER: if you want to use mysqli (<- see the "i" extension) commands you need to:

gksudo gedit /etc/php5/apache2/conf.d/mysql.ini

and add the line

 Restart the apache server and it will work


Submitted by guru katre (not registered) on Tue, 2009-04-28 10:50.

hi above document is really very good. i really thank. i have installed apache php and mysql in my pc

thanks :)

Submitted by Mike (not registered) on Mon, 2009-04-27 23:09.
While I realize the article was published quite a while ago, I just wanted to add that I also found this extremely helpful and I thank you for adding it. Wonderful job!
Submitted by Anonymous (not registered) on Sat, 2009-04-25 12:21.
Great Tutorial....
Submitted by harry (not registered) on Fri, 2009-04-24 09:27.


 I followed the above steps in installing lamp server but when I tried to connect to mySQL.. the below error occurs


ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

addition info:

apache works fine

php works fine

I have changed my bind address

I have changed php.ini file to get PHP to work with MySQL


plz help

Submitted by muscle boy (not registered) on Tue, 2009-04-14 10:56.

Thanks for the very great guide.i almost finish all of your instructions but i encountered some problem on ubuntu 8.10 which may be related to get php work with mysql.

the line ; doesn't exist,i just found ;

after i read the comment above,i can find line  extension=mysql in /etc/php5/apache2/conf.d/mysql.ini

typing gksudo gedit/etc/php5/apache2/conf.d/mysql.ini into terminal will find line

great tutorial,thanks a lot.



Submitted by Phil (not registered) on Sat, 2009-04-11 08:55.
My first go with linux and it worked great hope it is all as easy as this now I am off to netbeans
Submitted by ionoff (not registered) on Wed, 2009-04-08 20:52.

Don't follow this guide, just run

sudo tasksel install lamp-server


Submitted by ck (not registered) on Sat, 2009-03-21 19:02.

[sudo] password for ck:
sudo: nautilus/var/www: command not found





Submitted by chepe263 (not registered) on Sat, 2009-07-04 22:56.

There is a simply way


sudo nautilus, input password and go to /var/www


more easy can't be !

Works fine with ubuntu 9.04 (now i'm downloading mysql)+

sorry for my poor english


Submitted by AQIL (not registered) on Tue, 2009-03-17 09:26.

Thank you very much, it is very clear and help full article.


Submitted by Felipe Silveira (not registered) on Sun, 2009-03-15 16:51.
great article!
Submitted by Bernald (not registered) on Fri, 2009-03-13 12:16.

Hey, this article has been great to me and I have really loved that straight to point idea.

 We are new users of UBUTU and very excited to be part of the family.



Submitted by Anonymous (not registered) on Fri, 2009-03-13 00:38.
great and simple tutorial, does exactly what it does on the tin, worked fine and made me feel like I'm getting somewhere with this Linux jazz! Thanks for the help!
Submitted by Anonymous (not registered) on Mon, 2009-03-02 17:47.
Good job. It helped a lot!
Submitted by Anonymous (not registered) on Sun, 2009-03-01 10:13.
No trouble at all for this raw Linux newbie.  Thanks a bunch.
Submitted by Steve (not registered) on Sat, 2009-02-28 11:36.

Great tutorial, worked through it ok with just one or two things which I was able to figure out myself (MySQL Password, and Selecting to install for Apache 2).

Perhaps it is time that you ran through the process again yourself  and made the appropriate changes.

Otherwise great job.

One thing which did come up at the end when I restarted Apache2 was the message

Could not reliably determine the server's fully qualified domain name using (IP Address) for ServerName.

Any pointers as to what is happening and how I can fix this if it's a real problem?


Submitted by mikkey (not registered) on Wed, 2009-02-18 07:57.
Hi I m configuring SIT, but i am facing some problems:

1) We couldn't find configuration defaults, this probably means your include_path is wrong. Your current include path is .:/php/includes:/var/www/sit/includes
SiT! Requires its libraries to be in the include path which is specified in your php.ini file, modify your php.ini and set the new include path to be .:/php/includes:/var/www/sit/includes:/opt/lampp/htdocs/xampp/sit/includes

2) DB connection problem

Configuration Problem: Could not find database connection information (, the php include path is probably wrong

How to create and connect to the data base.

Please Help

Thanks in advance
Submitted by Jonathan (not registered) on Wed, 2009-02-11 22:17.

Great tutorial! Was able to install all without any issues.


Submitted by patv (not registered) on Sun, 2009-02-01 07:37.

I have not used Linux since 2001 and now I have a LAMP system running on my desktop.  Tutorial is good.

But what do I do now.  How do I start a web page for the world to see.

If anyone can point me to another great tutorial, thanks in advance.

Stay Cool.


Submitted by frank (not registered) on Fri, 2009-03-13 04:39.
put any web page (a file built with html andending  with .html) in the directory '/var/www'
Submitted by stussy (not registered) on Sat, 2009-01-31 04:43.
Worked just fine!  Only had to add the servername.  Thanks mate!
Submitted by ushan (not registered) on Mon, 2009-01-26 08:52.
ur tutorial is great. but i hav a little prob with php.ini. actually i am new to ubuntu. in my php.ini the line was not like ";". it was like this ";". what should i do? please advice
Submitted by jerdiggity (registered user) on Sat, 2009-01-10 10:01.

Wish there were more tutorials out there like yours... Awesome!

 In fact (I hope I'm allowed to post this part...) I was following your directions (but I was installing onto a fresh Kubuntu setup) and I had no problems.  Only difference (in case anyone uses KDE) was replacing which commands to run (SIMPLE, though):

  • Instead of typing gksudo I just typed sudo and
  • Instead of typing gedit I typed kate (although kwrite would have worked just as well...)

Either way, thanks VERY much for your help.

Submitted by Ken Nielson (not registered) on Sat, 2009-01-03 16:10.

Your how to guide for installing lamp on Ubuntu was great. Everything worked just like the instructions. The way it always should be.

 I did find that the password for mysql was automatically set in the script so I did not need to use the mysql command line to set the password.

 Great Job. Thanks

Submitted by oscar (not registered) on Wed, 2008-12-24 02:20.
well just want to tell you that your tutorial works really great i tried it with ubuntu 8.10 intrepid, and i encounter no problems whatsover, thank you for taking the time to make such a great tutorial. thanks again.
Submitted by Brockley Steve (not registered) on Thu, 2008-11-27 21:18.


I also had the problem with " mysql -u root " as it had already prometed for a password when installing. mysql -u root -p got me in and "exit" got me out again.

Finaly came to a halt with "Couldn't find package phpmyadmin "

Now trying to fix repositories........

Submitted by Hemant (not registered) on Tue, 2008-11-25 14:02.
It worked for me perfectly.. Thanks a lot
Submitted by Silvia (not registered) on Tue, 2008-11-25 02:29.
Muchisimas gracias por el tutorial...excelente
Submitted by gearbox (not registered) on Sun, 2008-11-23 16:43.
Thx !
Submitted by Mihai (not registered) on Fri, 2008-11-21 18:09.

This really helped, i was used to windows xamp & wamp managers, having some files of their own and management ghizmos of their own.

I just set up my first Ubuntu Studio, (i have had previous linux installs, lurking quasi unused on my computer), now i permanently deleted windows and deffected from the ranks of windows users.

This guide was straight forward enough and simple enough to actually be done in 5 minutes.




Submitted by Daf (not registered) on Thu, 2008-11-20 21:42.

Great Tutorial writing.

Easy to follow.

My problems are here:-

Option (2)INSTALLING MYSQL.... tell us how to find our IP address please!


mysql -u root


ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
bash: syntax error near unexpected token `('

Wonder whether you can help..?



Submitted by Anonymous (not registered) on Thu, 2009-01-15 16:29.

a bit late?


root@ubuntu:/# mysql -uroot -p

 press enter and the shell will ask you for the password.

new mysql versions require the option -p (for password) when you login in.



Submitted by Emil (not registered) on Mon, 2009-10-26 10:02.

When I follow your instruction on my Ubuntu Jaunty rootserver, I get this error message:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


any Ideas? is there a clearer tutorial anywhere?

Submitted by Emil (not registered) on Sun, 2009-11-08 14:33.

I have the same problem(using Ubuntu Jaunty 64bit).

No solution in sight?

and it has nothing to do with missing ' as there are no ' in mysql -uroot -p


Can anyone help?

Submitted by cordlafond (not registered) on Mon, 2008-11-24 20:55.
Did you perhaps loose one of the ' marks when you changed the password?
first page
previous page
next page
last page