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

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

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 web server 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 Ubuntu LAMP web server on installed, configured, and running in no time. 

Install LAMP Web Server on Ubuntu

The Ubuntu developers have made it easy to install and configure 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^

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

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

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.

Sponsors

Comments

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

  1. Benny LW says:

    Excellent, easy and accurate - good job m8!

  2. Dimitri says:

    Wow, fastest LAMP installation in history. Thanks.

  3. Charlie C says:

    Excellent. This is it! Thank you.

  4. Esi says:

    Excellent Tank You And Kissssss

  5. robert says:

    great tut but i got a problem. i did as it is here, now it says that i got latest version of phpmyadmin, but when i navigate to localhost/phpmyadmin in my browser, i see as follows
    Not Found

    The requested URL /phpmyadmin/ was not found on this server.
    Apache/2.2.16 (Ubuntu) Server at localhost Port 80
    Can you please tell me why is that? help me please

  6. robert says:

    Thank you Linerd for your reply. I selected apache2 during the installation, but i did the instructions sudo dpkg-reconfigure phpmyadmin and reloaded apache with sudo /etc/init.d/apache2 reload and still the same. Everything is installed, but does not work. I am kinda new to ubuntu, maybe it is a wrong directory or something? Thanks again

  7. Patrick says:

    Thanks a lot. Great job. Works perfectly.

  8. Druidtton says:

    A nice trough tutorial.

    Very well explained, and fitting to most flavours of linux.

    I learnt, while at the same time was able to quickly finish the installation process.
    I'm bookmarking this site.

  9. Angelo Russo says:

    Thank you, it worked flawlessy even on LUBUNTU

  10. xirian says:

    Thank you very much
    Can confirm that works even with Lubuntu 11.04

  11. Short and to the point. The simplest LAMP installation i've found so far. It works great for a development box. Thank!

  12. Guillermo says:

    Good! I followed all steps, however i had issues with testing.php file. When i navigate to http://localhost/testing.php the file just downloads. So, PhP is not really interpreting the file?

  13. Guillermo says:

    After cleaning the browser's cache it worked ;)

  14. Al says:

    Worked perfectly for me. Thanks very much.

  15. Zack says:

    Worked great, thanks for the help

  16. mickey says:

    I can feel the true spirit of open source in you. good job!

  17. suman kumar says:

    Worked great, Thanks a lot

  18. karim says:

    Is there any way to install it to usb drive

  19. Robert says:

    I followed this cookbook but the "test php" step failed. Namely, when I browsed to localhost/testing.php I got a blank screen. I found that the permissions on testing.php were 600. When I changed them to 644 it worked. Now I'm not sure if they are supposed to be 644 or if it's supposed to work with 600 permissions and something is wrong with my installation.

    • Linerd says:

      On my system, the test.php file already was set to 644 permissions. When I changed the permissions to 600, I also got a blank screen. I believe that permissions of 644 are correct.

  20. Shimba says:

    Thanks a million worked great

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>