Drupal development setup on Ubuntu 13.10

I upgraded my local computer to Ubuntu 13.10 today and revisited my Drupal development environment (this guide is also available for Ubuntu 12.04). Here is a simple and fast guide how to configure Ubuntu for development. There are a number of installation documentation pages on this topic on drupal.org, but they suggest to use the packaged Drupal installation and to run Drupal in subfolders (e.g. http://localhost/drupal6). They also do not cover some other important development tools like Phpmyadmin or php.ini settings. During development we want to edit files and we want to do that somewhere in our home directory to avoid any permission problems. There is also Drubuntu, but it is outdated and does way too much magic in my opinion. So here is a more transparent tutorial that highlights the key development configuration settings for Drupal development on a local computer (do not use this for a production server!).


To install a web server and MySQL and PHP and all the dependencies we simply install the default Ubuntu drupal7 package:

sudo aptitude install drupal7

The installation will probably prompt you for a few things: Set a password for the MySQL root user. For the Postfix configuration you can select the "Local only" profile, so that no outgoing mail will be sent by PHP from your computer. For the postfix system mail name you can just leave it at your default hostname. The installation will probably prompt you to configure a default drupal database, but we will do that manually afterwards, so skip it.

We don't want to expose any of our sites to the outside world, so we limit Apache to only listen on the localhost interface. Edit /etc/apache2/ports.conf and replace "Listen 80" with "Listen".


We want Apache to run as our own user account to avoid any permission problems or conflicts when running drush or editing config files. Edit /etc/apache2/envvars and change the user to your account name. Example:

export APACHE_RUN_USER=klausi
export APACHE_RUN_GROUP=klausi

Enable the Rewrite mod and restart Apache.

sudo a2enmod rewrite
sudo service apache2 restart

Now we would like to have Phpmyadmin to easily create, inspect and manipulate MySQL databases.

sudo aptitude install phpmyadmin

The installation will probably prompt you for a few things: Confirm that you want to automatically configure a database with dbconfig-common. Select Apache as web server to configure automatically.

Now your Phpmyadmin installation should be reachable at http://localhost/phpmyadmin/ .

We will need some tools for development:

sudo aptitude install git php5-xdebug php5-curl


It is important to tune your /etc/php5/apache2/php.ini for development purposes to show all PHP warnings. I changed the following entries:

memory_limit = 256M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
track_errors = On
html_errors = On
session.gc_probability = 1

Folder setup

The next step is the setup of a workspace environment in my home folder where I will develop my Drupal projects. Example for my "drupal-8" development environment:

  • Drupal root: /home/klausi/workspace/drupal-8
  • Apache config: /etc/apache2/sites-available/drupal-8.conf
  • Browser: http://drupal-8.localhost
  • Database: drupal-8

Checkout Drupal 8:

cd ~
mkdir workspace
cd workspace
git clone --recursive --branch 8.x http://git.drupal.org/project/drupal.git drupal-8

Apache config

Create an Apache configuration for your drupal-8 folder at /etc/apache2/sites-available/drupal-8.conf:

<VirtualHost *:80>
        ServerAlias drupal-8.localhost
        DocumentRoot /home/klausi/workspace/drupal-8
        <Directory "/home/klausi/workspace/drupal-8">
                Options FollowSymLinks
                AllowOverride All
                Require all granted

Enable the configuration and restart Apache:

sudo a2ensite drupal-8
sudo service apache2 restart

You might wonder why I do not use an Apache wildcard/catchall configuration, here is the reason why: unfortunately the VirtualDocumentRoot directive requires that you modify your .htaccess in your Drupal installation (you have to enable the RewriteBase /). This is bad because then you always have local changes in that file if you are working with a Drupal core git checkout.

localhost DNS

Create the domain entry for drupal-8.localhost in /etc/hosts. Add " drupal-8.localhost". You will have to add each new project name in this file (you could also install Bind to automatically resolve this, but seems like an overkill to me).

I wrote a simple bash script that automatically creates the Apache site config and the site's hosts entry for me. Make sure to change the WORKDIR to your directory and run it like this:

sudo deploy-site.sh drupal-8


Create the database in Phpmyadmin: Go to http://localhost/phpmyadmin , then "Privileges", then "Add a new User". Fill out the user name with "drupal-8", host localhost and generate a password (copy that password to use it later during the Drupal install process). Use the "Database for user" section and select "Create database with same name and grant all privileges".

Install Drupal

Now your Drupal installation should be reachable in your browser at http://drupal-8.localhost and you can start the installation. Done!

You can also use drush to install Drupal from the command line:

drush site-install --account-name=klausi --account-pass=klausi --site-name=drupal-8.localhost

Development tips

  • I highly recommend using an IDE for source code editing such as Netbeans or Phpstorm. Drupal is spread over thousands of files and shortcuts to jump to other files are a real time saver, same for code completion as you type. And having a debugger to step through the code is very helpful.
  • You want to speed up MySQL because you don't care about your local development databases anyway? Put MySQL on a RAM disc that syncs back to your hard drive on start/stop.
  • You want to examine mails that Drupal sends out? Configure PHP to write outgoing mails to temporary files.
  • You like the command line? Check out drush to do all sorts of Drupal administration tasks faster.
  • You want to know what's going on in that stupid function? Install the devel module for debugging purposes and insert dpm($variable); anywhere you want. It will pretty-print the variable in the browser for inspection.
Attachment Size
deploy-site.sh_.txt 674 bytes


A typo:
/etc/apache2/site-available/drupal-8.conf > /etc/apache2/sites-available/drupal-8.conf

For those not familiar with aptitude: note that Ubuntu 13.10 (at least with the way I installed it), didn't come with aptitude installed by default, so I needed to run this before I could follow the instructions:
sudo apt-get install aptitude

You can alternatively use "apt-get" instead of "aptitude" in the commands of this tutorial.

Also, your link to deploy-site.sh contains a # fragment at the end.

So good

I have got most of this working, but I can't import existing data bases either through phpMyAdmin or mysql command. In phpMyAdmin it gives the following error: "Warning: Unknown: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/javascript/) in Unknown on line 0"
Also I'm now on ubuntu 14.04 not 13.10. Any ideas would be great. After reading around it looks like the problem may have something to do with apache using my own name and group. But I'm not shore how to resolve this as I would like to use the setup you posted above. Also thanks for the bash script it works great.

First of all thanks for this tutorial it was verry helpful.
In order to work for me I changed start of drupal-8.conf from VirtualHost *:80 to VirtualHost drupal-8.localhost:80 and add ServerName drupal-8.localhost
Otherwise it shows default apache2 homepage instead of the virtual host home page. Also in order to be able to edit files in IDE (PhpStorm in my case) I added the user I used to www-data group and change user:group of files to :www-data. The last part was a real bummer since I come from Windows background

Hello, thanks for this article. I made a few modifications to deploy-site.sh so that it can have a different hostname and folder name. This is useful because a lot of people I collaborate choose to have Drupal in a sub "docs" folder of the git root. It's hosted in this repo: https://github.com/molenick/kubuntu-drupal-dev-setup.