Installing LAMP On Ubuntu For Newbies

Do you like HowtoForge? Please consider supporting us by becoming 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 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 ';extension=mysql.so' in the php.ini file instead i found ';extension=msql.so' and changed it to extension=mysql.so by adding 'y'.

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

Hey,

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 Arvind Kumar Chaubey (not registered) on Wed, 2010-08-25 13:18.

Hello

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.

Arvind

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.

Hi,

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

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

Regards,

Ruwan Wickramarachchi.

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 'extension=mysql.co' changed to 'extension=msql.co' 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:
;   extension=msql.so

But it should be corrected to show:
;   extension=mysql.so

 

I also added another line :
;   extension=mysqli.so

 

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 virtually..rest is much fine..have great development guys.take care.

raju aryan

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..

Cheers.

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

Bookmarked!!!

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.

Submitted by Stretch (not registered) on Thu, 2010-04-29 21:10.
Great Guide, very simple and to the point.
Submitted by Wasfi (not registered) on Mon, 2010-04-26 20:26.
I decided to cut off microsoft and all it's products and was really stuck with using mysql on ubuntu but u came to the rescue .. God bless you
Submitted by Anonymous (not registered) on Mon, 2010-04-26 13:59.

how i uninstall all that i installed.

everything was woking but after a restart i tried to change data base password now i get error in phpMyAdmin

Error

#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)

so it thinking just unstall the whole thing and try again.

Submitted by jeremy (not registered) on Sun, 2010-04-25 08:17.
a lot
Submitted by JimNYC (not registered) on Sat, 2010-04-24 00:11.
I didn't realize how relatively painless this could be on ubuntu. my thanks
Submitted by Anonymous (not registered) on Wed, 2010-04-21 21:36.
Thanks, that was painless.
Submitted by Mykell (not registered) on Mon, 2010-04-19 06:45.

But one more question about phpmyadmin:

 I got it to the point where http://localhost/phpmyadmin says 403 Forbidden. Any suggestions?

 (If it's relevant, I'm using Ubuntu Hardy Heron, and my webpages are in /usr/local/apache/htdocs)

Submitted by pankaj (not registered) on Sun, 2010-04-18 10:07.

thank you..

you made it easy to configure.

thanx a lot

Submitted by Anonymous (not registered) on Sun, 2010-04-18 08:52.

I really appreciate this how-to!

I'm building a website for a club at school, and I needed a LAMP server to create it on. I've looked at several tutorials, and this was the only one that even steered me anywhere near the right direction. Thanks to this, I can finally get to work on the site!

Submitted by Anonymous (not registered) on Thu, 2010-04-15 08:56.
Thank you so much for providing this excellent tutorial on LAMP configuration
Submitted by mah! (not registered) on Thu, 2010-04-15 01:43.
thank you for your guide given... i've learned so many things... thank you again...
Submitted by Anonymous (not registered) on Mon, 2010-04-12 02:59.
This was unbelievably helpful. THANKS
Submitted by Cyndi (not registered) on Thu, 2010-04-08 18:59.
Awesome newbie instruction.  Thanks!!
Submitted by Andiluvslinux (not registered) on Sat, 2010-04-03 08:22.

Hey Cargoship,

Your instructions were absolutely brilliant for me as a newbie in linux. Love the easy understandable instruction, though I wasn't quiet sure about one thing. I had to change the bind-address to my ip. Does that mean I have to change it to the IP address to the one assigned by my LAN or are you refering with that to the WAN address? As I said, these are my first steps in web-server doings. But otherwise awesome site ! Well done !

 regards andiluvslinux 

Submitted by Dazza (not registered) on Fri, 2010-04-02 14:39.

Nice guide.  Brief but all the right info in the right places.

 

Cheers!

Submitted by Artem (not registered) on Tue, 2010-03-30 03:47.

Many Many Many big THANKS!!!

I'm newbie to this and it not just helped, I installed everything almost w/o any troublems... Well one of the comments helped me with one problem but it was nothing big.

Installed it, now to learn how to use all this crap! LOL

THANKS A LOT again!

Submitted by Arpan (not registered) on Fri, 2010-03-26 15:49.

Thanks man!

I installed everything very smoothly with your help.

Can you please tell me a good manual for mysql.

 Thanks in advance for your help

Submitted by Anonymous (not registered) on Sun, 2010-03-21 23:02.
great instructions ! -- thanks
Submitted by MPG (not registered) on Wed, 2010-03-17 02:25.

In phpMyAdmin I get "No Privileges" under the area to create a new database.

 I get this on my account (MPG) and root...

Submitted by 除草 (not registered) on Tue, 2010-03-16 11:41.
Thank you very much. This guice is useful, just for the new PHPer.
Submitted by Mostafa (not registered) on Mon, 2010-03-15 10:17.
When trying to save the php test file to /var/www i get the "you don't have permission to save file here" error. should i change the permission of the folder or not? Actually i'm a noob in ubuntu and i read somewhere that it is better to not change the permission of the var folder. so what shall i do now?
Submitted by Anonymous (not registered) on Thu, 2010-03-25 18:37.

Did you use

sudo gedit /var/www/testphp.php

for editing the file?

The "sudo" is important to temporarily get root privileges.

Submitted by jester (not registered) on Fri, 2010-03-12 05:29.

you also need to 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
 save it and restart apache:
sudo /etc/init.d/apache2 restart

Submitted by Anonymous (not registered) on Sat, 2010-05-29 04:38.
Thanks dude, its really help me.out to phpmyadmin work correctly..
Submitted by Chris (not registered) on Fri, 2010-03-12 05:11.

Great post...

You said it was newbies...that wasn't the case since my installations took some turns that newbies might not logically put 1 and 1 together, ya know?

But you surely made it easy for me... Thanks again!

