Friday, December 10, 2010

Configuring LAMP on Ubuntu

This post is for those who have a very little knowledge of linux based operating systems. LAMP stands for Linux, Apache, Mysql, Php. The following are steps to install LAMP on Ubuntu.

Installation guide for Apache.

To start off with the installations, we will first install apache.

1. Open up the Terminal (Applications > Accessories > Terminal).

2. Copy/Paste the following line of code into Terminal and then press enter:

sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache 

To make sure we have installed everything properly we will test the apache installation.

4. Open up any web browser and then enter the following into the web address:

http://localhost/

5. You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!
 

Installation guide for PHP 

In this part will install PHP on our systems.

1. Again open up the Terminal (Applications > Accessories > Terminal).


2. Copy/Paste the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

3. In order for PHP to work and be compatible with Apache we must restart it.  Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.

1. In the terminal copy/paste the following line:

sudo gedit /var/www/test.php

This will open up a file called test.php.

2. Copy/Paste this line into the test file:

<?php phpinfo(); ?>

3. Save and close the file.

4. Now open you're web browser and type the following into the web address:

http://localhost/test.php

The page should look like this:
Congrats you have now installed both Apache and PHP!

Installation guide for MySQL

To finish this guide up we will install MySQL


1. Once again open up the amazing Terminal and then copy/paste this line:

sudo apt-get install mysql-server

2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line
bind-address = 127.0.0.1
And change the 127.0.0.1 to your IP address.

3. Now begin by typing the following into Terminal:

mysql -u root

Following that copy/paste this line:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
 (Make sure to change yourpassword to a password of your choice.)

4. Now we are going to install a utility called phpmyadmin. This utility is available here. This is useful in database administration. Download the latest version and extract the contents of the utility in the directory /var/www/phpmyadmin/

phpmyadmin could now be accessed by using the following url http://localhost/phpmyadmin/
It requires a mysql username and password which you have already set in the last step.


5. After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
 
gksudo gedit /etc/php5/apache2/php.ini

6. Now we are going to have to uncomment the following line by taking out the semicolon (;).
Change this line:

;extension=mysql.so

To look like this:

extension=mysql.so

7. Now just restart Apache and you are all set!
sudo /etc/init.d/apache2 restart

Now we have successfully configured LAMP on ubuntu. This is my first attempt to write a post like this. I would like hear from you what you have to say about the same.

No comments:

Post a Comment