I upgraded my local computer to Ubuntu 12.04 today and revisited my Drupal development environment. 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.
To install a web server and MySQL and PHP and all the dependencies we simply install the default Ubuntu drupal 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 127.0.0.1:80".
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:
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 php-apc
It is important to tune your /etc/php5/apache2/php.ini for development purposes. I changed the following entries:
memory_limit = 256M
error_reporting = E_ALL | E_STRICT
display_errors = On
display_startup_errors = On
track_errors = On
html_errors = On
session.gc_probability = 1
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
- Browser: http://drupal-8.localhost
- Database: drupal-8
Checkout Drupal 8:
git clone --recursive --branch 8.x http://git.drupal.org/project/drupal.git drupal-8
Create an Apache configuration for your drupal-8 folder at /etc/apache2/site-available/drupal-8:
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.
Create the domain entry for drupal-8.localhost in /etc/hosts. Add "127.0.0.1 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".
Now your Drupal installation should be reachable in your browser at http://drupal-8.localhost and you can start the installation. Done!
- 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.