Installing LAMP on Ubuntu 10.04 (Lucid Lynx)

April 29, 2010 by Linerd
Filed under: HowTo, Ubuntu, linux, 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 and then hit <Enter>.

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

128 Responses to “Installing LAMP on Ubuntu 10.04 (Lucid Lynx)”

  1. cniv says:

    Very well written and explained.
    I still remember 2 years back when I did LAMP setup on Hardy, it took me about 30 minutes to install, configure and figure out what was going wrong.

    Now it is really easy to install LAMP on Ubuntu 10.04, very well job done for new flavour of Ubuntu.

  2. SIMON says:

    A Great Job,,,Thanks very much.

    It help me a lot, after trying for several days to make LAMP server work, found your Article. Now finally going to install again DRUPAL, will let you know my website when is up.

  3. fasil says:

    Hi there, I have followed all the steps and installed everything but http://localhost/phpmyadmin/ is not working.
    please tell me the solution for this.
    thank you

  4. Mads says:

    Yea... I couldn't get phpmyadmin to work too.
    Then I realized that it wasn't 'selected', it's just red because the 'cursor' is on it.
    To select it, press spacebar.

    I know, it's really simple and already specified in the instructions, but I'm used to modern GUIs and didn't spare it a thought!

    Good instructions.
    /Mads

  5. ShowMeGrrl says:

    This was great! The LAMP installation package set up by Ubuntu is just wonderful and your instructions were very clearly presented. This was SO easy and fast, it's unbelievable!

    I had one problem: After typing the line:
    sudo nano /var/www/testing.php

    and getting a nano text editing screen and typing in the phrase:

    I then tried to save the file using my mouse to click on the "Save Contents" command on the "File" menu. Up came the usual GUI dialogue box asking me to type in the file name and browse to the proper folder where I wanted to save the file to. When I did this, I got a message saying that the file could not be saved because permission was denied.

    I went online to nano text editor documentation to try to find a keyboard command for saving the file and found that the command to save a file without exiting is ^O (Ctrl-O). For some reason, I was allowed to save the file in this manner.

    Apparently, using the File menu command and browsing to the folder got me out of sudo mode to user mode and I was denied permission to save to the var/www folder. But using the keyboard command, I was still in sudo mode. That's the way it seemed to me, anyway.

    So the moral of the story is to use "Ctrl O" to save the testing.php file.

  6. Jambal says:

    This is a great post ! one stop shop. My setup was up in less than 5 minutes. In fact the process was faster than I put the passwords to work. Great Post , Guy rocks

  7. Matt says:

    At first I had the same problem as ShowMeGrrl and couldn't save using nano as I didn't know to save using "CTRL+O" in nano. So instead I simply used sudo gedit /var/www/testing.php and saved using "CTRL+S" which worked beautifully.

    Aside from that, everything went perfectly fine the first time around. Now if I could just figure out where the hell I can find this stuff installed on my system, that would be great. I was trying to enable the phpMyAdmin tracking but can't find the "./scripts/" directory or the "create_tables.sql" file in order to create the database for it.

    Being an extremely new Ubuntu user, I'm not familiar with how/where things get installed and how/where to find them later. With Windows, I usually specifically choose exactly where everything should be installed, so finding things later is very easy. Not so much in Ubuntu. I never know where things are going using the apt-get installation method.

    Don't get me wrong, I actually like the ease of installing stuff in Ubuntu, I just wish I knew where the hell I was installing stuff to.

    Anyway, can anyone point me in the right direction to find the "./scripts/" directory so I can test the tracking feature of phpMyAdmin?

    • Linerd says:

      You can try using the "Search for Files" program found under Applications→Accessories→Search for Files...
      or you can search from the command line with

      find / -depth -name scripts
  8. Anjali says:

    This is very easy and simplest way for installing LAMP SERVER.Thankq so much.

  9. Matt says:

    Thanks for that Linerd! That's exactly what I needed. I had tried to search through the file browser, but never could find the directory or script (even with the little search feature). Actually, I still haven't found it just yet, but using the command line seems much faster and a more convenient way of searching. Thanks again!

  10. ketan says:

    it was grate help, was up and running with my web server in less then 7 minutes
    thanks a lot and keep doing good work

    ketan

  11. chunn says:

    Great instruction! I am a new ubuntu user and just successfully installing LAMP and set up Joomla on my laptop.... but I cannot further install virtuemart component since I can't access the directory var/www/tmp ... I think it is about permission, but don't know much about it.

    I have read that if it is on a server, we have to change CHMOD...

    Please help me to install the component into var/www/tmp

    • Linerd says:

      You can copy files to the /var/www directory as root using sudo.

      sudo cp filename /var/www

      Or you can change the ownership of the www directory so you don't need to be root. Assuming your user ID is user1 and your main group membership is user1, the command would look like this:

      sudo chown -R user1:user1 /var/www

  12. eHope says:

    Thanks. Great! Super desciption

Leave a Reply