LAMP Installation On Ubuntu

The acronym LAMP refers to a set of free software programs commonly used together to run dynamic Web sites or servers Linux, the operating system; Apache, the Web server; MySQL, the database management system (or database server) and Perl, PHP, and/or Python, scripting languages.

This tutorial is how to install LAMP on Ubuntu Desktop.


Here are several steps to install Ubuntu Linux Desktop if you have not already done so.

  • First download and burn your own installation CD file from the Ubuntu Linux site or order a free CD from Shipit – Free CDs.
  • Second, try out your new Ubuntu Linux without changing anything on your computer by booting the installation CD. This is a great way to test compatibility with your computer.
  • Third, install Ubuntu Linux permanently on your computer by double-clicking the install icon on your temporary desktop.
    1. Download the Ubuntu Linux Desktop ISO CD image from the Ubuntu Linux site.
    2. Burn a bootable CD from the ISO CD image.
    3. Boot the CD on the target machine. Make sure the network is connected. If all is successful, Ubuntu Linux will start up in a fully functional friendly desktop environment. Experiment for a while if you like.
    4. Double-click on the installer icon on the desktop to permanently install Linux.
    5. Enter Name, Username, Password, and Time Zone. Set the clock if necessary. Choose automatic partition and format to erase the previous operating system.
    6. WARNING – This will wipe out everything on the target machine hard drive.
    7. Wait.
    8. Restart.
    9. Remove the CD to prevent starting over.
    10. Type Enter to boot.
    11. Login.


Install Apache

sudo apt-get install apache2

Testing HTTP Server by open a web browser and enter http://localhost


Install PHP5

sudo apt-get install php5 libapache2-mod-php5

Stop/Restart Apache

sudo /etc/init.d/apache2 restart

Test the installation

sudo gedit /var/www/testphp.php

Insert this following line into testphp.php file.

<?php phpinfo(); ?>

Save this new file.
Open a web browser and enter http://localhost/testphp.php
Be sure to remove the file afterwards, as it may pose a security risk.

sudo rm /var/www/testphp.php


Install MySQL Server

sudo apt-get install mysql-server

