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 Lawal Adekunle (not registered) on Fri, 2008-11-14 11:48.
God i wish all guides were like this! I am so thankful for this, Its so easy and straight to the point. Thanks a Million. really.
Submitted by JIm Lees (not registered) on Wed, 2008-11-12 17:28.

I'm new to Ubuntu. I've just installed 8.10 as experiment since I normally run PCLOS.

As with everything I've tried to do under Ubuntu, I've found nearly everything I've tried to do more complicated than it needs to be!

  Having said that-- I found your first effort to write a howto very clear and concise.

Thank you.


Submitted by Giovanni (not registered) on Tue, 2008-11-11 14:39.

very good guide, all done well!!!

Submitted by Jonathan` (not registered) on Fri, 2008-11-07 05:25.
Straightforward and fast, an excellent guide for getting LAMP up quickly on *buntu. Many thanks and kudos!
Submitted by Sadiq (not registered) on Thu, 2008-10-30 08:27.
I am very thankful to this. I have installed lamp without any error.
Submitted by jay (not registered) on Wed, 2008-10-29 00:26.
This actually worked for me. no hitch at all. Veru good tutorial. The problem is, when I accessed my www ( root folder )  folder i don't have permission to add, paste, delete or create folder. The ownership is on root. Is there a way I can modify this so I can add new files therein? Thanks
Submitted by kyle (not registered) on Sat, 2008-11-08 06:24.

On the desktop, right-click, create launcher. Then application in terminal, then type in "sudo nautilus /var/www". Then just run the launcher from the desktop and you should be fine.

@Tutorial Writer

Worked great, thanks for the post :)

Submitted by Bruno Silva (not registered) on Mon, 2008-10-27 19:30.

TOP 10


Submitted by Anonymous (not registered) on Sat, 2008-10-25 15:07.
Everything worked perfectly fist time, thank you very much for a great tutorial.
Submitted by Anonymous (not registered) on Sun, 2008-10-12 17:26.
Wonderful article. It helped me a lot! Thank you.
Submitted by Lagavulin (not registered) on Sun, 2008-10-12 16:08.

Thanks a lot, this was really helpful.  However, I encountered some problems on Ubuntu 7.04 which may be related to previous Apache installations, configurations and deinstallations.

 1.  Apache complained: "Could not reliably determine the server's fully qualified domain name, using for ServerName"

Solution:  Add a directive "ServerName myserver" to apache2.conf and add "    myserver" to /etc/hosts.

 2.  http://localhost did not work.

Solution:  Apache is listening on port 8081.  See ports.conf. 

 3.  Apache did not execute the php testscript but simply served the file.

Solution:  I had to activate the php module manually by creating a symbolic link:

$ cd /etc/apache2

$ sudo ln -s ../mods-available/php5.load mods-enabled/php5.load

Submitted by ZP (not registered) on Sun, 2008-09-21 09:17.

Thanks for the wonderful guide.

I also didn't need to edit php.ini for it was already edited but I couldn't restarting web server apache2.

it says: Unable to resolve host ... and  fails !

I'm totally a newbie and I'd appreciate it if you tell me if there is anything wrong.

Thanks in advance

Submitted by Hélio Évora (not registered) on Sat, 2008-09-20 13:21.

Thank you for this tutorial.

It's very good and it's help me to solve all my problems...

Hélio Évora

Submitted by Zmetser (registered user) on Thu, 2008-05-22 11:10.

First: Excellent work dude!

Second: I had to copy phpmyadmin into my document root directory to work http://localhost/phpmyadmin, with this command in shell:

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

# /usr/share/phpmyadmin/ is the directory where phpmyadmin installed
# /var/www/ is your document root directory

Submitted by mcmarwa (registered user) on Sun, 2008-03-02 13:30.

Thanks!  This worked very well, with one minor glitch for my particular case.  After installing mysql, I needed to start mysql with:

sudo /etc/init.d mysql start

Then everything else worked. 

Submitted by srodden (registered user) on Sat, 2007-10-06 11:00.
Thanks very much for the howto. i installed on Oct 5 and the php.ini you refered to near the end has no ; line to uncomment. Not able to log in using the root and password  set earlier but i haven't spent any time troubleshooting yet.
Submitted by zaphu (registered user) on Mon, 2007-08-20 04:43.
one can also add the desktop GUI to the server installation by following this guide on Enjoy your new LAMP server! 
Submitted by aromaman (registered user) on Sun, 2007-08-19 20:52.

Hi cargoship. I had problems, I'm afraid, and did not manage to get lamp operational. I've posted my questions on the forum, as requested by the admin. I'm new to Linux so I suspect I'm the problem, not your procedure.


Submitted by majikins (registered user) on Tue, 2007-08-07 06:49.
Hi Great howto - thanks! A newbie would not know to type 'exit' after step 3(MySQL section)to get to step 4. Cheers
Submitted by douglaslopezt (registered user) on Sat, 2007-07-28 01:45.
Excelent How-to, very usefull, very simple and efficent. Thanks a lot.
Submitted by DJ_Maiko (registered user) on Wed, 2007-07-18 23:09.

First off, thanks a ton for the awesome how-to. My only question is:

Do I have to be connected to the internet to get all of this started? I ask because I plan to set this up on a separate machine & I haven't picked up a router/nat yet. So I just want to make sure if I need that in place for everything to work properly w/out having to re-do it again if I start w/out internet connectivity.

Submitted by Cargoship (registered user) on Thu, 2007-07-19 09:44.
@DJ_Maiko - Nope you do not need an internet connection to get LAMP to work.
Submitted by Cargoship (registered user) on Wed, 2007-07-18 14:29.

Thanks for the comments everyone.

@ IronHide - Now just do whatever you want with your brand new installation!

@locutus_of_borg - I re-installed LAMP and it still seems to be in php.ini, but you are right it is also in mysql.ini. I am not sure it if makes a difference though.

@mihai331 - I think I might edit the guide to explain more the purpose of what people are doing. Like what they are downloading, and why they would edit this and that. Also maybe a few pictures for extra clarification.

Submitted by IronHide (registered user) on Tue, 2007-07-17 17:54.
 Great article! Easy to follow. Now what?
Submitted by ferret99 (registered user) on Tue, 2007-07-17 10:51.

    sudo apt-get install apache2 php5 mysql-server phpmyadmin

Worked for me. 

Submitted by locutus_of_borg (registered user) on Tue, 2007-07-17 10:47.

i followed your guide with my new installation of ubuntu server 7.04 (feisty) and everything worked exactly as you said.

one small correction in the part where you edit:  /etc/php5/apache2/php.ini

 it seems, they moved "" to /etc/php5/apache2/conf.d/mysql.ini so we dont really need to bother editing php.ini after all.

thanks for the guide, saved me the trouble of figuring out the correct sequence of packages to install 

Submitted by mihai331 (registered user) on Mon, 2007-07-16 01:32.
Just went through and it worked wonderful.
As a small advice. Maybe you should explain why some things are changed and maybe what other options one has depending on the purpose.

Great tutorial!
Thanks! :)
Submitted by srodden (registered user) on Sat, 2007-10-06 11:21.

I am running the 64bit version of Ubuntu 7.04 and I found that I could not log in with phpMyAdmin. It refused me with an error #1035. A little googling reveals that loading the mcrypt package fixes it.

sudo apt-get install php4-mcrypt


Now I'm in and running fine! 

Submitted by sudarshan (not registered) on Mon, 2009-06-01 12:34.

It is so nice that you took time to write such an awesome exaustive tutorial by doing everything in command line. It saved a great deal of time

Thank you

Submitted by Anonymous (not registered) on Mon, 2009-07-06 14:15.

I always thought there was a magical one liner to get LAMP up and running.

 Was it 

sudo tasksel install lamp-server


Submitted by Joe (not registered) on Mon, 2009-09-28 01:12.

Great Tutorial,

 A few additions if you are hosting a site on this,

Enable Apache Rewrite = ># a2enmod rewrite

nano /etc/apache2/sites-available/default

<Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

Submitted by J-man (not registered) on Sun, 2009-11-08 15:23.

My php.ini file doesn't have the ";extension..." line...

What should I do?

Submitted by sofazen (not registered) on Sun, 2011-10-23 17:12.

I sorted this out just adding it (

Thanks to the autohor for this outstanding step by step guide !!!!

first page
previous page