Wednesday, August 25, 2010

How-to: Setup LAMP on Ubuntu 10.04

Here's a lengthy yet simple procedure that describes how to install LAMP server on Ubuntu 10.04.

Installing Linux Apache MySQL and PHP, as what LAMP stands for, is described here. Since We've mentioned that we're installing it on Ubuntu 10.04 which is a linux, we're done with the first part. We will thus install Apache MySQL and PHP here.

Installing Apache

Open the Terminal and type the following.
sudo apt-get install apache2
Now it prompts for your password. Enter and press Return. Apache will be installed.

Testing Apache

Open any web browser and type the following in the address bar.
http://localhost/
It should open up the test page which must say - "It Works!". If you aren't getting that, then something's wrong and repeat the installation procedure again.

Installing PHP

Open up the Terminal again (Applications -> Accessories -> Terminal) and type the following line (or just copy-paste this).
sudo apt-get install php5 libapache2-mod-php5
php5 is your PHP engine and libapache2-mod-php5 is a library file that enables apache to recognize php scripts.

Testing PHP

In order to test PHP you should write a PHP script in the /var/www/ directory. Here's a quick guide to write and run a php script.

Open up a Terminal again and type the following.
sudo gedit /var/www/phptest.php
A editor opens up. Copy paste the following simple program.
<?php phpinfo(); ?>
It should open up the php information sheet which is something like this.



If you can see this then you're done with Apache and PHP installation.

Installing MySQL

Installing MySQL is little troublesome and may go awry. The following guide is pretty perfect and if anything goes wrong and doesn't act the way it is supposed to be then just comment here and I can help you out.

Open up the Terminal and type the following :
sudo apt-get install mysql-server
This should install the mysql-server.

At the end of the installation it asks you to set a password for the mysql running on your local system. Set it.

Now you can open MySQL in command line by typing the following in the command line (terminal).
mysql -u root -p
It requests your mysql password now. Enter and press return to enter the mysql prompt. If you can see the mysql prompt then you've successfully installed mysql.

phpMyAdmin is a GUI to the MYSQL and can be used for easy creation of databases. To install phpMyAdmin Copy/Paste the following in the terminal.
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
Now the last thing is to get your PHP working with MySQL and for that you've to edit a file called php.ini. Here's how.

Open the terminal and type the following.
gksudo gedit /etc/php5/apache2/php.ini
A file in an editor opens. Search for this line
;extension=mysql.so
And edit it to this
extension=mysql.so
(we've only removed the semi colon). Save and Exit.

Now restart apache
sudo /etc/init.d/apache2 restart
That is it. LAMP is set up on your Ubuntu Linux Machine. :)

PS: If you find any problems anywhere in this guide then please comment on the post. I will be glad to help.

1 comment: