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.

PHP5

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 127.0.0.1 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 = 127.0.0.1 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 [email protected]-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 “;extension=mysql.so

extension=mysql.so

After this restart Apache 2

sudo /etc/init.d/apache2 restart

Python

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

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

  • Simei

    Very Cool! I hope that this never broke.
    🙂
    Thanks man.

  • You have a space between “

  • Ok, I see, it is some problem to public that code
    <?php
    phpinfo();
    ?>
    So, problem in space between < and ?

  • Brian

    The correct path on my install for the php.ini file is…

    /etc/php5/apache2/php.ini

  • Oops. The errors are corrected. Thanks for pointing out.

  • wh0rd

    You forgot to correct the PHP syntax error in testphp.php

  • Paul

    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

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

  • Jamie

    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 🙂

  • Pingback: Patrick Cosyns Blog » Blog Archive » Setting Up a Lamp Server on a Ubuntu Desktop()

  • Pingback: Django in Ubuntu « Code Ghar()

  • Sandeep

    Excellent and helpful information .

    Thank you

    Regards

    Sandeep

  • thanx mann im new to ubuntu and linux all together and i dont think im ready for a server release but wanted a linux invirament for testing my websites.

  • Erik

    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?

  • Roger Heathcote

    Jeez Erik don’t give up so easily. I just googled ‘install phpmyadmin’ and found several easy step by step guides – try this one http://www.howtoforge.com/ubuntu_debian_lamp_server

    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: http://movingtoubuntu.technicalbloke.com

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

    Roger.

  • Ram

    Excellent instructions – some of the best I have seen. Short, crisp, clear, and it works.

  • Yamin

    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)

    Thanks
    Yamin

  • Daniel

    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.

    Thanks.

  • victor villalobos

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

  • @Daniel
    sudo /etc/init.d/apache2 restart
    You need to restart the apache server to render php, I just ran into the same thing myself.

  • hrdotnet

    correct nice work guys

  • iss correct and nice share guys.. thanks for review

  • Salman Majid

    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.

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