Install a LAMP (Apache, PHP, Mysql) On Ubuntu

Posted on Monday April 18, 2011 / by Eric Potvin

This guide will help you to install a local web server using Apache, MySQL and PHP on Ubuntu.

Install apache2:

sudo aptitude install apache2

Edit the /etc/apache2/httpd.conf to setup your ServerName

ServerName <myhostname>

Start apache2 and test:

sudo /etc/init.d/apache2 start

* If everything is OK you should see an ordinary HTML page when you type: http://localhost in your Firefox browser

Stop apache to install other component:
sudo /etc/init.d/apache2 stop

Let's install PHP

sudo aptitude install php5 libapache2-mod-php5

Restart Apache

sudo /etc/init.d/apache2 start

To test the PHP installation, create a dummy file in /var/www/

    //file: test.php

PDO (PHP Data Objects)

If PDO (PHP Data Objects) is not installed, this is how to install it:

First, install some needed modules:

sudo aptitude install php5-dev libmysqlclient15-dev

libmysqlclient15-dev is needed by PDO mysql driver

Next, install the PHP pear:

sudo aptitude install php-pear

Then, you can install the PDO itself an the database specific driver, for example mysql driver:

pecl install pdo
pecl install pdo_mysql

Check the php.ini: open the /etc/php5/apache2/php.ini and add check if these following lines are there

if not installed, you can simply add it

And don't forget to restart your web server.

sudo /etc/init.d/apache2 restart

Install MySQL


sudo aptitude install mysql-server

Set your root password

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypass');

Try running it

mysql -uroot -p

your password will be asked!

Now let's install mysql with apache

sudo aptitude install libapache2-mod-auth-mysql php5-mysql

Set the default engine

If you like to set the default engine to innodb or myisam you can easily change it using the default-storage-engine option in the /etc/mysql/my.cnf file.

default-storage-engine = innodb

Restart MySQL

/etc/init.d/mysql restart

Restart apache and test

sudo /etc/init.d/apache2 restart

(optional) you can setup your /etc/mysql/my.cnf file regarding your needs

Installation done! enjoy!

Once everything is installed, you might need some useful PHP extensions like:

sudo aptitude install php5-cli php5-curl php5-gd php5-imap php5-mcrypt