Installing LAMP on Ubuntu 10.04 and 10.10 (Lucid Lynx, Maverick Meerkat)

April 29, 2010 by
Filed under: HowTo, linux, Ubuntu, web development 

If you're developing websites, it's nice to be able to test your code in the privacy of your own computer rather that out in the public internet. In order to do that, you'll need to install a webserver on your development computer. LAMP (Linux, Apache, MySQL, php) is one of the most common web hosting platforms, so it's a perfect environment for you to build and test your website code. If you carefully follow these step by step instructions, you'll have your own LAMP setup running in no time. 

Install LAMP on Ubuntu

The Ubuntu developers have made it easy to install the LAMP server packages with a single command. Simply open a terminal window and enter the following.

sudo apt-get install lamp-server^

No, that's not a typo. Please make sure to include the caret (^). The command will not work without it.

sudo apt-get install lamp-server^

sudo apt-get install lamp-server^

The apt package manager will show all the packages that need to be installed. Hit <Enter> to confirm that you want to install them.

LAMP packages

LAMP packages

You will then be prompted to change the password for the root user on the MySQL database.

Set MySQL root password

Set MySQL root password

Enter the password you want. You'll be prompted to enter it a second time to confirm.

After you confirm your password, apt will continue to install the rest of the packages.

Congratulations, your LAMP installation is now complete! That was the easy part, now you need to get a few things configured to make your system easy to work with.

Test Apache

Open a web browser and enter the address http://localhost/. You should see a web page that says "It Works!"

Testing Apache

Testing Apache

Test php

Now that you know Apache works, you'll want to test the php installation. You'll need to create a file in /var/www called testing.php. Open a terminal and enter:

sudo nano /var/www/testing.php

Enter the following line into the text editor, save the file and exit.

<?php phpinfo(); ?>

Next, restart Apache with the following terminal command:

sudo /etc/init.d/apache2 restart

Now go back to your web browser and enter the address http://localhost/testing.php/. You should see a page displaying version information for your php installation.

php Information

php Information

Configure MySQL

Since I'm installing LAMP for a web development environment, I want the MySQL database to be bound to the localhost IP address. This should be 127.0.0.1 for your system. You can verify it with this terminal command.

cat /etc/hosts | grep localhost

You'll now want to verify that the correct bind address is set up in MySQL's my.cnf file.

cat /etc/mysql/my.cnf | grep bind-address

You should see a line that looks like this:

bind-address		= 127.0.0.1

If the IP address doesn't match the one for your system, you'll need to edit the my.cnf file to correct it.

Install phpMyAdmin

You don't need to install phpMyAdmin, but it's a much easier way to get in and adjust things in your MySQL database if you're not familiar with MySQL's commands. You can install phpMyAdmin from the command line with:

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

The installation will prompt you to select a web server for automatic configuration.

phpMyAdmin Setup

phpMyAdmin Setup

This is important! Use the space bar on your keyboard to select apache2. Make sure there's a * next to apache2 like the picture below and then hit <Enter>.  (Click the picture to enlarge it and see what I'm talking about.)

phpMyAdmin Setup: select apache2

phpMyAdmin Setup: select apache2

The next screen will explain some information about database configuration. Hit the <Enter> key to move on.

phpMyAdmin database config

phpMyAdmin database config

Another screen will come up asking if you want to configure a new database called dbconfig-common.  Since this is a fresh installation, use the <Tab> key to select Yes and hit <Enter>.

phpMyAdmin dbconfig-common

phpMyAdmin dbconfig-common

You'll be prompted next to enter the MySQL root password. Enter the MySQL root password that you created earlier, hit <Tab> to select Ok and hit <Enter>.

MySQL root password

MySQL root password

You'll then be prompted to enter a MySQL application password for phpmyadmin. You can hit <Enter> and a random password will be generated. I chose to use the same password that I used for the root MySQL password.

MySQL application password

MySQL application password

If you enter your own password, a password confirmation screen will come up. Confirm your password.

MySQL application password confirmation

MySQL application password confirmation

Your phpMyAdmin installation and configuration is now complete.

Testing phpMyAdmin

Open your web browser and enter the address http://localhost/phpmyadmin/. You should see a page like this.

phpMyAdmin log in

phpMyAdmin log in

You can log in with the username root and the root password that you created earlier.

Logged into phpMyAdmin

Logged into phpMyAdmin

Congratulations, you're now ready to start building your local website. If you're only working on one site you can put all of your files into /var/www.  If you'll be working on multiple sites you may want to consider some additional Apache configuration to keep things neat and clean on you system.

Comments

