Install LAMP on Ubuntu 9.10 Karmic Koala

October 29, 2009 by Linerd
Filed under: HowTo, Ubuntu, linux, web development 

Why install LAMP on your desktop computer?

Why would I want to install and set up a LAMP (Linux, Apache, MySQL, php) stack on Ubuntu 9.10? It’s useful if you want to set up a private web development environment. Perhaps you want to develop your own WordPress theme. If you are developing websites and experimenting, it’s nice to do it in the privacy of your own computer, rather than out on the public internet.

Install LAMP

The Ubuntu developers have created a very easy way to install a LAMP server on an existing system. It's all kicked off with this one simple terminal command.

sudo apt-get install lamp-server^

Note: Please make note of the caret (^) in the above command, it's not a typo, it's required to make the command work.

Install LAMP with apt-get

Install LAMP with apt-get

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

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

Setting root password for MySQL

Setting root password for MySQL

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.

Lamp installation is complete

Lamp installation is complete

Congratulations, your LAMP installation is complete! That was the easy part, now you need to get things configured to make the 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!"

Apache works!

Apache works!

Testing php

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

gksudo gedit /var/www/testing.php

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

<?php phpinfo(); ?>
Creating testing.php

Creating testing.php

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.

Testing php - it works!

Testing php - it works!

Configuring MySQL

Since I'm installing LAMP for a web development environment, I want to bind the MySQL database 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 the my.cnf file.

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

You should see a line that looks like

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 muck around with things in your MySQL database if you're not familiar with the MySQL 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. Use the space bar on your keyboard to select apache2 and then hit <Enter>.

Configure phpMyAdmin for Apache2

Configure phpMyAdmin for Apache2

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

Configure dbconfig-common

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

Enter MySQL root password

Enter 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. If you enter your own password, a password confirmation screen will come up. Confirm your password.

MySQL application password confirmation

MySQL application password confirmation

The phpMyAdmin installation is now complete.

Testing phpMyAdmin

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

Testing phpMyAdmin

Testing phpMyAdmin

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

phpMyAdmin home screen

phpMyAdmin home screen

Congratulations, you're now ready to start building your local website. If you're only working on one site you can put all of the 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

