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

Wouter

 

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>

 or 

 gksudo gedit <command here>

 with

 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.
SUPERB! THANKS SO MUCH FOR THE HELP!
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.

Parag

http://narayank.blogspot.com

 

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 ";extension=mysql.so" section isnt needed - because it now starts as "extension=mysql.so"

 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

extension=mysqli.so

 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.

 hi,

 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 ;extension=mysql.so doesn't exist,i just found ;extension=msql.so

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 extension=mysql.so

great tutorial,thanks a lot.

Ramon

 

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

Tada

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

[sudo] password for ck:
sudo: nautilus/var/www: command not found
ck@freekbox:~/Desktop$

 

?????

wadoidonow?

ck

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

There is a simply way

 type

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

chepe263

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.

 

cheers

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?

Steve

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 (db_connect.inc.php), 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.

Thanks

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.

Thanks.

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 ";extension=mysql.so". it was like this ";extension=mssql.so". 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.

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

hello

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.

 Thanks!

 

 

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!

Then:-

mysql -u root

gives:-

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


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


Wonder whether you can help..?

Thanks

Daf

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

a bit late?

 anyways,

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.

 

Rabie.

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

Jim

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

TKS

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 127.0.1.1 for ServerName"

Solution:  Add a directive "ServerName myserver" to apache2.conf and add "127.0.1.1    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 ;extension=mysql.so 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 zaphu.com 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 "extension=mysql.so" 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
        </Directory>

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 (extension=mysql.so)

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

first page
previous page
5