Monday, July 11, 2011

How to install LAMP in Linux Ubuntu 11.04

How to install Linux, Apache, MySQL, PHP in Linux Ubuntu 11.4
I couldn't believe that it is so easy to install LAMP in Ubuntu. It is a little different with installing in older versions but steps are too easy to realize. Just do it now.
More Linux Tricks and How-tos can be found at: Linux Category.

1. Install Apache

Open your terminal and type these commands:

sudo apt-get install apache2

This command will install Apache to your computer. You will need to connect to the internet to do this. After the command has finished it works. Open you Internet browser and type:


"It works!" will display on you browser. You have finished installing Apache2.

Note: To restart Apache use this command:

sudo /etc/init.d/apache2 restart

From now on, The document root of the default web site is /var/www.

2. Install PHP5
In this part we will install PHP 5.
Step 1. Again open your Terminal (Applications > Accessories > Terminal).
Step 2. Type the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5 php5-common php5-cli

Step 3. In order for PHP to work and be compatible with Apache we must restart Apache. Now we need to test if we installed PHP correctly.
Step 1. In the terminal copy/paste the following line:

sudo gedit /var/www/testphp.php

This will open up a file called phptest.php.
Step 2. Copy/Paste this line into the phptest file:

Step 3. Save and close the file.
Step 4. Now open you're web browser and type the following into the web address:


The page should show you information about PHP installed in your computer. It means you have installed PHP5 successfully.

As we have PHP-CLI instaled, we can test the installation of the GD Library with command line:

php -r "var_dump(function_exists('imagecreatefromjpeg'));"  

<-- will output true if GD Library is installed
php -r "var_dump(function_exists('imagerotate'));"  

<-- will be false if the limited library is installed

3. Install MySQL

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

sudo apt-get install mysql-server mysql-client

After a few minutes waiting depend on you internet connection, you will get this dialog:
Remember: Because MySQL has been upgraded since its older version so you don't need to type some complicated commands during installation. MySQL tried to give you the GUI.
Just type your password for root user. Please remember this user/password.
 MySQL will ask you to let it config webserver to work with. You should choose Apache2 (press Space bar to select and TAB to move cursor.) and OK.

Step 2: We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:

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

During the installation you will get this diablog:
You should choose YES if you don't have any database installed before. 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

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


To look like this:

We want MySQL to listen on all interfaces, not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address =

nano /etc/mysql/my.cnf

Then we restart MySQL:

/etc/init.d/mysql restart

Now check that networking is enabled. Run

netstat -tap | grep mysql

Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart

Now you can access PHPMyAdmin via this address: http://localhost/phpmyadmin/
You will have to provide password for root user that you have established before to enter PHPmyAdmin. This will look like this:

Note: To restart MySQL use this command:
/etc/init.d/mysql restart

As you see, It is easy to complete your webserver with PHP and MySQL in this.

Special Note: What if I already forget my MySQL's password. You can visit this page to find how to reset MySQL password.

Thank you for visiting my blog. Any question can be comment below.

No comments:

Post a Comment