74 Responses to “Install LAMP on Ubuntu 9.10 Karmic Koala”

  1. Fahrisal says:

    Another Question:
    How do I copy paste wordpress files or Joomla files to folder www like I was used to do in windows?.
    I'm unable to paste the files by using "copy paste click".

  2. Ryan says:

    Super clear guide, set up with no problems.

  3. Kirsten says:

    Hi! I've been looking at several guides for installing wordpress in ubuntu and yours is really the most in-depth that I've come across, but I'm having some significant problems in configuring phpmyadmin. Yes, I did check the apache2 box with my spacebar, I promise.
    I get
    error 1045 (28000): Access denied for user 'root@localhost'
    at the completion of the reconfigure. I'm wondering if the error could have it's roots in mysql name/password or if I've done something especially silly.

    Also, I have tried this:
    Edit /etc/apache2/apache2.conf and add the following lines to the end of the file
    #for phpmyadmin
    Include /etc/phpmyadmin/apache.conf
    and when I do the apache2 restart fails, if this additional info is helpful at all. Any comments at all would be appreciated.

    • Linerd says:

      @Kirsten - If the phpmyadmin configuration is successful, then the lines you've added to /etc/apache2/apache2.conf are not required and may cause a conflict, so go ahead and undo that change. That may take care of the problem with Apache starting.

      I sounds like something may have gone wrong with the phpmyadmin installation. I would try removing it and reinstalling it along with the Apache mod-auth module. Remove it with

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

      and reinstall it with

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

      It should take you through the phpmyadmin configuration again.

      If your hunch is correct about your MySQL root password, you can reset it by running

      sudo dpkg-reconfigure mysql-server-5.1

      Good Luck!

      • Kirsten says:

        I was finally able to get through the phpmyadmin install without errors, by following the reinstall steps above. Thank-you. Unfortunately I still don't get anything at http://localhost/phpmyadmin/ not even a 404. Alas. Still, I appreciate your help.

        • Linerd says:

          So you're able to access the other http://localhost/ sites?

          Leslie's comments below indicate you're not alone. You might want to try completely removing LAMP and try again from the beginning.

          Before you do that, you may want to check your /etc/apache2/apache2.conf file and make sure you didn't remove too much. the end of my file looks like this:

          # Include of directories ignores editors' and dpkg's backup files,
          # see README.Debian for details.
          
          # Include generic snippets of statements
          Include /etc/apache2/conf.d/
          
          # Include the virtual host configurations:
          Include /etc/apache2/sites-enabled/

          Also, my listing of /etc/apache2/conf.d/ is this:

          -rw-r--r-- 1 root root  269 2009-04-01 12:01 charset
          -rw-r--r-- 1 root root   21 2009-11-14 11:04 fqdn
          lrwxrwxrwx 1 root root   28 2009-06-13 11:20 phpmyadmin.conf -> ../../phpmyadmin/apache.conf
          -rw-r--r-- 1 root root 1464 2009-04-01 12:01 security

          This page might be of some help: https://help.ubuntu.com/community/ApacheMySQLPHP

          • Kirsten says:

            Thank-you Linerd, uninstalling and starting from scratch did it. You're instructions are incredibly helpful!

  4. Greg says:

    I, too, am on the lookout for CLI removal of LAMP in Ubuntu 9.10. Any thoughts or suggestions?

    (Thanks, btw, for the guide/tutorial!!)

    • Linerd says:

      @Greg- You should be able to do i with something like

      sudo apt-get purge apache2 mysql phpmyadmin

      I'm not sure of the actual package names, I'm away from my Linux box right now. I'll take a look at it and post an update. After removing the main packages, you can then clean up the rest with

      sudo apt-get autoremove

      You can also use aptitude instead of apt-get for the first command and the autoremove will be done automatically.

    • Linerd says:

      Greg - I figured it out. Take a look at: How To Remove LAMP in Ubuntu.

  5. Live says:

    OK, now that I've installed it. How do I uninstall or remove this lamp-server? It seems everyone is talking about installing it, but I'm not comfortable if I don't know what it installed in my system, I think there are 10-20 packages, how do I remove all of them? Is there a command, a GUI, how do you do it?

  6. Leslie says:

    That is a great tut - so clear and easy to follow. With my system, everything worked except the last step. http://localhost/phpmyadmin/ which gives 404 Not Found. What did I do wrong?

    • Linerd says:

      Leslie - Did you remember to select "apache2" during the phpMyAdmin configuration like in the picture? Use the Tab key to go to that field and use the Space bar to select it. You can re-run the phpMyAdmin configuration with:

      sudo dpkg-reconfigure phpmyadmin
      • Leslie says:

        Thanks for answering :) Yes, I did do that. I even tried the purge and (re)install (to Kirsten above) in case I had missed something. I still get the same result.

        Should I email you? This could go on awhile - I've talked to a couple of others on this already and we are getting nowhere! I really hope you can help :S

        • Linerd says:

          Honestly, I have no idea what you might have done wrong. The process has gone smoothly for me every time I've run it. If you want to start over with the install, I just wrote a post on how to uninstall LAMP in Ubuntu. This will purge all of the web server information from your system so you can start fresh.

          Good luck.

        • Linerd says:

          Leslie - Take a look at my recent reply to Kirsten. It may provide some help.

          • Leslie says:

            Thanks. I got it working, and meant to put my reply here, but instead I have put it as a new comment! Sorry about that. My listing of /etc/apache2/conf.d/ is quite different to yours.

  7. [...] under: HowTo, Ubuntu, linux, web development  The most popular post on this blog is How to Install LAMP on Ubuntu 9.10. On that post, I've had a few comments asking how to remove the single command LAMP installation. [...]

  8. alain says:

    I started like you mentioned but is one problem

    * Starting web server apache2 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs
    [fail]
    invoke-rc.d: initscript apache2, action "start" failed.

    can you help me

  9. Leslie says:

    Hey, I got it to work. I used
    sudo gedit /etc/apache2/apache2.conf

    to insert the below code into apache2.conf - at bottom of page.
    Include /etc/phpmyadmin/apache.conf

    Tut source: http://tolearnfree.blogspot.com/2009/11/how-to-install-apache2-php5-mysql-and.html
    then I used your restart apache command, Linerd
    sudo /etc/init.d/apache2 restart

    Thanks for a superb tut here and thanks also to Mike Kenzie, collector of vintage computers
    http://www.ncf.ca/~ba600
    You are real life savers :D Are you in Twitter Linerd?

  10. Ray says:

    Can someone confirm that this guide works with the non-server version of Ubuntu 9.10?

    • Linerd says:

      This indeed is a guide for installing LAMP on Ubuntu Desktop. It should work on a server install as well, but I haven't tried it.

  11. novice says:

    This was the best 'how to' that i've come across in a long time.

    Thank you.

Leave a Reply