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 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!
Submitted by Anonymous (not registered) on Mon, 2011-07-04 16:55.
Thank you, very easy and clear tutorial !
Submitted by sheenu (not registered) on Tue, 2011-06-28 02:44.
All done in a jiffy... loads of thanks.... :)
Submitted by Caleb (not registered) on Mon, 2011-06-27 21:20.
Great guide! The only issue I ran into was step 3. I even tried it with sudo, didn't work. Found out that I already have MySQL installed, I believe that that may have been the issue. I am running on 10.10 and LAMP work beautifully. Thanks for the guide.
Submitted by KidGr (not registered) on Sat, 2011-06-25 09:53.
thanks a lot man.
i had a problem with mysql and i saw the link after i solved it!!!
Excellent tutorial
Submitted by Nikhil Baliga (not registered) on Fri, 2011-06-17 16:48.
Thank you for the excellent step-by-step procedure. 
Submitted by Melvin (not registered) on Fri, 2011-06-10 19:32.

I really must  say that you are very good what you teach. Thank you for your time and knowledge.

I install this to my Ubuntu desktop, but i want to know if it  possible to use any controller to access them as one interface (like a control panel).

I also will like to know if you can guide me through the ftp setup or openssh

Although i would have love to communicate with my Ubuntu Server 11 directly with a webmin, but i am having problem installing it.

it shows this error message any time i type

~$ sudo apt-get install ethtool
[sudo] password for mklaw: 'i typed password'

THEN error

Reading package lists.... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ethtool

 ANOTHER error

~$ sudo /etc/apt/sources.list
[sudo] password for mklaw: 'i typed password'

THEN error

sudo: /etc/apt/sources.list command not found

I am not sure  if it is referring me to the CDROM instead of the internet to download.

Please offer your warmest support.

 

 

Submitted by texas hold em (not registered) on Fri, 2011-06-17 12:47.
Great blog, and the author is surely cool! Pretty good, man!
Submitted by upul karunarathne (not registered) on Fri, 2011-06-10 01:41.
It's a great tutorial , help alot
Submitted by sabyasachi (not registered) on Wed, 2011-06-08 11:03.

It is really helpful.

 

Submitted by Anonymous (not registered) on Sun, 2011-06-05 17:11.

wow, just wow. amazing!!!!!!!!!!!!!!!!

easiest guide ever

Submitted by jonathan young (not registered) on Thu, 2011-05-26 01:20.
just wanted to say this is one of the best, most concise and easy to follow guides for doing something incredibly complex, kudos to you folks!  thank you!!!
Submitted by kuberprok (not registered) on Wed, 2011-05-18 20:02.
Brilliant!
Submitted by Anonymous (not registered) on Thu, 2011-05-12 21:17.

Great walk-through, works great!

Thanks

Submitted by Pramod (not registered) on Tue, 2011-05-10 19:22.
very easy yet very useful thanks a lot :)
Submitted by Madhawa (not registered) on Mon, 2011-05-09 07:40.
Very good post. It worked for me. Thank you.
Submitted by tiwigi (not registered) on Sat, 2011-05-07 17:18.
thank you, it was totally no pain ;) (in ubuntu 11.04 no need for last steps with mysql extension ... anyway works like a charm)
Submitted by Goga (not registered) on Sat, 2011-04-30 21:43.
Great job! Very easy to follow, and straight to the point! Thanks!
Submitted by Anonymous (not registered) on Sun, 2011-04-17 13:36.
neat elegant. very well done indeed!
Submitted by dexter (not registered) on Sun, 2011-04-10 15:39.

wat a site !!!!!!

superb!!!!

thnx a lot

Submitted by Ges Scott (not registered) on Tue, 2011-04-05 19:12.

Excellent! Thank you so much. You're tutorial is straightforward and so easy to follow. After quite a number of years using WAMP on windows I migrated to Linux using Ubuntu. I was very concerned about using/configuring my development environment. I had searched around for a way to use LAMP. I found you! Everything was/is up and running within half hour just by pasting your commands.

Once again thank you very much. More tutorials like this from you please!

Ges Scott

 

Submitted by Arun Prasad (not registered) on Thu, 2011-03-31 19:55.
It was very helpful. Thanks a lot for this wonderful information. You made my day. :)
Submitted by Shammancer (not registered) on Thu, 2011-03-31 05:18.
This guide is right at the point and tells you exactly what you need to do. Keep up the good work. 
Submitted by Anonymous (not registered) on Tue, 2011-03-29 17:11.
thanks a lot !!!
Submitted by Anonymous (not registered) on Fri, 2011-03-25 18:38.

This guide was invaluable, my mother in law sponsors a student where I live, and the student needs a machine as she can't afford one*. I have resurrected a 7 year old laptop with XUbuntu into a reasonably decent dev environment, so your altruism has helped people helping others, good karma :-).

Went as smoothly as ice, I'm a .net dev by day and  I love Linux, but my job keeps me pretty tied to MS operating systems. I only use Linux under VMs to keep my hand in. When my wife buys herself a new lappie, I have plans for the old one :evil grin:

* This is why I've remained anonymous.

Submitted by David (not registered) on Thu, 2011-03-24 08:40.

From fresh ubuntu installation to running phpmyadmin in about 10 minutes!

 Thanks