MySQL initially only allows connections from the localhost ( We’ll need to remove that restriction if you wish to make it accessible to everyone on the internet. Open the file /etc/mysql/my.cnf

gksudo gedit /etc/mysql/my.cnf

Find the line bind-address = and comment it out then save the file.
MySQL comes with no root password as default. This is a huge security risk. You’ll need to set one. So that the local computer gets root access as well, you’ll need to set a password for that too. The local-machine-name is the name of the computer you’re working on.

mysqladmin -u root password newpassword
mysqladmin -h root@local-machine-name -u root -p password newpassword
sudo /etc/init.d/mysql restart

MySQL Administrator

Install MySQL Administrator

sudo apt-get install mysql-admin

Refresh Gnome Panel

killall gnome-panel

Run MySQL Administrator
Applications -> System Tools -> MySQL Administrator

MySQL for Apache HTTP Server

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

To get PHP to work with MySQL, open the php.ini file

gksudo gedit /etc/php5/apache2/php.ini

You’ll need to uncomment the “;” line so that it looks like this

Restart Apache

sudo /etc/init.d/apache2 restart

Well done!

  • Alanlai

    Hi, i have a problem regarding this 2 command

    mysqladmin -u root password newpassword
    mysqladmin -h root@local-machine-name -u root -p password newpassword

    when you mean “password newpassword”

    do u want me to type that into my console as is??
    or should i change password to my PASSWORD e.g.”apple”

    and newpassword to something else?!!?

    and for local-machine-name can i type my ip like “” ?

    thanks for this easy to follow tutorial

    anyways, I interpreted you to mean type password as is, and in place for newpassword, we put in our own password, our choice.

    so what i did was

    mysqladmin -u root password apple
    mysqladmin -h root@ -u root -p password apple

    after the 2nd command, i was prompt to enter a password. Which i inputted apple.

    However, i got the error of
    “mysqladmin: connect to server at ‘root@klalaiold-desktop’ failed
    error: ‘Unknown MySQL server host ‘root@klalaiold-desktop’ (1)’
    Check that mysqld is running on root@klalaiold-desktop and that the port is 3306.
    You can check this by doing ‘telnet root@klalaiold-desktop 3306’

    for your info,,

    “root@klalaiold-desktop:/etc# netstat -tap | grep sql
    tcp 0 0 localhost:mysql *:* LISTEN 7648/mysqld ”

    Thanks for this great tutorial

  • AlanLai

    moreover, oh the 2nd time running the following command, i get the following error

    root@klalaiold-desktop:/home/klalaiold# mysqladmin -u root password apple
    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’
    root@klalaiold-desktop:/home/klalaiold# mysqladmin -h root@klalaiold-desktop -p password laiking1
    Enter password:
    mysqladmin: connect to server at ‘root@klalaiold-desktop’ failed
    error: ‘Unknown MySQL server host ‘root@klalaiold-desktop’ (1)’
    Check that mysqld is running on root@klalaiold-desktop and that the port is 3306.
    You can check this by doing ‘telnet root@klalaiold-desktop 3306’
    root@klalaiold-desktop:/home/klalaiold# telnet root@klalaiold-desktop 3306
    telnet: could not resolve root@klalaiold-desktop/3306: Name or service not known
    root@klalaiold-desktop:/home/klalaiold# netstat -tap | grep sql
    tcp 0 0 *:mysql *:* LISTEN 4182/mysqld

  • Speediii

    Mysql Administrator also hangs when you click on “User Administration.

    I fixed this by adding the following line to /etc/environment


  • hg-203

    heads up, if your installing on a vanilla Ubuntu install make sure you have your repositories set up to grab the community maintained repositories, if not you probably wont be able to install the mysql-admin package

  • Yea, Mysql Administrator is hanging for me as well.

    I made the DEBUG_DONT_SPAWN_FETCHES=1 adjustment but it is still hanging when I click on User Administration.

    Anyone else?

  • I think these blog is really useful for new comers and Excellent resource list.

  • AlanLai,

    Let’s try to solve this ๐Ÿ˜‰

    mysqladmin -h root@local-machine-name -u root -p password newpassword

    You can try this:

    mysqladmin -h localhost -u root -p password apple

    or you can remove -h attribute:

    mysqladmin -u root -p password apple

  • William

    So far, so good. Everything seems to be in order, so it’s time to push on and install WordPress. Many thanks for this excellent tutorial.

  • Pingback: links for 2007-02-12 at Just another geek()

  • Pingback: Computer » links for 2007-02-12()

  • fwiffo

    Installing mysql also forced installing postfix. Installing config needs configuring it with debconf. I had no idea how or why to do this, as I don’t need a mail server, need I? It would have been nice, if you had mention it or given some more info about it. Otherwise, thanks for the nice guide on installing lamp.

  • fwiffo

    Typo: of course, on the second sentence I mean “Installing postfix” and not “Installing config”. Sorry.

  • As a security precaution, I would advise against setting mysql to listen to the entire internet, instead, just make sure that all your PHP scripts reference the server as “localhost” or “” and it should work fine.



  • rrutia

    This procedure is to do LAMP install. Thanks..

    Does anybody know how to create a database after the installation is complete?

  • Pingback: LAMP Installation On Ubuntu « Microwave Biscuit()

  • Henry

    I am a Windows pro, Webmaster pro, and total Linux n00b.

    May I suggest that you also include instructions on how to modify apt-get to point to universe (and subsequently, to apt-get update)? In my installation, your instructions didn’t work because phpmyadmin and mysql-admin packages were not available.

    Took me a good half hour to figure out the whole universe thing.

    Thanks for the instructions, though.

  • dearblues

    why did i get did msg

    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
    Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!

  • dearblues

    and also. when i try to change to password again. i get this msg.

    one more thing. how can i delete all the installation and do one more clean installation.

  • To Create a Database:

    The easy way is through PHP MyAdmin, a web based MySQL front-end interface (and one of the packages installed in this tutorial.

    Log in with the root mysql account you created above. About half way down on the right side frame is a form for creating a new database.

    PS: Cool tutorial. I agree about a need to explain (or at least mention) the postfix config as it threw me too.

  • Pingback: Instaling Ubuntu 6.06 LTS Server (Dapper Drake) « Todor Ivanov’s Weblog()

  • Oscar

    Great tutorial. I had tried using XAMPP earlier but encountered some problems and I was convinced that XAMPP would be en easier choice. I was looking for the XAMPP instructions again and fell into this page (thank God). I thought what the heck and followed the instructions step by step. Everything worked fine exept installing phpmyadmin. I installed it using the same command used in this tutorial but after installing everything else. It works fine.

  • Pingback: LAMP Installation On Ubuntu Quick Tutorial()

  • Thanks for this gr8 LAMP guide. Got my Ubuntu LAMP shining brightly, for some home work over the weekend.

    Right back 2 work.

    Thanks again for posting this.

  • Pingback: Dr-Hamza’s Space()

  • There are many useful informations in this article. Thanks and greetings from Thuringia!

  • Ken

    Two small nits to pick:

    – Under MySQL Administrator, to start MySQL Administrator it is “Applications -> Programming -> MySQL Administrator”, not “Applications -> System Tools -> MySQL Administrator” – “System Tools” is wrong

    – Under MySQL for Apache HTTP Server, you need ADD “” it is not included but commented out,a s your tutorial says.

    Aside from the above nits, nice tutorial – off to install WOrdPress now (see you there)…

  • William: Thanks

    fwiffo: No problem

    Matt: Thanks for ur suggestion

    rrutia: You can run phpmyadmin or using command line to create database.

    Henry: You can edit /etc/apt/source.list and add universe repository

    dearblues: make sure your mysal is running by type sudo /etc/init.d/mysql start

    To uninstall mysql type this command
    sudo apt-get remove libapache2-mod-auth-mysql php5-mysql phpmyadmin

    George Nagy: Thanks for your suggestion

    Oscar: great

    Doug: Thanks

    Kunst: Greeting from Indonesia ๐Ÿ˜‰

    Ken: Thanks. Perhaps I will check for the version of Ubuntu

    Thanks a bunch…

  • Pingback: Linh tinh v? Lamp « Giangpd’s home()

  • Pingback: Installing Ubuntu 6.06 LTS Server (Dapper Drake) « Todor Ivanov’s Weblog()

  • Very good article, thanks for sharing

  • Hi – I’m getting this but that disc is long gone. Any workarounds?

    Media change: please insert the disc labeled
    ‘Ubuntu-Server 6.10 _Edgy Eft_ – Release i386 (20061025.1)’
    in the drive ‘/cdrom/’ and press enter



  • crashnburn007

    please note inorder to get phpmyadmin working I had to open /etc/apache2/apache2.conf and add the line…
    Include /etc/phpmyadmin/apache.conf
    then restart apache
    sudo /etc/init.d/apache2 restart

  • ray

    Hi,thaks for your tutorial
    but i’m got some trouble,when i type :

    sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

    and press enter,there an error issues

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    php5-mysql: Depends: php5-common (= 5.2.3-1ubuntu6) but 5.2.3-1ubuntu6.3 is to be installed
    E: Broken packages

    How to solve this?
    Thanks before

  • Pingback: Order of the Bath » Blog Archive » Installing LAMP on Ubuntu 7.10 Desktop()

  • Thanks for the tutorial.
    @ray: it works with me, maybe just a temporary bug?

  • Matt

    I’m having a similar problem as Ray. libapache2-mod-auth-mysql and php5-mysql both installled but getting error “E: Couldn’t find package phpmyadmin”.

    I’ll keep trying since it worked for Urlaub, but is there some other way to get this package?

  • Matt

    AHA! Need to set apt-get to look universal instead of just at E:

    Found directions here:

    don’t forget to update aptitude after editing
    sudo aptitude update

  • Darren

    Thanks a lot for this! Finally a tutorial that works!

  • this tutorial was very helpfull!

  • Pingback: Wordpress On Ubuntu , Lamp first ( Installing and understanding lamp on ubuntu For Newbies ) - Infection Control()

  • Lishy Guy

    Very useful tutorial, thanks! Is there any way to change the folder that localhost refers to? For example, could I change it so my localhost was ~/Web?

  • Drizz

    Ok theres a whole lot wrong with this tutorial. Where you say “Youโ€™ll need to uncomment the โ€œ;extension=mysql.soโ€” That doesn’t exist.
    I see, but there is no “;”.

    Also I’m having this problem:
    sudo /etc/init.d/mysql restart
    * Stopping MySQL database server mysqld [ OK ]
    * Starting MySQL database server mysqld [ OK ]
    * Checking for corrupt, not cleanly closed and upgrade needing tables.

    Also when typing “mysqladmin -u root password newpassword” I get: mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’

    And another problem: mysqladmin -h root@local-machine-name -u root -p password newpassword
    Gives me errors.
    This is ridiculous. Now I have a totally garbled install of all kinds of crap that doesn’t work.

  • putu

    I’m interested in using ubuntu 8.04 then I’ve got the cd.
    But the problem is I still affraid to install ubuntu, I’ve got 3 partition(C,D,E) now on my hardisk with Wind**s OS.
    If I would like to install ubuntu as you said that we just need to follow the instruction (automatic partition) how many partition will be created?
    Can I get more Partition?
    I do apologize for my english and thanks for your attention…
    Warmes greeting from Bali

  • Hi all,

    I followed the install-instructions above and everything works perfect.
    But now I have a question. How to create a mysql database now ?

    I am a real linux-newbie, sorry

    br, Kalle

  • I just saw the post number 17 but:


    does not work. I get an 404, because in /var/www nothing related can be found.
    Something wrong with the paths?

    br, Kalle

  • Pingback: Choosing a Flavor « Jason’s Linux Learning Journal()

  • Pingback: flotsky - just another geek » Blog Archive » links for 2007-02-12()

  • slamet

    I have trouble. I created file1 <? Klik ?> and file2
    File2 is not working properly. Do you explain it for me?

  • orluke

    when i followed this, i got hung up (ubuntu 8.10) at the steps

    mysqladmin -u root password newpassword
    mysqladmin -h root@local-machine-name -u root -p password newpassword

    the error i was getting:

    mysqladmin: connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’

    But then I realized that I had already installed and configured mysql on my machine a while ago (for use with amarok). I remembered the password I had used originally, and it worked fine. duh.

  • oockown

    just done..
    makasih banyak y ( ;

  • Pingback: Desktop Diary with LAMP and WordPress « Strug’s Blog()

  • Pingback: EC does IT » LAMP Installation On Ubuntu ยท supriyadisw dot net()

  • Sion

    Excellent notes, which have saved me a great deal of time. Many thanks for this.

  • Pingback: links for 2009-07-07 « Sigidisig()

  • Very nice tutorial..I just hope there was a tutorial like this for ubuntu server.One of the reasons why newcomers do not find linux very friendly is becoz of lack of proper documentation on nitty gritty things..but this one is gr8.
    thanks a bunch

  • Pingback: Wordpress for Everyone | Freelancing and Outsourcing Tips, Commentary, Analysis, and News from oDesk()

  • Pingback: Installing WordPress in Ubuntu « Curly Braces()

  • pragati

    Tried the following steps to install apache and PHP
    Install Apache

    sudo apt-get install apache2Testing HTTP Server by open a web browser and enter http://localhost

    Install PHP5

    sudo apt-get install php5 libapache2-mod-php5


    but it says no package found

    please help.
    where i can get apache mysql and php for my ubuntu

    • Samrat

      Hello, this command searches online for packages.So check whether U are connected to internet.

  • so how to create a http site after putting up dis lamp?? (plzz email me how)
    im getting an error ;;;

    connect to server at ‘localhost’ failed
    error: ‘Access denied for user ‘root’@’localhost’ (using password: YES)’

    when changing password!!

  • Bridgette

    Brilliant Guide Ubuntu kk 9.10

  • Pingback: Conkr | Blog | links for 2007-02-12()

  • Oneqman

    Thanks for the manual. Very informative

    One typo I noticed… should be