How to setup Drupal development server from Ubuntu 9.04 server

Even in the Ubuntu Server 9.04 there is a nice LAMP option with Apache, PHP and MySQL, some more steps are necessary to turn Ubuntu Server 9.04 into a real Drupal development environment. After these steps, you will have a development server, where all Drupal versions, unlimited number of domains and development projects can be set up. Use this tutorial to get a more sophisticated Drupal development environment. And don't forget, there is a simple way in Ubuntu 9.04 for Drupal 6: sudo apt-get install drupal6

This howto starts just after the Ubuntu Server 9.04 install with LAMP and OpenSSH options finishes.

  1. Update and upgrade
  2. sudo apt-get update
    sudo apt-get upgrade

    Just to have the latest state from Ubuntu 9.04

  3. Fix IP address
  4. sudo nano /etc/network/interfaces
    Change this line
    iface eth0 inet dhcp

    like these lines, but the IP address and other parameters should differ in you case!
    iface eth0 inet static
    address 192.168.2.23
    netmask 255.255.255.0
    gateway 192.168.2.1

    Then restart the network:
    sudo /etc/init.d/networking restart

  5. Increase PHP memory
  6. The default memory limit in PHP is 16 MB, which is to low for Drupal if we are going to use some modules, as well. So increase this memory to 64 MB with this:
    sudo sed -i 's/memory_limit = 16M/memory_limit = 64M/' /etc/php5/apache2/php.ini

  7. Install the GD library for image processing

  8. sudo apt-get install php5-gd
    sudo /etc/init.d/apache2 restart

  9. Apache configurations
  10. We need Apache with virtual host setting, in order to enable multiple domain developments. Enable Apache two modules:

    sudo a2enmod vhost_alias
    sudo a2enmod rewrite

    Add some lines to /etc/apache2/httpd.conf

    NameVirtualHost *
    ServerName localhost

    Configure a virtual host for each Drupal version (Drupal 6 example below). Open a file:

    sudo nano /etc/apache2/sites-available/d6

    and copy these line into. Change the DocumentRoot and Directory setting as your configuration requires.

    # 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 *:80>
    ServerAdmin webmaster@localhost
    ServerName d6
    ServerAlias d6 *.d6

    DocumentRoot /home/USER/workspace/drupal6
    <Directory /home/USER/workspace/drupal6/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined

    </VirtualHost>

    Enable now these settings.

    sudo a2ensite d6
    sudo a2dissite default

    With these settings you can develop any domains called http://MYDOMAIN.d6.

    Don't forget to put a line into your /etc/hosts files pointing to this domain name to the IP address of your development server. You should do this in your clients, and in the /etc/hosts file of this server, as well.

    192.168.2.23 wepoca.d6

  11. Preparation for Drupal
  12. Before first test, create the workspace and add the Apache user to the group of the user.

    cd ~
    mkdir workspace
    sudo adduser www-data USER

    Now download, un-tar and prepare a fresh Drupal. These steps might differ in each development project, we just do here a quick test.

    cd ~/workspace
    wget http://ftp.drupal.org/files/projects/drupal-6.11.tar.gz
    tar xf drupal-6.11.tar.gz
    ln -s drupal-6.11 drupal6
    rm drupal-6.11.tar.gz
    mkdir -p drupal6/sites/wepoca.d6
    cp drupal6/sites/default/default.settings.php drupal6/sites/wepoca.d6/settings.php
    chmod 775 drupal6/sites/wepoca.d6
    chmod 664 drupal6/sites/wepoca.d6/settings.php

  13. MySQL configs for Drupal
  14. We need a MySQL user for Drupal. Its user-name and password will be asked if you install Drupal.
    This user can be added to MySQL, but don't forget to change the user-name (DRUPAL-USER-IN-MYSQL) and the password (DRUPAL-USER-PASSWORD-IN-MYSQL). You will need the root password for MySQL, as set up during the LAMP server install:

    mysql -uroot -pROOTPWD -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON *.* TO 'DRUPAL-USER-IN-MYSQL'@'localhost' IDENTIFIED BY 'DRUPAL-USER-PASSWORD-IN-MYSQL'"
    mysql -uroot -pROOTPWD -e "FLUSH PRIVILEGES"

    Databases for Drupal instances can be created as well, but use your database name instead of DRUPAL-DATABASE:

    mysql -uDRUPAL-USER-IN-MYSQL -pDRUPAL-USER-PASSWORD-IN-MYSQLD -e "CREATE DATABASE DRUPAL-DATABASE CHARACTER SET 'utf8'"

  15. Restart Apache and clean up

  16. sudo /etc/init.d/apache2 restart

    After the site has been configured, don't forget to restrict the access right to config files:

    cd ~/workspace
    chmod 755 drupal6/sites/wepoca.d6
    chmod 644 drupal6/sites/wepoca.d6/settings.php

  17. Optional: Install phpMyAdmin
  18. To have phpMyAdmin, type:

    sudo apt-get install phpmyadmin

    You can use phpMyAdmin with the database user set up for Drupal.