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:

http://localhost/

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:

http://localhost/testphp.php

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 = 127.0.0.1

And change the 127.0.0.1 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:

;extension=mysql.so

To look like this:

extension=mysql.so

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 Wild (not registered) on Thu, 2013-05-23 10:19.
Thank you so much. 2 thumbs up.
Submitted by inbrown (not registered) on Tue, 2013-05-21 22:44.
Worked perfectly.  Thanks for the tutorial!
Submitted by Hai Bui thanh (not registered) on Sun, 2013-05-19 14:58.
I highly recommend

This guide is very easy to follow

 

Submitted by Faraz Hashmi (not registered) on Sat, 2013-05-18 08:01.
This is a nice guide to install lamp, I have look @ this to recall all the process of the installation for lamp. THANKS!
Submitted by Yesaya (not registered) on Tue, 2013-05-14 18:59.

straight forward guide, thanks.

I would like to mention thought that the line to link php to mysql is a little different. mine said extention=msql.so instead of extension.mysql=so. I am using ubuntu 13.04.

 It works all the same.

thanks again. :)

Submitted by mike (not registered) on Tue, 2013-05-07 17:58.
Awesome guide, easy to follow, very well done. Thank you very much!
Submitted by Anonymous (not registered) on Sun, 2013-04-28 04:18.
I don't know about you guys but I prefer to install LAMP in a single click after reading about other methods.

 Don't know if you are allowed to link to other guides here or not but this one seemed to help as it had alot of screenshots, http://draalin.com/installing-lamp-on-ubuntu/

They had two different installation methods there too which was nice.

Submitted by Volodymyr Krupach (not registered) on Tue, 2013-04-09 11:58.
Nowdays to configure mysql you need just to type:

sudo apt-get install php5-mysql

 and restart:

sudo service apache2 restart

Submitted by miNo (not registered) on Tue, 2013-04-02 22:15.

when I installed everything worked good but now when I want to login into phpmyadmin I get message like this #2002 Cannot log in to the MySQL server

please help

Submitted by Anonymous (not registered) on Mon, 2013-03-18 16:23.
Try adding -p at the end of it so it'll look like "mysql -u root -p", it will ask   you for a password hopefully you remember it.
Submitted by Anonymous (not registered) on Thu, 2013-03-07 20:01.
I have followed your instructions on installing LAMP. I did not follow

Install MySQL Nr 2 (Optional).

 Now just restart Apache and you are all set!...........I got the following:

alex@alex-PC:~$ sudo /etc/init.d/apache2 restart
[sudo] password for alex:
 * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
                                                                         [ OK ]
alex@alex-PC:~$

Is this correct?

Kind Regards

Alex

Submitted by Peter N (not registered) on Wed, 2013-03-06 23:09.
Thank you very much for the excellent guide.  It is my first look at Linux and LAMP and I will use its resources to publish my own (historical) information with the goodwill and free of charge that you have done.
Submitted by Magnus (not registered) on Sat, 2013-03-02 18:26.
Thank you for the exelent, simple and working guide
Submitted by Manan (not registered) on Sun, 2013-02-24 21:55.
Thank You !!!!! You saved a lot of my time.....
Submitted by Ernie (not registered) on Wed, 2013-02-20 21:07.

Thank you, very helpful. Everything came up and is working.

 

Submitted by PetiteFleurBleue (not registered) on Mon, 2013-01-07 13:39.

I just have it done on Linux Mint Debian Testing,it also worked perfectly well

after adding the "cp" line suggested by Mauricio on 2012.10.08.

One difference was that "extension=mysql" was present in the .conf file as  "extension=msql" .

Only details changed, as the presence of menus to edit the mysql password or to choose between apache and another server. Maybe because it seems this tuto was writen in 2007 and then these menus didn't exist yet. 

Very useful, thanks a lot!

 

