Install LAMP on Ubuntu Desktop

My development server is old. You’ll get a chuckle when you see the specs. It runs on a 400Mhz Pentium II CPU with a 128MB RAM and a 40GB drive. This old relic still manages to run Apache, MySQL, PHP and a local DNS. The server has also gone through 4 Ubuntu upgrades from version 7.04 to 9.04. After each upgrade, pages that require MySQL and PHP have slowed down considerably.

You guessed it. It’s about time to move to another machine. So, I’ve decided to install AMP minus the L (Linux) since we are already installing it on the Ubuntu Desktop. The following tutorial will show you how to install Apache, MySQL, PHP as well as the MySQL admin tool called PhpMyAdmin. Let’s get started:

Install Apache

sudo apt-get install apache2

Install PHP. Restart Apache

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

Install MySQL

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

Finally PhpMyAdmin
sudo apt-get install phpmyadmin

You’ll be asked to provide passwords on the MySQL and PhpMyAdmin installations. There are a couple of minor tweaks you have to do to make sure the applications are working properly. First, make sure the MySQL extension is set in PHP. Restart Apache again after you make your changes.

MySQL Extension. Restart Apache

sudo vi /etc/php5/apache2/php.ini
extension=mysql.so
sudo /etc/init.d/apache2 restart

Now, open your Firefox browser, and type `localhost` in the address bar. If you see “It Works!,” that means the installation was successful. One final thing before you go, I installed WordPress and the installation was a success, except for the mod_rewrite which wasn’t working if you try to use the permalinks feature. To make the permalinks feature work, first you’ll need to create a .htaccess file and make it writable. Next, turn on mod_rewrite module.

Mod Rewrite

cd /var/www/
touch .htaccess
chmod 777 .htaccess
sudo a2enmod rewrite

Lastly, make sure AllowOverride is set to All. Edit the file:

sudo vi /etc/apache2/sites-available/default

Allow Override

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

Restart Apache

sudo /etc/init.d/apache2 restart

22 thoughts on “Install LAMP on Ubuntu Desktop

  1. good post, thanks!

    [quote]
    extension=mysql.so
    [/quote]

    where does this have to be added? in what section? what for exactly?

    1. Simon, I had a chance to review the MySQL extensions. Sorry for not being clear on the instructions. You were supposed to uncomment extension=mysql.so located under Dynamic Extensions in php.ini. I found out there is NO need to uncomment extension=mysql.so since it works just fine. I updated the post above. Thanks.

  2. Well, why all install always apache, which isnt good for server ?? I think people should start usign nginx, lighttpd, cherookee. Apache is very slow and hasn’t some features like lighttpd :)

    1. Olbi, I was writing for the masses. Apache is by far, the most popular and highly recognized web server in the market. There is no doubt lighttp, nginx and cherokee are lighter and faster web servers, but at the moment Apache still is the king, hence the LAMP install how-to on the Ubuntu Desktop.

  3. this is good advice for the old ubuntu,s i was playing with ubuntu 6/7 for a few years and it didnt run for me i tried alsorts now i,ve got super ubuntu 9.04 and apache 2 is in it it,s a dream still working on it [but i dont no longer need windows] so i,d like to thank the hackersclub who got me interested in ubuntu and nmap hackers for there part and to all those wonderfull peoples contributing to ubuntu[us] and to richard stallman who started the ball rolling with his freinds LEZLOW nb you can freely give copies of ubuntu to anyone if you cant get a copy e me lezlow111@yahoo.co.uk i,ll forward a link

    1. I’m sure tasksel is a convenient tool, but there are times it’s worth installing applications from the Terminal, not to mention the knowledge and the hands-on training you’ll get by playing with the Terminal.

  4. Thank you for the guide. I followed your instructions to the letter, but I couldn’t get mod_rewrite working. I have tried many times before and come unstuck at this part every time. Is there something else you need to do that I have missed? Are there certain permissions that need to be set for it to work?

    I am using Ubuntu 9.04.

    1. Noelinho, There’s a couple of things you could check. Make sure your Apache server has the mod_rewrite module installed. You can check the httpd.conf file. Look for “LoadModule rewrite_module modules/mod_rewrite.so” and “AddModule mod_rewrite.c” to make sure they are not commented out. Also check the permissions of .htaccess.

  5. Just as an update: I edited /etc/init.d/apache2/sites-available/default again, changing the following:

    DocumentRoot /var/www

    Options FollowSymLinks
    Allow Override None

    I changed AllowOverride None to AllowOverride All, and then restarted the server again. Then it worked.

    Just in case anyone else has any problems… I’ve never managed to get mod_rewrite to work in Ubuntu before!

    1. It worked. I think the apache2 restart in the end did the trick also. I should also add the restart instruction in the end to be perfectly clear. :)

  6. What does the following do?

    cd /var/www/
    touch .htaccess
    chmod 777 .htaccess
    sudo a2enmod rewrite

    I just started with linux (ubuntu), I was following dozens of tutorials how to install LAMP, but none of them worked when it came to .HTACCESS use. (it constantly gave me ‘internal server error’ )

    I was just about to give up when I bumped into your site, I tried the above commands from your tutorial (the .htaccess part)…and like “magic”…it worked….

    Anyway…my THANKS for your efforts!!

    1. The touch command creates a blank file. Chmod changes permission to a file and makes it executable and writable to others. The a2enmod command enables mod_rewrite in Apache. I’m glad .htaccess worked for you.

  7. Hello!

    Everything works just fine but “my links are not pretty” :).

    I use ubuntu 9.10, i follow all these steps and everything is ok but it seems that the .htaccess doesn’t work because i get a blank page where the url should be “pretty”.

    Could anybody help me? Pls! Thanks a lot

Comments are closed.