Saturday, October 20, 2012

Installing a LAMP Stack on Ubuntu Using APT

This is to help people set-up and install a LAMP (Linux-Apache-MySQL-PHP) stack in Ubuntu, including Apache 2, PHP 5 and MySQL 5.0. You can actually do it with one line of commands but since that’s not the point, let’s go step by step.
Installing Apache 2

open up the Terminal and then type this line:

sudo apt-get install apache2 apache2-utils

To restart the server
sudo /etc/init.d/apache2 restart

Browse to http://localhost , you should see displayed a text message “it works”

By default, your document root folder is located at : /var/www/ . Out of the box, you won’t have write permission to this folder, so first of all we need to change that by changing the ownership of the folder to your user.

At a terminal, do the following (replacing salimane with your login name):

sudo chown -R salimane /var/www

By default, Ubuntu’s Apache 2 will ignore the directives in your .htaccess files. To make .htaccess files work as expected, you need to edit the file /etc/apache2/sites-available/default (sometimes /etc/apache2/sites-available/000-default)
Look for a section that looks like this:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/

You need to modify the line containing “AllowOverride None” to read “AllowOverride All”. This tells Apache that it’s okay to allow .htaccess files to over-ride previous directives.

You must reload Apache before this change will have an effect:

sudo /etc/init.d/apache2 reload

Installing MySQL Server

open up the Terminal and then type this line:

sudo apt-get install mysql-server

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 MySQL configuration file my.cnf .

gksudo gedit /etc/mysql/my.cnf

remove or comment out the line

bind-address =
and restart mysql server with :

sudo /etc/init.d/mysql restart

Installing PHP5

open up the Terminal and then type this line:

sudo apt-get install php5

Installing PHP5 module for apache2

open up the Terminal and then type this line:

sudo apt-get install libapache2-mod-php5

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

To ensure there are no issues with PHP let’s give it a quick test run. In the terminal copy/paste the following line:

echo "<?php phpinfo(); ?>" > /var/www/phpinfo.php

Now open your web browser and type the following into the web address: http://localhost/phpinfo.php

Installing MySQL module for PHP5

open up the Terminal and then type this line:

sudo apt-get install php5-mysql mysql-client

then edit the PHP configuration file php.ini and uncomment the following line by taking out the semicolon (;).
Change this line:


To look like this:

Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart

Installing PHPMyAdmin

One of the easiest ways to manage your new MySQL database server is to use the graphical tool PHPMyAdmin.
Simply go to your terminal again and enter the following command:

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

Restart Apache :

sudo /etc/init.d/apache2 restart

Now just point your browser at http://localhost/phpmyadmin/.

Installing some useful modules in PHP

If you have installed xampp for Linux you will see that by default they are already some modules installed for you . But unfortunately for the default lamp stack in Ubuntu it’s not, so let’s install those common used modules in php like gd,pear,curl,memcache,xmlrpc,xsl…

sudo apt-get install php5-dev php5-gd php-pear php5-curl php5-memcache php5-xmlrpc php5-xsl php5-imagick php5-mcrypt php5-mhash

Restart Apache

sudo /etc/init.d/apache2 restart

No comments:

Post a Comment