As a web developer I prefer to work on my development environment before rolling out the changes to Production environment. For the same I use Apache, MySQL and PHP package on my Ubuntu 12.04 box. Today’s article is about how to install all these packages with minimum commands and efforts. To achieve this we are going to install LAMP on our Ubuntu box. LAMP (Linux, Apache, MySQL and PHP) is an open source Web development platform that uses Linux as operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language.

Installation
Step 1 Open a command prompt and run following command to install LAMP

sudo apt-get install lamp-server^

install-lamp-on-ubuntu-1
install-lamp-on-ubuntu2

Step 2 At the time of installation you will be prompted to set a password for the root user for MySQL
install-lamp-on-ubuntu3
install-lamp-on-ubuntu4

Your LAMP installation is now complete. Just a single command to install all three package on a ubuntu box.

Configuration
LAMP will install the default things. Now we have to modify certain parameters as per our need.

Configuring apache webserver
Open a command prompt and add ServerName hostname in the Global Configuration tag of /etc/apache2/apache2.conf
install-lamp-on-ubuntu5
Remember to put your hostname.

Run following command to restart your apache2 server

/etc/init.d/apache2 restart

install-lamp-on-ubuntu6

Configure MySQL
Since this tutorial is for setting up a local web development environment, the MySQL needs to be bound to the localhost IP address. By default this should be 127.0.0.1 on your system. Just in case, you can verify it with these commands.

cat /etc/hosts | grep localhost

You should see something like

 
You now  want to verify that you have the correct bind address in MySQL's my.cnf file.
<pre lang="bash">
cat /etc/mysql/my.cnf | grep bind-address

You should see:

bind-address = 127.0.0.1

If the bind address doesn’t match the one set for localhost on your system, you’ll need to edit/etc/mysql/my.cnf as root to correct it.

Testing Apache
Open a web browser window and enter the address http://SERVER_IP_OF_LAMP/ You should see a web page that says “It Works!”
install-lamp-on-ubuntu

Testing PHP
Now that you’ve confirmed that the Apache web server works, you want to make sure that your php installation is working. To do that you need to create a file in /var/www called testing.php. You can use your favorite text editor as root, or you can use the following terminal command:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/testing.php

Go back to your web browser and enter the address http://SERVER_IP_OF_LAMP/testing.php and you should see a page displaying information about your php installation.
install-lamp-on-ubuntu8

How to Install LAMP on Ubuntu 12.04
Tagged on:                                                                                                                                                                                                                                                                                                                                     

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Recommend on Google