446 Responses to “Installing LAMP on Ubuntu 10.04 and 10.10 (Lucid Lynx, Maverick Meerkat)”

  1. maali says:

    Hi,

    While installing i am getting below error on ubuntu 10.04:
    The following packages have unmet dependencies:
    mysql-client-5.1: Conflicts: mysql-client-5.0 but 5.0.51a-3ubuntu5 is to be installed
    mysql-client-core-5.1: Conflicts: mysql-client-5.0 but 5.0.51a-3ubuntu5 is to be installed
    mysql-server-5.1: Conflicts: mysql-server-5.0 but 5.0.51a-3ubuntu5 is to be installed
    mysql-server-core-5.1: Conflicts: mysql-server-5.0 but 5.0.51a-3ubuntu5 is to be installed
    E: Broken packages

  2. ccbogel says:

    The installation worked smoothly as exactly as shown. I installed on Ubuntu 11.10 Oneric

  3. shailendra says:

    when i was installing LAMP server on Ubuntu 10.04 server i got following error
    root@HM01AP01:~# apt-get install lamp-server^
    E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
    E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

    please solve this issue...!

    • Linerd says:

      I've seen this error when there's another package manager running. Was Synaptic or the Update Manager running at the time of the error?

    • pemborsky says:

      You must install as root, like so:

      sudo apt-get install lamp-server^

      ...at which point you'll be prompted to enter your administrator password. Enter it, then press the return key. Should work fine.

  4. jephath says:

    Installation worked smoothly, thanks.

  5. Prasanth says:

    Installation worked very Smoothly Thanks...

  6. Great tutorial.. works all through..

  7. Takis says:

    Very good guide. No problem during installation. Thanks a lot!

  8. Zen420 says:

    Hi, I was trying your installation method and ran into the following...


    ~# sudo apt-get install lamp-server^
    sudo: unable to resolve host Zen420
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    libapr1 is already the newest version.
    php5-common is already the newest version.
    libapr1 is already the newest version.
    php5-common is already the newest version.
    The following extra packages will be installed:
    apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common
    libapache2-mod-php5 libaprutil1-dbd-sqlite3 libaprutil1-ldap
    libmysqlclient16 mysql-common php5-mysql
    Suggested packages:
    apache2-doc apache2-suexec apache2-suexec-custom php-pear
    The following NEW packages will be installed:
    apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common
    libapache2-mod-php5 libaprutil1-dbd-sqlite3 libaprutil1-ldap
    libmysqlclient16 mysql-common php5-mysql
    0 upgraded, 11 newly installed, 0 to remove and 5 not upgraded.
    Need to get 0B/8,071kB of archives.
    After this operation, 22.0MB of additional disk space will be used.
    Do you want to continue [Y/n]?

    I never had any prompts about setting up mySQL password... Didnt try past that because if this fails, I cannot move forward with the project that im working on. I am running Backtrack 5 which i believe is based off Ubuntu. Is this the reason why I am failing the install. I am updated as of 2 mins ago.. Any help would be greatly appreciated...

    Thanks,
    Zen420

  9. Zen420 says:

    *Solved.. I just re-installed MySQL...

  10. Jim81 says:

    I cannot get http://localhost/phpmyadmin/ to work it says not found. I am not sure what I am doing wrong I have tried this 3 times. everything else seems to work.

  11. shimba says:

    Thanx a million Linerd its real a timeserver, it has worked for me more than once.

  12. That works like a pro. :)

    Thanks.

    I keep this page for my personal reference on http://www.webnapps.co.uk/helpful-links
    I hope this will be OK with you.

    Cheers.

  13. Gary Rubin says:

    I have run into an issue during the installation of phpmyadmin.
    An error occurred while installing the database:

    mysql said: ERROR 13 (HY000) at line 1: Can't get stat of './phpmyadmin'
    (Errcode: 13)

    I researched it and found some information that it has something to do with AppArmor, but the ill-advised (security reasons) fix didn't work for me.

  14. Avinash says:

    how much time will it take to load?? because im aint getting the local host process the last line i see in ubuntu 10.04 is
    ""ldconfid deffered processing now taking place
    avi@ubuntu:~$""
    can u help me out plss bro its a project

  15. Avinash says:

    now it says
    "apache2:Could not reliably determine the server's fully qualified domain name"

  16. Avinash says:

    in the last step of urs
    what username should i use???
    my ubuntu name was avinash and password was same for all i mean for mysql as well as
    for the ubuntu start now it says "" #1045 cannot log into mysql server"" please help

  17. Laurence says:

    Hi,

    Thanks very much for the walk through. Worked like a dream except for one step:

    When testing PHP, I can't save the file testing.php to the www folder. When I try and save I get the error message: "You do not have the permission necessary to save the file"

    And when I enter sudo nano /var/www/testing.php into the terminal, I get the message: "command not found".

    please help

  18. Laurence says:

    and evidently I also need to get the hang of html tags...

  19. Danny says:

    i have installed LAMP server successfully and every single stage of the process
    going well but when it comes to matter of testing , it keeps telling the following categorically message

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>