Local Development (LAMP)

The easiest and best way to test new features or do potentially damaging things to your site is to do so on your own computer. By doing this, you will always be able to safely destroy data with impunity. The basics of creating a local environment are relatively simple. You will need a full Linux Apache MySQL PHP (LAMP) stack in order to accomplish this. Below I detail how to create a LAMP stack on your local machine.

Needed Packages

In order to get a fully functional LAMP stack you will need to run the following command:

$ sudo apt-get install apache2 mysql-server mysql-client php5 php5-mysql libapache2-mod-php5 php-pear

If you are running Ubuntu or Mint, you may be able to simply run:

$ sudo apt-get install lamp-server^

This command should install everything you need to have a functional LAMP stack.

NOTE: During the installation, mysql will ask you for a root password. This is not your 'root' password, but a password specifically for mysql. Use a unique password here and not your system password.

Next, stop apache with the command:

$ sudo service apache2 stop

Configuration File

Once you've built your LAMP stack, you'll need to make one more modification.
Edit the file /etc/apache2/envvars

$ sudo gedit /etc/apache2/envvars

Add the following lines:


Where YOUR_USER_NAME is the name of your normal user.

Comment out (add a '#' in front of) the lines that read:

# export APACHE_RUN_USER=www-data
# export APACHE_RUN_GROUP=www-data

Save the file.

EXAMPLE: In my envvars file there's a block that looks like this:
# export APACHE_RUN_USER=www-data
# export APACHE_RUN_GROUP=www-data
export APACHE_RUN_USER=ross
export APACHE_RUN_GROUP=ross

Start apache with the command:

$ sudo service apache2 start

NOTE: This is how I run my apache processes, though there are other configurations if you want to research them.

Test apache

You should now be able to verify apache by going to in a web browser. You should see simply

"It Works!"

If you do see this, then your apache configuration is complete. If you do not see this, then something has gone wrong.

MySQL User

Since we do not want to run mysql with the root user, we'll create a new user to handle the mysql queries. The most secure way to do this is to add a new mysql user for very project you plan to create. However, in most cases this is not necessary. I recommend creating a single mysql user that has access to all of your databases.

To accomplish this you'll want to enter the mysql prompt as the root user. The following commands should get you there. You'll be prompted for a password, use the password you set for root during the mysql-server configuration.

Make sure to change 'NEW_USER_NAME' and 'PASSWORD', below, to the correct values.

$ mysql -u root -p
mysql> GRANT ALL PRIVILEGES ON * . * TO 'NEW_USER_NAME'@'localhost';
mysql> exit;

Now test the user and password to make sure you can access the mysql database:

$ mysql -u NEW_USER_NAME -p

This should prompt you for the password you entered in the "IDENTIFIED BY 'PASSWORD';" section above.

Once you've verified mysql is functioning properly, you should be setup.