Submitted by Anonymous (not registered) on Tue, 2012-12-18 21:08.
Your tutorial was the fastest, most comprehensive lesson I have ever seen and best of all...it actually worked FLAWLESSLY! You are the man!!! Thanks
Submitted by Damian (not registered) on Thu, 2012-12-13 15:42.
I am trying to install LAMP on Ubuntu desktop 12.10 but when i go to follow your list using terminal  its not finding anything in the locations to install, any help would be appreciated..
Submitted by Anonymous (not registered) on Tue, 2013-02-12 18:49.

Did you run "sudo apt-get update"?

Submitted by Anonymous (not registered) on Thu, 2012-11-22 19:18.
excellent thanks very much
Submitted by munir (not registered) on Thu, 2012-11-15 00:10.
Yo
Submitted by Mauricio (not registered) on Mon, 2012-10-08 17:21.

In order to phpmyadmin works, you need to copy it to www:

sudo cp -R /usr/share/phpmyadmin /var/www

so, you can use it typing: http://localhost/phpmyadmin at your prefered browser. 
 

Submitted by Anonymous (not registered) on Tue, 2012-10-02 13:36.

Its really easy to install LAMP with ONE single command in ubuntu:

sudo apt-get  install lamp-server^ phpmyadmin

 

Copy past, and you are set. All you need to do to get started is add

extension=mysql.so

 to your /etc/php5/apache2/php.ini file

Submitted by Suresh (not registered) on Sun, 2012-09-09 07:35.
please say how to test the phpmyadmin that I have installed....
Submitted by Anonymous (not registered) on Sat, 2012-07-28 12:57.
If you get error when doing mysql -u root, do mysql -u root -p instead, it'll work. 
Submitted by Roderick (not registered) on Wed, 2012-07-25 05:58.
The steps you put here worked flawlessly, except that the file in your instructions "mysql.so" is "msql.so" in php.ini .  Perhaps it changed recently.
Submitted by Ben (not registered) on Mon, 2012-07-23 15:29.

Don't forget to start with:

sudo apt-get update

Thanks for the tutorial!

Submitted by userzero (not registered) on Tue, 2012-07-17 14:03.
Fantastic aide, have done this a fair few times now, always years apart and I always forget the coding, very simple and straightforward, keep up the good work...if you fancy doing a how to install j2ee on eclipse for linux anytime, let me know, I can never get it right! ;-)
Submitted by Kiran (not registered) on Fri, 2012-07-13 18:31.
That was real crisp and straight forward way of doing it. Everything worked wonderfully smooth. The only glitch I faced was that http://localhost/phpmydmin didn't open the phpmydmin interface. A search at the ubuntu forums provided the solution for that too. In case anyone else needs.

http://ubuntuforums.org/showthread.php?t=859338 

 

Submitted by Luis Palacios (not registered) on Thu, 2012-07-05 04:07.

Wonderful tutorial
It was very helpful, 100% functional

Easy to understand, and I learn a lot with this

 Thank you very much!!

Submitted by Steve (not registered) on Thu, 2012-06-07 23:28.
What directory location does this install default to for each app? Also could you change the installation location?  Any reason not to? Just curious, thanks.
 
 

 

 

Submitted by Anonymous (not registered) on Fri, 2012-05-25 08:50.
The lamp-server set up now has the ;extension=mysql.so in the /etc/php5/apache2/conf.d/mysql.ini .
Submitted by Alberto Magassela (not registered) on Thu, 2012-05-24 23:24.
Extraordinary.

I learned a lot from this tutorial.

thank you very much
Submitted by Hari Thakur (not registered) on Fri, 2012-05-25 15:17.
Thanks a Lot ..!
Submitted by Anonymous (not registered) on Wed, 2012-05-16 09:10.

thanks for your guide - I could installed everything alright

I think it would be even more helpfull if you explain how to reach phpmyadmin

 I used it before and after some thinking got to the configuration to be able to use it - I mean, 

 coping the content of /etc/phpmyadmin/apache.conf to /etc/apache2/httpd.conf