Submitted by Anonymous (not registered) on Fri, 2010-03-12 03:55.
this was quick and easy not hard at all the pasword thing throw me off cause it just pushed me into making a password i didnt need to go through the password step but not hard at all
Submitted by milamoto (not registered) on Thu, 2010-03-11 18:50.

Your tutorial is excellent.

Thanx!

Submitted by anand ganti (not registered) on Fri, 2010-03-05 01:53.

good great post

 

Submitted by Anonymous (not registered) on Wed, 2010-03-03 23:13.
Simply thank you!
Submitted by Ravi Veliyat (not registered) on Wed, 2010-03-03 09:59.

I have used php-mysql in windows already...

but i was totally unknown to Linux or Ubuntu..

then the guidelines provided by you helped me..

i found it very easy to install php in ubuntu..

 

Thanx man..!

Submitted by Anonymous (not registered) on Sun, 2010-02-14 11:38.
Many thanks for your Lamp Install guide. As a newbie I found it very easy to follow. It worked perfectly without a hitch.
Submitted by outstanding! (not registered) on Sat, 2010-02-13 01:30.

Thankyou!

 

This was perfect for a newbie like me.  Please, write more guides just like this.

Submitted by Anonymous (not registered) on Thu, 2010-02-11 20:11.

Needed a quick and dirty way of getting a LAMP environment going (I haven't touched *nix in ages) and your guide was a Godsend!

 

Nice job - thank you!  :)

Submitted by James (not registered) on Mon, 2010-02-08 23:45.

This was much easier than the xampp on Ubuntu install I did a couple months ago, which involved searching to solve "after install" problems. But your nice simple straight forward guide?... No problems at all. Everything works. Beauty!

And now I have a bonafide real deal lamp install :) - Sweeeeet!

Submitted by Da Vidis (not registered) on Thu, 2010-02-04 14:27.
Many thanks, the LAMP installation was smooth
Submitted by kostaslivs (not registered) on Wed, 2010-02-03 13:27.
THE BEST!
Submitted by Lippy (not registered) on Sat, 2010-01-30 18:06.
Thanks for the guide.  Made installing everything easy for a course I am taking that requires I create a database and front end website in php for it.
Submitted by kingkeamo (not registered) on Fri, 2010-01-29 10:26.

great tutorial thank you

 

Submitted by Juan Alejandro ... (not registered) on Sun, 2010-01-24 20:59.

Hi I installed the lamp on my ubuntu server and everyhitng is almost perfect just one problem.

 

I finished all but when i try to get into my /ipaddress/phpmydmin it is not working yet.

 

Can you tell me pleae how i can browse in my phpmyadmin page.

 

 

Thanks a lot.

Submitted by A. Self (not registered) on Sat, 2010-01-23 23:44.
I am new to Linux and definitely appreciate the easy walk-through on this process. Thanks!
Submitted by Bilal Malik (not registered) on Tue, 2010-01-19 19:10.

It was great help.

Thanks,

Bilal

Submitted by Joel (not registered) on Sun, 2010-01-17 16:36.
Had installed all the packages but was stuck with trying to figure out how to run the test scripts i was writing for the tutorials. All of them just said to post it to the web server document root and while i knew what that was, dint know where the local root was for apache! Anyway thanks again... i was getting desperate enough to consider just wamp and learning php.
Submitted by johny (not registered) on Fri, 2010-01-15 15:09.
Dont worry, your tutor was really helpful and easy to follow, 5 stars!!! ;-)
Submitted by Mark (not registered) on Wed, 2010-01-13 12:43.

I followed your instructions and it all worked perfectly first time.  The only difference was that the MySQL and PHPMyAdmin both prompted for passwords and usernames etc so there was no need to tinker with configuration files.

 Nicely presented HowTo.

Submitted by sunil (not registered) on Tue, 2010-01-12 20:27.

hi sir

 after completion of Lamp installation on my system and when i am trying to open the following url i.e http://localhost/phpmyadmin it says phpmyadmin was not found on this server.So please do reply

 

Thanks and Regards

Sunil Jadhav 

Submitted by Sree (not registered) on Tue, 2010-01-12 03:23.
Thanks..
Submitted by john (not registered) on Sun, 2010-01-10 19:16.

Hey!!

 Bro that was smoooth sailing for me!! Thanks a lot.

 For your first tutorial it was really good!

 

Submitted by MSK (not registered) on Sun, 2010-01-10 15:56.
extremely useful. thanks
Submitted by Dave (not registered) on Sun, 2010-01-10 13:07.

Had to add LAMP via a remote system and it worked just fine with a few differences:

1) MySQL version  5.1.37-1ubuntu5 prompted for the root password thus eliminating the tricky part.

2) Didn't find the  ;extension=mysql.so  entry in php.ini, so I didn't make that change and as of yet, I am not experiencing any issues.

 Very helpful post

 Thanks

 Dave

Submitted by i hate mondays (not registered) on Sat, 2010-01-09 10:54.

well,thx helped me a lot...

 i had project to make  and it was kind of impossible to make under windows.and now ,after rethinking some stuff,i would love to permanently change my os to linux... 

 u should make more tutorials for newbs...there are a lot of us out here:))

Submitted by deeba (not registered) on Fri, 2010-01-08 11:14.
excellent job.thank u....
1
next page
last page
Sponsored Links: Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com

One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com

One number. one voicemail. Seize the lead with Sprint. Learn more

AT&T Synaptic Compute as a Service. Boost your power on demand.

Trial: IBM Cognos Express Reporting, Analysis & Planning

Learn benefits of Simpana software.
View the Gartner Video

Sprint 4G - The Ultimate Mobile Broadband
Click here

SAP-Business Objects Crystal Reports Server
Complete reporting without hidden costs. Free Trial