Overview
This tutorial has been updated to work with Ubuntu 9.04 (Jaunty Jackalope), but should also work well on earlier versions of Ubuntu. The intent is to provide step-by-step instructions to help you with the server setup of a complete development workstation on Ubuntu. DO NOT USE THESE INSTRUCTIONS FOR PRODUCTION SITES. This flexible setup will allow you to easily develop for multiple clients/projects AND work on multiple versions of Drupal. This tutorial is edited and maintained by the Drupal community. If you find something incorrect, know a better "best practice", or something simply doesn't work, please leave a comment and we'll fix the tutorial. But if you know how to correct the tutorial, please just update the wiki.
Details on Multi Vhost setup
This tutorial may seem incomplete. That's because it is only a part of a series of posts found in the Drubuntu group. After you've completed your server setup, you might want to know the details on how/why we chose this configuration. Be Sure to visit the overview and links of the Drubuntu HOWTO, which explains how to install and configure an Ubuntu/LAMP/Eclipse Drupal development environment.
GUI Centric Approach
If you would prefer to try a more GUI centric approach to installing LAMP, there is a great video walkthrough available that details some of these steps. However the video tutorial helps you to set up a single vhost server, not the multi vhost we configure below. A single vhost setup might be easier for someone deploying a single website. A multi vhost setup tends to be more useful for development, and is a much more flexible setup. Plus this configuration its ready to support Drupal in either a single OR multi-site setup.
Install LAMP Workstation packages from Ubuntu repository
The code packages that install LAMP are listed below. This command also installs other modules as the result of dependencies of the primary package.
*** !Important note for Ubuntu Lucid and higher releases, you should see the section on apt pinning if you intend on running PHP 5.2 instead of the default 5.3 that is in the lucid and higher repositories.
To install LAMP, run this command at a terminal:
sudo apt-get install apache2 php5 php5-mysql php5-gd mysql-server
To install optional extensions, run this command at a terminal:
sudo apt-get install php5-curl php5-imagick php5-ffmpeg phpmyadmin mysql-query-browser php5-cli php5-mcrypt
- Query the web for updates (php5-curl)
- Provide additional imaging capabilities (php5-imagick)
- Various media capabilities (php5-ffmpeg)
- Opcode cache for faster page loads (php-apc)
- Interactive PHP debugging (php5-xdebug)
- PHP command line (php5-cli)
- KCacheGrind is a graphical tool to let you browse xdebug trace datafiles
- Mysql utilties (phpmyadmin, mysql-query-browser, mysql-admin):
Note: This installs php5 as an apache module - if you want to develop/test code using php 4 (no longer necessary in most cases) please read the PHP 4 Support page.
Configure Apache
Note: Replace USER with your Ubuntu username in the following code snippets.
Now that you have a basic LAMP install, you need to configure your setup. Following are a series of snippets to streamline the configuration process.
-
Enable apache modules:
sudo a2enmod vhost_alias rewrite
-
Configure apache webserver access to your workspace and a catch-all vhost by adding the following to /etc/apache2/httpd.conf:
Copy the following snippet into httpd.conf
# based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the Directory below, change USER to match YOUR USERNAME
# If you're unsure, Open the PLACES > HOME FOLDER menu. Nautilus will list your username in the Titlebar.
<Directory "/home/USER/workspace">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
NameVirtualHost *
ServerName localhost
If you can't save the httpd.conf, you should be editing it as a user with root permissions - i.e. something like
sudo vi /etc/apache2/httpd.conf
OR
gksudo gedit /etc/apache2/httpd.confIf you use phpmyadmin you can add the following line to this file import phpmyadmin's configuration file:
Include /etc/phpmyadmin/apache.conf
If you are concerned about Apache allowing the trace http method (which could be a security issue in some situations) you can also add the following line to this file:
TraceEnable Off
-
Configure automatic vhosts for non-multisite or non-Drupal sites.
Save the following as /etc/apache2/sites-available/localhost:
If you want, you can skip this part and just put each drupal install in a separate folder
on your web document root.
# Based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the VirtualDocumentRoot below, change USER to match YOUR USERNAME
#
# What this file does:
# Configure Apache so that when you browse the local URL http://DOMAIN.localhost/
# Apache will use the siteroot path /home/USER/workspace/DOMAIN/
# Remember to add your new DOMAIN.localhost domain to /etc/hosts for 127.0.0.1
<VirtualHost *>
ServerName localhost
ServerAlias localhost *.localhost
VirtualDocumentRoot /home/USER/workspace/%1/
</VirtualHost>
For Drupal sites using this setup will also require a change in the .htaccess file located in the root Drupal folder or Clean URLs will not work. Change the line# RewriteBase /
toRewriteBase /
to allow Clean URLs to function properly. -
Configure a vhost for each Drupal version by creating a file in /etc/apache2/sites-available as shown below and by updating the file /etc/hosts as mentioned in the code comments of Step 3 above.
Here's an example for Drupal 6:
Save the following as /etc/apache2/sites-available/6:
# Based on Drubuntu multisite config file from http://groups.drupal.org/node/6266
#
# IMPORTANT! READ ME!
# In the DocumentRoot below, change USER to match YOUR USERNAME
#
# What this file does:
# Configure Apache so that when you browse the local URL http://DOMAIN.{Drupal-version}/
# Apache will use the siteroot path /home/USER/workspace/{Drupal-version}/
# and Drupal multi-site will do the rest
# See http://groups.drupal.org/node/6268 for full details on how to add a new site.
<VirtualHost *>
ServerName 6
ServerAlias 6 *.6
DocumentRoot /home/USER/workspace/drupal-6/
</VirtualHost>Then edit the file /etc/hosts and add this line at the top:
127.0.0.1 drupal-6.localhost
If you get an error about permissions then be sure that you are editing the file with "sudo" or "gksudo" as in the httpd.conf examples above.IMPORTANT: Now,
- Repeat this step for other Drupal versions, saving a file for each vhost as 5, 47 and/or head, AND updating the /etc/hosts file for each as shown above.
-
Enable each vhosts site as needed (definitely the first three lines):
sudo a2dissite default
sudo a2ensite localhost 6 5 47 head - Configure PHP: In /etc/php5/apache2/php.ini search for the memory_limit parameter, and raise it's value to something like 64M.
Or use sed to do this:
sudo sed -i 's/memory_limit = 16M/memory_limit = 64M/' /etc/php5/apache2/php.ini
-
Restart Apache:
sudo /etc/init.d/apache2 restart
APT Pinning
If you are on Ubuntu 10.04 or higher you may want or need to run PHP 5.2 instead of 5.3. If this is the case and you plan on following the above instructions with no serious modifications then you will likely only need to do the following:
- Remove any previously installed PHP 5.3 packages:
dpkg -l | grep php
- Duplicate your existing sources.list replacing lucid with karmic and save it in sources.list.d
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/karmic.list
- Create a file in /etc/apt/preferences.d like this (call it for example /etc/apt/preferences.d/php):
sudo vi /etc/apt/preferences.d/php
OR
gksudo gedit /etc/apt/preferences.d/phpPaste the following in the new file:
Package: php5
Pin: release a=karmic
Pin-Priority: 991
Package: php5-common
Pin: release a=karmic
Pin-Priority: 991
Package: libapache2-mod-php5
Pin: release a=karmic
Pin-Priority: 991
Package: libapache2-mod-php5filter
Pin: release a=karmic
Pin-Priority: 991
Package: php5-cgi
Pin: release a=karmic
Pin-Priority: 991
Package: php5-mcrypt
Pin: release a=karmic
Pin-Priority: 991
Package: php5-mysql
Pin: release a=karmic
Pin-Priority: 991
Package: php5-gd
Pin: release a=karmic
Pin-Priority: 991
Package: php5-curl
Pin: release a=karmic
Pin-Priority: 991
Package: php5-imagick
Pin: release a=karmic
Pin-Priority: 991
Package: php5-ffmpeg
Pin: release a=karmic
Pin-Priority: 991
Package: php5-cli
Pin: release a=karmic
Pin-Priority: 991
* now you can continue with the normal installation instructions and you will end up with PHP 5.2 instead of 5.3.