You could also say you get to phpmyadmin, not as an application but through the browser - I tried finding phpmyadmin application icon to run it! ;-(

Submitted by shijesh (not registered) on Sat, 2012-04-07 11:39.

Excellent guide .. was able   to install LAMP on my Ubuntu 11.10 in 30 mins..

 

Gr8 Job..

 

Best Regards,

Shijesh

Submitted by robsoles (not registered) on Sun, 2012-03-25 04:36.

I won't mind if anybody would like to explain to me how the following line leads to something that can't be configured and secured as adequately as stepping it all out as above here.

sudo apt-get install apache2 php5 libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-mysql

was just checking if much had changed since the last LAMP I set up....

Submitted by Anonymous (not registered) on Fri, 2012-03-23 00:15.

$ sudo gedit /var/www/testphp.php
[sudo] password for kelly:

(gedit:4824): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.OIV7AW': No such file or directory

(gedit:4824): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory
 

 

gksudo gedit /etc/apache2/apache2.conf

(gksudo:4889): Gtk-WARNING **: Unable to locate theme engine in module_path: "pixmap",

 $ sudo /etc/init.d/apache2 restart
apache2: Syntax error on line 232 of /etc/apache2/apache2.conf: Could not open configuration file /etc/phpmyadmin/apache.conf: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.
   ...fail!

I have no clue where to start! And the first two PHP and Apache installations are supposed to be easy! Oh no, I am scared! I must be an EXTREME newbie! Any help greatly appreciated! 

Thanks!

 

Submitted by Anonymous (not registered) on Fri, 2012-03-23 12:17.

 an easy way to lamp on ubuntu on a video

https://www.youtube.com/watch?v=YbdYXe-cTdY

Submitted by Albaraa (not registered) on Fri, 2012-02-17 05:32.
After I configure the file my.cnf using: gksudo gedit /etc/mysql/my.cnf

The following happens:

 (gedit:3714): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.LBQG9V': No such file or directory


(gedit:3714): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory


(gedit:3714): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.EXJE9V': No such file or directory


(gedit:3714): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory


(gedit:3714): Gtk-WARNING **: Attempting to store changes into `/root/.local/share/recently-used.xbel', but failed: Failed to create file '/root/.local/share/recently-used.xbel.DLTS9V': No such file or directory


(gedit:3714): Gtk-WARNING **: Attempting to set the permissions of `/root/.local/share/recently-used.xbel', but failed: No such file or directory

And when I open the file again it would be changed, but after doing all of the other steps I still cant access my, localhost/phpmyadmin 
 
 So any help is much appreciated, THANK YOU!
Submitted by Anonymous (not registered) on Tue, 2012-02-14 09:42.
I am receiving this error: (gedit:9535): Gtk-WARNING **: cannot open display. 
 
The error occurs during this step:

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

Submitted by Javier (not registered) on Tue, 2012-02-07 20:45.
I have a problem when I test PHP.

In step 4, in the browser, when I type http://localhost/testphp.php, it shows me that it can't connect to the server, and it doesn't show the page of php.

Then, when installing mysql, in step 3, I have this error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

I don know what to do, I followed the instructions one by one...

Thanks in advance.

Javier.

Submitted by Alek Silver (not registered) on Mon, 2012-02-13 08:54.

This error message means that you already set up a password for MySQL.

When you install MySQL in Ubuntu, it asks you to enter a password.(MySQL in the terminal window)   If you entered a MySQL password at install, then you need to type this to log into MySQL:

mysql -u root -p

It will then ask you for the current MySQL password for the user "root"

If you entered a MySQL password at time of install, you can skip the step in this tutorial where it tells you to create a password.

Submitted by irealrush (not registered) on Wed, 2012-01-11 13:02.
AWesome tutorial. thanks alot ! 
Submitted by Des (not registered) on Fri, 2011-12-16 13:08.

I am a complete novice, so any answer please in easy speak just like the great instructions. I was able to follow easily but have this

 could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for server name.

 

I have change the bind address to the ip addy i found on the network settings for this computer, what have I done wrong??

Thanks in advance

Des

Submitted by informaticien51 (not registered) on Sat, 2012-02-04 10:04.

you have made nothing wrong...this say that there is no dns server in your host.

You have no http://example.com adress..

 That s not a problem, because you access to your site via http://localhost

Submitted by Elly (not registered) on Wed, 2011-12-14 01:48.
Perfect! Thanks
Submitted by chika.tambun (not registered) on Wed, 2011-12-14 00:38.

install ubuntu server with lamp server then just add phpmyadmin package..

xampp like would be yours

Submitted by GuestHouse (not registered) on Mon, 2011-12-12 12:04.
Thanks a lot! Really easy guide to understand, this one goes right down to the hard drive archive. 
Submitted by Mani (not registered) on Sat, 2011-12-10 20:24.

Well it seems I got it all to work, thanks for the write-up.

Submitted by Anonymous (not registered) on Tue, 2011-12-06 05:20.
Thanks for making a guide that is easy to understand and doesn't have unnecessary information riddled throughout!  That is so hard to find.  Keep up the good work!
Submitted by Gavin (not registered) on Sat, 2011-11-12 09:45.

In the past running windows and apache after installing phpmyadmin all i did was go to http://localhost/phpmyadmin, not this doesnt work in this case and am wondering how I can access phpmyadmin to make changes.

 

I am running ubuntu 11.10 if that is of any help.

 

Thanks Gavin,

Submitted by Patrick (not registered) on Tue, 2012-01-03 06:25.

Gavin,

 

Add

Include /etc/phpmyadmin/apache.conf

to the bottom of your

/etc/apache2/apache2.conf

 file and restart the apache server

you will now be able to use

localhost/phpmyadmin

to access the program.

 -Patrick

Submitted by Koenigscat (not registered) on Wed, 2012-02-01 10:22.
Thank you man!

 also, after adding that line to the bottom of that file, apache needs to be restarted in order for phpmyadmin to show up in 'http://localhost/phpmyadmin'

for those who don't know, do the following

 sudo /etc/init.d/apache2 restart

Submitted by Paul (not registered) on Sat, 2012-01-14 23:51.

Thanks for the info Patrick!

I was having the same problem that Gavin was.

Submitted by Nicker (not registered) on Fri, 2012-02-24 23:16.
Thanks Patrick, that helps a great bunch.
Submitted by Arno (not registered) on Wed, 2011-11-09 11:37.
Great guide ! I Just followed the steps and everything worked immediately. Thanks taking the time to make this guide and for saving me a lot of time ;-)
Submitted by Akhenaton_2 (not registered) on Mon, 2011-10-31 10:53.