Submitted by bcow (not registered) on Mon, 2011-03-21 20:24.
Excellent guide! Thank you for taking the time to make it!
Submitted by RUBY (not registered) on Sun, 2011-03-20 17:21.
recently i switched over to linux mint 10 julia and am facing lot of problem with LAMP INSTALLATION.thati followed up the instructions given in the link http://www.howtoforge.com/ubuntu_lamp_for_newbies
and followed each step as mentioned but i skipped the following section
-----------------------------------------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. -----------------------------------------------
as i am working only in my laptop computer and i don't have ip too;

MOREOVER
DIALOGUE BOX ASKED ME IF I WANTED TO SET UP A DATABASE NAMED some conf.....(i don't remember clearly)
which i said no to;;as i d installed my sql earlier itself;;

it showed a couple of dialogue boxes asking to enter your password-which i did;;then
the rest of commands;;showed the following errors in the terminal

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

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





now that i have restartted the server and server is running;;;
it shows the proper:IT WORKS message for::::http://localhost/

and it does show the proper configuration for
http://localhost/testph.php



but for http://localhost/phpmyadmin

its showing
----Not Found

The requested URL /phpmyadmin was not found on this server.
Apache/2.2.16 (Ubuntu) Server at localhost Port 80----------


SOMEBODY PLEASE HELP
Submitted by walker (not registered) on Fri, 2011-04-15 08:17.

well, i had the same problem and, i solved it with:

use the command like this:

 mysql -u root -p

 after that you have to type your password, that is already exist if you add one before.

its worked to me fine. 

Submitted by Gosmo (not registered) on Tue, 2011-03-22 16:02.

You have to follow the next instructions:

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

Submitted by Abin V Paul (not registered) on Wed, 2011-11-02 06:55.
This was a great help
Submitted by Anonymous (not registered) on Thu, 2011-07-07 17:43.
brilliant! this was the only thing missing from the above tutorial, thanks!
Submitted by Bison (not registered) on Thu, 2011-07-07 10:22.
This should be added to the guide, I wouldn't have found out about it if I didn't check the comments section.
Submitted by Dawiss (not registered) on Fri, 2011-06-17 09:37.
Thanks, had the same problem.
Submitted by Anonymous (not registered) on Sat, 2011-06-11 17:38.
Thanks a million... never knew how easy it was, thanks.
Submitted by t0m3kk (not registered) on Wed, 2011-04-20 21:23.

Man, 10x for your post... I had the same problem but now the problem is solved and everything looks fine :)

Regards,

George

Submitted by Jorge Biquez (not registered) on Sat, 2011-03-19 02:23.
works like a charm!. Great !
Submitted by Anonymous (not registered) on Fri, 2011-03-18 16:35.

Work Great! Thanks!

Submitted by Frostraver (not registered) on Fri, 2011-03-11 23:23.
Very good guide! Thank you!
Submitted by Willy (not registered) on Thu, 2011-03-10 05:42.
This is an awesome guide; good work, I would like know about security and maybe how to link my data base with freeradius, and to a login portal page to authenticate wi-fi users.. would you happen to have a guide that you would like to share...
Submitted by RHYTHM (not registered) on Sun, 2011-03-06 16:41.
I am looking for a guide how to install a LAMP.. I spend how many hours just to look for the right site...that's why I'm very thankful that I've found this one!.. thank you... may our GOD blesses you in all aspects of your light.... GBU..
Submitted by Val Ian Enriquez (not registered) on Fri, 2011-03-04 08:10.
Thanks for the steps! :)
Submitted by Anonymous (not registered) on Tue, 2011-03-01 18:02.

thank you thank you thank you, what has taken me hours just took minutes you should be a tech writer way better than UBUNTU docs
atp

Submitted by shabeer (not registered) on Wed, 2011-02-23 13:05.
thanq dear , am also a new user and am very happy now
Submitted by Bitz (not registered) on Wed, 2011-02-16 04:20.

Thank you SO much... I'm a new user....and had some issues figuring this out...... gone through many forums and none helped.... until I got to yours!

 Once again  THANK YOU!!!!!!!!

Submitted by Kristofer (not registered) on Mon, 2011-02-14 15:11.

Great walk-through, but I got stuck in the end.

 Where I'm supposed to remove the semicolon.. Can't seem to find that special line ;extension=mysql.so ....

 Then when I try to restart Apache, nothing happens.

Thanks in advance! 

Submitted by Joema (not registered) on Sat, 2011-02-12 07:22.
I am Joe from China, Beijing.Thanks for your guide! its great!!! I am new to LAMP. I wish to know you. You can be my teacher.
Submitted by Anonymous (not registered) on Thu, 2011-02-03 03:51.
this works great.  thank you so much.  write more guides :)
Submitted by rsgracey (not registered) on Tue, 2011-02-01 17:07.
Wonderful instructions. Followed them with no difficulties whatsoever. One question: The date on this is 2007. Does it retrieve all the latest versions, or do I have to worry about that now?
Submitted by jarcmaster (not registered) on Sat, 2011-01-29 03:27.

 Those with the GKSUDO command  simply replace this line:

gksudo gedit ....

 with this one: sudo gedit ....

 

 

 

Submitted by Anonymous (not registered) on Sat, 2011-01-22 19:12.
Wonderful and easy to follow. Thanks!
Submitted by Anonymous (not registered) on Sat, 2011-01-22 09:51.

superbly easy setup instructions. Worked exactly the way you say.

 Thanks a bunch!

 

Submitted by Mike (not registered) on Sat, 2011-01-15 22:16.
Thanks, It is really very easy to set up LAMP by using this guide!
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?
first page
previous page
2
next page
last page