Ubuntu Lamp

If you are doing any type of development on a Linux box you are probably going to need the LAMP suite. That is, Linux, Apache, Mysql, and PHP. This is by far the most common collection of apps used to serve web content. It is often used to serve open source projects like Wordpress and many others. The other benefit is that it is free!

In this guide I am going to assume you already have Ubuntu 8.10 (intrepid) installed. If not you can head over to Ubuntu.com and grab it.

Installation

Apache

The first app we will install is the web server Apache. To get started open your console and type:

sudo apt-get install apache2

After you put in your password and accept and a short wait you should have a working installation of Apache. To test it point your web browser to http://localhost

Apache default screen

PHP

sudo apt-get install php5 libapache2-mod-php5

Once this finishes we need to restart Apache. This will apply the changes.

sudo /etc/init.d/apache2 restart

Now lets test it by replacing ‘/var/www/index.html‘ with index.php adding the following line:

Vim phpinfo

MySQL

Install all the MySQL stuff:

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

When you get a prompt enter a password you would like to use as the root MySQL user.

Once done open, ‘/etc/mysql/my.cnf‘ and change the bind-address to your local IP. (usually 192.x number).

mysql bind-address

Extra Stuff

phpmyadmin

sudo apt-get install phpmyadmin

After phpmyadmin is installed you can see it view it, http://localhost/phpmyadmin/.

mod_rewrite

Chances are you want to use mod_rewrite in your applications to make URLs a bit more pretty. It is also required by lots of software, like Wordpress.

sudo a2enmod rewrite
/etc/init.d/apache restart

Starting and Stopping Apache

Run, Stop, Test, And Restart Apache

Use the following command to run Apache :

sudo /usr/sbin/apache2ctl start

To stop it, use :

sudo /usr/sbin/apache2ctl stop

To test configuration changes, use :

sudo /usr/sbin/apache2ctl configtest

Finally, to restart it, run :

sudo /usr/sbin/apache2ctl restart

Subscribe via Email

Subscribe to Nixtutor via Email

Enter your email address:

Was this information useful?

31 Responses

  1. Adam

    2-11-2009

    More simply, the LAMP stack can be installed using this one-liner:

    sudo apt-get install lamp-server^

    The carrot is NOT a typo; it needs to be there. More information here: https://help.ubuntu.com/community/Tasksel

  2. Mark Sanborn

    2-11-2009

    Awesome tip, didn’t know about the debian/ubuntu tasksel program. Thanks adam!

  3. Roon

    2-12-2009

    Cool guide thanks, I be diggin

  4. Shawn

    2-15-2009

    Just wondering if you had any tips for someone trying to follow this guide instead of a prior xampp installation.

    I have followed up until the point of installing apache2 and when I test localhost, my url gets defaulted to localhost/xampp.

    Now I’m not sure what to do at this point b/c all prior documentation tells me that to remove xampp I just run rm -rf /opt/lampp where that is the folder I installed xampp in.

    any advice?

  5. [...] This will get you up and running fast: Installing Apache Mysql and PHP on Ubuntu 8.10 [...]

  6. Vijay Patil

    3-7-2009

    Nice step by step instruction. For those who wants to install the stuff individually. Keep up the good work.

  7. Fredrick onyango

    3-13-2009

    This tutorial is fantastic.Though I’m new to Linux It made everything look cheaper than I thought.Thanks a lot

  8. itsmemad

    3-23-2009

    I’m basically a Windows user… But installing Apache, PhP, Mysql on Windows is a pain in the ass… So thought to install ubuntu and this guide is so cool… It made the installation in a ziffy… Thanks.. Digged!

  9. Felix

    3-26-2009

    just followed the procedures:

    after installing myphpadmin and testing http://localhost/myphpadmin/ i get 404 not found error

    any ideas why?

  10. Mark Sanborn

    3-26-2009

    Because you didnt follow the procedure carefully enough :D You type phpmyadmin, not myphpadmin.

  11. Etomak

    4-9-2009

    Nice guide but having problem saving index.php on /var/www

    Thanks.

  12. Etomak

    4-9-2009

    this is the error.

    “You do not have the permissions necessary to save the file. Please check that you typed the location correctly and try again”

    any idea?

  13. Mark Sanborn

    4-10-2009

    Use sudo or root to modify the file for this test purpose.

  14. Etomak

    4-10-2009

    Thank you, everything work right…

  15. Etomak

    4-10-2009

    pardon for may innocence.

    I encounter this error

    Fatal error: Call to undefined function mysql_connect() in /var/www/myapp/con.php on line 4

    here is the function that causes the error

    function connect(){
    $link = mysql_connect(“localhost”, “usr”, “pass”)
    or die(“Could not connect to the Database Server!”);
    $db = mysql_select_db(“mydb”, $link) or die(“Could not select Database!”);

    }

    thanks in advance

    BTW I can’t edit ‘/etc/mysql/my.cnf‘ again I do not have the right to made changes on the file.

    I would like to change the permission but did not know if it is right. :-)

  16. Jade Robbins

    4-10-2009

    That means you don’t have mysql support in your php install.

    sudo apt-get install php5-mysql

    Should take care of that.

    Just sudo gedit and open the file to edit your mysql conf!

  17. Etomak

    4-11-2009

    thanks for the reply, I did what you told me but still throwing same error.

  18. Mark Sanborn

    4-11-2009

    Jade is correct, you need to install php5-mysql as per his instructions and also in the article.

    You also need to remember to restart the apache service when you are done for the changes to take effect.

  19. Etomak

    4-12-2009

    It works after restarting the apache.. :-)

    thanks guys….

  20. Calle

    4-14-2009

    Excellent guide – Clean and simple!
    Just a comment about the last step when restarting Apache (again). If you follow the guide from the start, you should restart Apache using “sudo /etc/init.d/apache2 restart”, not “/etc/init.d/apache restart” as the guide says in the step for mod_rewrite.

    Anyways, awesome step-by-step guide that makes life easier for everyone! :)

  21. nop2

    4-15-2009

    thanks a lot..

  22. Kingsley

    4-20-2009

    Hi Thanks for your article. Now how do i install Oracle and connect to it on Ubuntu?

  23. h2o

    4-25-2009

    Thanks!

  24. Myfacefriends

    5-8-2009

    this is awesome! thanks

  25. senthil

    7-8-2009

    thanks for ur guide i have problem like i could not save the file in www directory .how can solve pls reply me

  26. senthil

    7-8-2009

    The requested URL /phpmyadmin/ was not found on this server.

    this the message i got while openning the phpmyadmin

  27. senthil

    7-14-2009

    hai i can access a file linux apache www root folder
    it shows i not have access permission bit try command like sudo instead it show user is not on sudouser file pls help me ….

  28. Yang

    9-7-2009

    I’m testing each of them one by one on my SSH terminal. But that’s really quite a lot to digest. Seems it’d take a long time before I read through every article of this blog.

  29. norhuda

    9-16-2009

    thank you very much. it help me alot especially installation on lamp. nice work and keep this guidance forever for those who needed. i will always support open source.

  30. adr

    1-24-2010

    I’ve been trying to get this to work but get as far as installing phpmyadmin but when I go to check I get the 404 Not Found error message.

    I’ve spent two days trying to find out what’s gone wrong. Any ideas where I should be looking?

  31. David

    2-14-2010

    I am new linux and this was very helpful. Thank you so much.