Very good guide, worked pretty well.

Sometimes I've completed with other sources for subjects like extension=mysql.so which was msql.so in my file.

And I had a little problem with phpmyadmin. The simlink was not created, just create it manually or copy the folder into /var/www.

Otherwise, it was excellent and very useful!

Submitted by Egirland (not registered) on Sun, 2011-10-30 21:00.

Followed instruction with full success! Thanks.

I preferred using Synaptic rather than apt-get.... so the mysql password has been asked me by a friendly setup window....

 

Submitted by Paul (not registered) on Sun, 2011-10-23 19:46.

Very good guide, easy to do, had it up in 1/2 hour!

 Thank-you

 Paul

 pnoblet@gmail.com

Submitted by Jason (not registered) on Wed, 2011-10-19 20:35.
Thanks man! Worked perfectly.
Submitted by Anonymous (not registered) on Tue, 2011-10-18 02:01.
This appears to have worked perfectly. Thanks so much
Submitted by mhdere (not registered) on Mon, 2011-10-10 20:32.
great, easy to follow. thanks
Submitted by grant (not registered) on Mon, 2011-10-10 16:19.
please add 'mysql -u root -p' with the "-p" into this tutorial. When using the command 'mysql -u root' I get an access denied, you must use the '-p' so that the system prompts you for the root password in order to continue with the rest of the tutorial. Thanks.
Submitted by Anonymous (not registered) on Wed, 2011-11-30 07:11.
Hi. I also have the same problem of mysql-u root giving me "ERROR 1045 (28000): Access denied for user 'root-p'@'localhost' (using password: NO)" even after I tried your suggestion of using "-p" it still gives me the same error". Help please
Submitted by Dan (not registered) on Sat, 2012-02-04 01:36.
Looks like you didn't leave a space between root & -p

