LAMP Environment

by Admin on July 20, 2010

Contributed by Sohail Ashraf

This week on Ubuntu we have for you LAMP Environment. Below is the tutorial which will help you in its installation and configuration.
Installing and configuring LAMP Environment

Use the following procedure to install and configure LAMP Environment. This will install Apache, PHP and MYSQL collectively.

* Go to Terminal Applications → Accessories → Terminal
* sudo su
* Enter the root password
* sudo apt-get install apache2
* Type in your browser address bar. http://localhost/ and you will see a message “It works!”
* sudo apt-get install php5
* sudo apt-get install libapache2-mod-php5
* sudo apt-get install mysql-server
* You will find a blue screen like figure 1. Just enter the password you want to choose for mysql and then use “tab” key to select “ok” and then press “enter” key to proceed.

Figure 2: Set Mysql Server Password

* After that you will again find a blue screen like figure 2 for confirmation of password. Just enter the password and then use “tab” key to select “ok” and then press “enter” key to proceed.

Figure 3: Repeat Mysql Server Password

* sudo apt-get install php5-mysql
* sudo /etc/init.d/apache2 restart
* sudo /etc/init.d/apache2 stop
* Or you can use below command for this purpose too.
* To restart apache use apache2ctl graceful command in Terminal
* To stop apache use apache2ctl graceful-stop command in Terminal
* To check the status of your web server use apache2ctl status command in Terminal
* chown <your user name>.<your user name> /var/www
* /var/www will be you default web root directory
* PHP Configuration file will be located on /etc/php5/apache2/php.ini
* Apache Configuration file will be located on /etc/apache2/httpd.conf
* MySQL configuration file will be located on /etc/mysql/my.cnf
o sudo apt-get install phpmyadmin

Installing PHPMyAdmin

You will find a blue screen like figure 3. Press “space” key against apache2 and then use “tab” key to select “ok” and then press “enter” key to proceed.

Figure 4: PHPMyAdmin Server Type Selection

Then you will see “Configuring phpmyadmin “ popup just use tab key with option “yes” and press etner . See the fig 4.

Figure 5: PHPMyAdmin Setup Manually or Automatically

Again You will find a blue screen like fig 5. Enter the password which you set for mysql server.Use “tab” key to select “ok” and then press “enter” key to proceed.
Figure 6: Mysql Root Password

Again You will find a blue screen like fig 6. Enter the password for using phpmyadmin application .Use “tab” key to select “ok” and then press “enter” key to proceed.

Figure 7: PHPMyAdmin Password

Again You will find a blue screen like fig 7. Enter the confirmation password for using phpmyadmin application .Use “tab” key to select “ok” and then press “enter” key to proceed.

Figure 8: PHPMyAdmin Confirm Password

Just type http://localhost/phpmyadmin on your browser address bar to check it will working.
Installing GUI front end for mysql

If you want a GUI based front end for mysql then use the below step else move to next step.

* sudo aptitude install mysql-admin

Installing PHP Libraries/Modules

The following steps will show you how to install PHP Libraries/Modules in your  Linux System. The regular procedure is to use tar balls. But some libraries can be installed automatically.
Installing GD2 Library for PHP

This will demonstrate you to install GD2 Library

* Go to Terminal Applications → Accessories → Terminal
* sudo su
* Enter the root password
* apt-get install php5-gd

Generalized procedure of installing Libraries

This will show you the generalized approach to install PHP libraries.

* Go to Internet and find tar balls of that library. These files would be .tar.gz extension
* Download tar ball
* Go to Terminal Applications → Accessories → Terminal
* cd <path to tar ball>
* tar –zxvf <library>.tar.gz
* cd <libaray>
* make
* make install

Setting Up a Web Site

First, create a subdirectory of /home/user_name/mydomain.com to contain the site. It makes sense to name this directory after the domain that will live there.

* Go to Terminal Applications → Accessories → Terminal
* mkdir /home/user_name/mydomain.com
* Now create /home/user_name/mydomain.com/index.html .
* nano /home/user_name/mydomain.com/index.html

Write something simple like the following:

<html>

<head>

<title>Mydomain.com test index page</title>

</head>

<body>

<h1>Hello World!</h1>

</body>

</html>

After this now create /etc/apache2/sites-available/mydomain.com

* nano /etc/apache2/sites-available/mydomain.com

We use the <VirtualHost> directive to define the virtual site, and the <Directory> directive to define the /home/user_name/mydomain.com/ directory as publicly accessible (Allow from all). Like so copy following code and paste in  you file:

<VirtualHost 127.0.1.1:80 >

#Basic setup

ServerAdmin webmaster@mydomain.com

ServerName mydomain.com

DocumentRoot /home/user_name/mydomain.com

<Directory /home/user_name/mydomain.com>

Order Deny,Allow

Allow from all

# Don’t show indexes for directories

Options -Indexes

</Directory>

</VirtualHost>

Save this file and move back to Terminal.Now, to enable the site you use the a2ensite command (Note:use a2dissite to disable). The following creates a symlink /etc/apache2/sites-enabled/mydomain.com, which enables the site.

* a2ensite mydomain.com

Now You need to edit hosts file and add following line.

127.0.0.1       mydomain.com

* sudo nano /etc/hosts

You need to reload Apache to see the site…

* /etc/init.d/apache2 reload

If DNS is working, you should now be able to point your browser at www.mydomain.com see the index.html page you created above.

How to enable a module in Appache

If you need to enable any module in Appache then just use “a2enmod” command next mention the name of that module.

* Go to Terminal Applications → Accessories → Terminal
* sudo a2enmod rewrite

{ 3 comments… read them below or add one }

Yasir July 24, 2010 at 5:09 PM

Its really helpfull

Ahmed August 11, 2010 at 10:35 AM

Great.. So a php Developer should use ubuntu for development.

Ahmed August 11, 2010 at 10:36 AM

Also quite descriptive dude. I was trying to create lamp environment from last two days. but after reading this article just in 5 minutes i set it up.

Leave a Comment

Previous post:

Next post: