Tuesday, February 11, 2014

Install LAMP in Ubuntu 13.10 Saucy(Apache, MySQL, PHP)

This is a short guide to installing a basic LAMP(Linux, Apache, MySQL, PHP) development environment on Ubuntu 13.10 Saucy Salamander.  There are a few differences with the installation on 13.10 compared to previous versions due to the newer version of PHP and Apache in the official repositories.

First install lamp:
Open a terminal and run the following:

sudo apt-get install lamp-server^

After the lamp server installation you will need write permissions to the /var/www directory.  Follow these steps to configure permissions.

Add your user to the www-data group

sudo usermod -a -G www-data <your user name>

now add the /var/www folder to the www-data group

sudo chgrp -R www-data /var/www

now give write permissions to the www-data group

sudo chmod -R g+w /var/www

NOTE: these changes will not be seen in nautilus until you log out and log back in again.

Some extra things to install
The following are not essential but they are things I almost always need as part of a LAMP install so I have included instructions on installing them.

json_encode
You will almost certainly want the json_encode function in PHP which no longer comes installed by default.  To install it run the following command:

sudo apt-get install php5-json

Curl:

sudo apt-get install php5-curl

Mod rewrite:

sudo a2enmod rewrite

To enable mod rewrite you also need to do some apache configuration:

sudo gedit /etc/apache2/sites-available/000-default.conf

add the following to the file below the DocumentRoot option:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

sudo /etc/init.d/apache2 restart

GD2 Graphics Lib:

sudo apt-get install php5-gd

Turn on error messages
If you are setting up a dev environment then you will want to turn on error messages too. To do this run the following:

sudo gedit /etc/php5/apache2/php.ini

then find the line that looks like this(around line 480):

display_errors = Off

and change it to

display_errors = On

There are a bunch of other error reporting variables you can turn on in the php.ini file for development purposes, they are well commented so just turn on any that you think will be useful.

I also highly recommend making the same changes to the php.ini file that is used when running php scripts from the command line(this includes cron jobs), just run the following command to open it and make the same changes you did above.

sudo gedit /etc/php5/cli/php.ini

You will need to restart Apache for the changes to take effect.

sudo /etc/init.d/apache2 restart

And that's it, have fun!