If you use

mysql -u root 

and get an error regarding password then you probably already have a password set in which instance you should use 

mysql -u root -p 

 which will then prompt for the password which you have already written down ;)

Submitted by Anonymous (not registered) on Mon, 2011-09-19 14:49.
It worked with no hitches!
Submitted by Anonymous (not registered) on Sat, 2011-09-17 23:04.
thanks you!!!!!!
Submitted by edzams (not registered) on Thu, 2011-09-15 15:10.
Great job for a first timer. Appreciate it much. All the best.
Submitted by Akhenaton (registered user) on Thu, 2011-09-08 21:52.

Very clear and useful - thx !

 

Submitted by Amanda (not registered) on Sun, 2011-08-28 06:12.
This tutorial helped me figure out what I did wrong with my LAMP installation. Thanks for a great, very helpful tutorial!
Submitted by Joe (not registered) on Sun, 2011-08-21 07:23.

Tutorial went great until editing the php.ini file.

There is no ;extension=mysql.so entry in the php.ini file.

 

Ubuntu 11.04

Submitted by vijith vijayan (not registered) on Wed, 2011-09-07 18:10.
now its found,ok...
Submitted by Vi Jeh (not registered) on Wed, 2011-09-07 18:04.
I also have same problem in php.ini.edit
Submitted by Caeruleus (not registered) on Fri, 2011-08-26 09:34.
If you just searched the file for ";extension=mysql.so" you wouldn't have found it. There is a tab between the semi-colon and the word extension
Submitted by Berl (not registered) on Thu, 2011-08-25 08:51.
You find the ;extension = mysql.so by using the "extension" keyword in your search. just next,next,...
Submitted by Anonymous (not registered) on Sat, 2011-08-20 23:37.
Crystal clear and works a treat - thank you.
Submitted by Nuno Godinho (not registered) on Fri, 2011-08-19 22:29.
Cristal clear! You made it extremely simple. Many thanks to the authors of this article.
Submitted by Anonymous (not registered) on Sun, 2011-08-14 20:54.

THanks a ton for this article, the only problem i had was in the step to get php and mysql to work together, i couldnt find the specified line to edit =/

 

Submitted by Arun (not registered) on Sun, 2011-08-14 19:53.

Very easy to follow and works great ... excellent writeup.

Thank you 

Submitted by Anton (not registered) on Fri, 2011-08-12 12:50.
It works great! BUT indicate explicitly that with the command
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
you also install mysql extensions for PHP and Apache!
Submitted by rishi (not registered) on Fri, 2011-08-12 10:09.
am vry glad to convey my regards to u..i am beginner to linux...this tutorial helped mi a lot to learn more abt installin things in linux...hope every beginner try this tutorial lik mi ..thank u so much :)
Submitted by J Soe (not registered) on Tue, 2011-08-09 17:20.
I just wanna thank you for this great tutorial! :)
Submitted by akiara kalchek (not registered) on Thu, 2011-08-04 04:09.
Thank you alot for this guide.. i don't know how long this is on the net, but i used it today on ubuntu natty and works perfectly... thank you
Submitted by Emilio Vargas (not registered) on Tue, 2011-07-26 22:58.
Great Doc thanks so much for your post it worked wonderfully. love the way you present step by step commands. I'm new in the ubuntu world and very scare some times with this of terminals buy with docs like this soon it all be conquered.
Submitted by Juan (not registered) on Wed, 2011-07-20 16:13.

Thanks!

 Worked great!

Submitted by orbit (not registered) on Tue, 2011-07-19 19:36.
thanxxxxxxxxxxxxx a lot
Submitted by .Jebin (not registered) on Tue, 2011-07-19 13:35.

Very clear man.. and it work crystal clear.. Thanks!

 

Submitted by Kelly (not registered) on Sat, 2011-07-16 03:49.
You are the man. This tutorial was great. You got me up and running. Thanks a million.
Submitted by Yaron (not registered) on Wed, 2011-07-13 09:40.
Help me a lot. Thanks Again!
1
next page
last page