Setting up LAMP on your Ubuntu desktop

lampMany of you must be wanting to try some web development and would like to setup their own LAMP(Linux, Apache, MySQL, PHP/Perl/Python) stack. Ubuntu has a special Server Edition for setting up your own LAMP server, most of you may want to install it on your desktop (I like it that way).

This involves installing Apache, PHP, Python and MySQL. I think Python will be installed by default and we only need to install mod_python for Apache. I use Ubuntu Edgy Eft 6.10.

Apache 2

Apache is the most popular web server and I use it for my development work. Apache 2 can be installed by running this command in the terminal.

sudo apt-get install apache2

All your files should be placed in the /var/www/ folder to be viewed from your server.


PHP is on version 5 and can be installed by running

sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart

You can easily test whether you have correctly installed PHP by writing a simple test file.

gksudo gedit /var/www/testphp.php

This will open a text editor and here insert this line. There should be no space between < and ?. WordPress inserts a space in between.
< ?php phpinfo(); ?>
Point your browser to http://localhost/testphp.php

MySQL Server

Next install MySQL server

sudo apt-get install mysql-server

MySQL by default allows connections only from i.e., only from your own computer. This is ok if you are developing only on your own system. If you want to access your MySQL server from a network,

gksudo gedit /etc/mysql/my.cnf

Find the line bind-address = and comment it. Comments start with ;(semicolon).

If you want to set a different password to your MySQL server (than the default none),

mysqladmin -u root password your-new-password
mysqladmin -h root@local-machine-name -u root -p password your-new-password
sudo /etc/init.d/mysql restart

Install MySQL for Apache

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

After this, you have to enable the MySQL extension in your php.ini. Edit the file

gksudo gedit /etc/php5/apache2/php.ini

Here uncomment the line “;

After this restart Apache 2

sudo /etc/init.d/apache2 restart


Python for Apache can be installed by installing the libapache2-mod-python package.

sudo aptitude install python
sudo aptitude install libapache2-mod-python

25 thoughts on “Setting up LAMP on your Ubuntu desktop”

  1. In the line under mysql, mysql comments begin with a ‘#’

    In the ‘Install MySQL for Apache’ section, you need a break before the second sudo

  2. Followed your guide using Ubuntu 7.10. Worked like a charm. Nice guide; well-written and easy to follow. Unpacked tikiwiki into the www directory and was able to config and use it no problems.

  3. HI!

    I’m not new to development (asp or php) but new to Linux. This is the guide I’ve been looking for to simply use Ubuntu Desktop as a LAMP.

    Thanks mate, I’ve blogged a link to this post – i’ll be referring back to this quite a lot 🙂

  4. Hi,
    Thanks for this explanation. New as I am, however,to Linux (Ubuntu), I am used to WAMP on Windows. That is a matter of installation and you are up and running. Now that I have done the above, how do I get to php myadmin to administer my databases or get webpages in a folder I have no access to, though I have administrative rights. In other words, I havent a clue how to move on and find it highly frustrating. Is everything on Linux this complicated, because then I will move back to Windows?

  5. Jeez Erik don’t give up so easily. I just googled ‘install phpmyadmin’ and found several easy step by step guides – try this one

    I guess no-one’s made anything like WAMP for linux coz there doesn’t sem like there’s much more to it than typing: sudo apt-get install php5 mysql-server apache2 phpmyadmin – and then tweaking a few config files. It’s publicly accessible servers where you need to get all hardcore about.

    You should be able to get to PHPmyadmin by browsing to http://localhost/phpmyadmin just like you do on Windows. If you dont get that you either haven’t installed or configured it correctly

    Likewise for web pages to be served up as such you have to put them in your htdocs folder, just like you do with Wamp in Windows. If you don’t know where that is search for your apache config file ‘httpd.conf’ and look in there. If you go to http://localhost you should get a listing of your htdocs folder rather than a ‘Failed To Connect’ Error.

    Anyway I’m just about to try this myself and as I suspect you’re not the only one who’s stumped as to the next step I’ll make some notes as I do and write a detailed lead-you-by-the-hand guide on my blog soon at:

    Keep your chin up and don’t look back, it’ll start to seem easier soon 🙂


  6. After installing the phpmyadmin, you didnt mention how to configure it, in order to run it from browser. I figured it somehow, but thought it might help others…

    after: sudo apt-get install phpmyadmin
    do this: gksudo gedit /etc/apache2/apache2.conf
    and add this line: Include /etc/phpmyadmin/apache.conf
    then save the file.
    now do the other steps as mentioned in this article.

    After doing all this, phpmyadmin should be accessible via browser. i.e
    http://your-domain/phpmyadmin (your-domain = localhost)


  7. I have followed all of the instructions on this page and can even view the http://localhost/phpmyadmin login page. But how do I view other php files? I still get the open/save dialog box. Or do I have to login? Because I have no idea what my username is. I didn’t get a choice of what to use. I know the password as it asked, but even using my login username does not work.

    Any help would be great.


  8. Thanxs a lot!! Now i have my own web development enviorement for testing and production!!!

  9. Hello everyone,
    I am new to Ubuntu / Linux and just installed the Ubuntu 11.10 Desktop. I am going to install PHP, MySql, Apache and, actually going to learn these three platforms from scratch. Question is, can I install these packages in Desktop environment OR do I need to install Ubuntu Server? Second question, can I run my PHP 4x scripts after I install PHP in Ubuntu?

    Thanks a lot.

  10. Wow! Thank you so much, I wish that with this I can do my scripts without hosting every time for trying them on the Internet.

Comments are closed.