Install Apache/PHP/Mysql On Ubuntu



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/
<?php
    //file: test.php
    phpinfo();
?>

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
extension=pdo.so
extension=pdo_mysql.so
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

Get MySQL:
sudo aptitude install mysql-server

Set your root password
mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’xxxxxx’);

Try running it
mysql -uroot -p
* you password will be asked!

Now let's install mysql with apache
sudo aptitude install libapache2-mod-auth-mysql php5-mysql

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!
copyright ericpotvin.us 2010 © all rights reserved.