Build a Linux Webserver for Drupal in 8 Quick Steps

March 19, 2010

Recently I’ve had a cluster of projects that required setting up a large number of LAMP environments for Drupal on Rackspace Cloud Servers. Since these servers come with nothing, you have to install everything but the OS from scratch. This article describes how to do that in almost no time.

The examples below assume you’re running Ubuntu 9.10 (or 10.4) and are logged in as root.

0. Update

sudo apt-get update

sudo apt-get upgrade

Set the local time:

mv /etc/localtime /etc/localtime-old

ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

1. Install Apache 2

First, make sure your server knows its name by setting the correct server name in these two files:



Then install Apache:

sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert

If you’re going to need to install an SSL certificate, install openssl:

sudo apt-get install openssl

Then, make sure Apache knows the server’s name:

vi /etc/apache2/apache2.conf

and add this line:

ServerName <fully-qualified domain name>

2. Install the MySQL Server and Client

sudo apt-get install mysql-server mysql-client

During the installation process, you’ll be prompted to create a password for the root user.

3. Install PHP5 with MySQL, GD, ImageMagick, and Memcache support

sudo apt-get install libapache2-mod-php5 php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl php5-fpm php-apc

sudo apt-get install imagemagick

sudo apt-get install memcached

4. Install and Configure an FTP Daemon

apt-get install vsftpd

Next, upen vsftpd.conf (vi /etc/vsftpd.conf) and set the following configuration options:

  • anonymous_enable=NO
  • local_enable=YES
  • write_enable=YES
  • local_umask=022
  • chroot_local_user=NO

Restart the FTP daemon: /etc/init.d/vsftpd restart. (In some case I’ve noticed that changes in vsftpd.conf are not recognized until the server is rebooted.)

Finally, create a new user to use for FTPing:

adduser username (Follow prompts to enter a password and other information.)

5. Install sendmail, alpine and zip/unzip

sudo apt-get install sendmail

sudo apt-get install alpine

While you’re at it, install zip/upzip, which you’ll probably need at some point:

sudo apt-get install zip

6. Enable mod_rewrite for Clean (SEO-friendly) URLs

First, enable Apache’s mod_rewrite module. To do this, create a link to rewrite.load in /etc/apache2/mods-enabled:

ln -s -T /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

Lastly, open /etc/apache2/sites-enabled/000-default and look for

<Directory /var/www/>

Make these changes:

  • Change Options Indexes FollowSymLinks MultiViews
    to Options Indexes FollowSymLinks (remove ‘MultiViews’)
  • Change AllowOverride None
    to AllowOverride All
  • Add the following lines:
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

If you want to password-protect* the site using HTTP Basic Auth, then add these directives:

AuthUserFile /etc/htpass/.htpasswd
AuthGroupFile /dev/null
AuthName "Enter Password"
AuthType Basic
require user drupaluser

Then, create the .htpass file:

mkdir /etc/htpass
cd /etc/htpass
htpasswd -c .htpasswd <username>

Follow the prompts to set the password for this user.

7. Restart Apache

/etc/init.d/apache2 restart

Confirm that Apache is loading the rewrite module:

apache2ctl -M

The module rewrite_module should be included in the list.

8. Install Drupal with the Zen theme and the CCK, FileField and Views modules

8.1 Create a database for Drupal to use:

mysql -u username -ppassword -e "create database database_name"

8.2 Install Drupal and set up directories:

cd /var/www
gunzip drupal-6.19.tar.gz
tar -xvf drupal-6.19.tar
rm drupal-6.19.tar
mv drupal-6.19/* ./
rm -R drupal-6.19
cp /var/www/sites/default/default.settings.php /var/www/sites/default/settings.php
chmod -R 0777 /var/www/sites/default
cd /var/www/sites/all
mkdir modules
mkdir themes

Get the Zen base theme:

cd /var/www/sites/all/themes
gunzip zen-6.x-1.1.tar.gz
tar -xvf zen-6.x-1.1.tar
rm zen-6.x-1.1.tar

Install modules:

These will vary according to your requirements. These are the ones I include by default.

cd /var/www/sites/all/modules

gunzip cck-6.x-2.6.tar.gz
tar -xvf cck-6.x-2.6.tar
rm cck-6.x-2.6.tar

gunzip filefield-6.x-3.3.tar.gz
tar -xvf filefield-6.x-3.3.tar
rm filefield-6.x-3.3.tar

gunzip views-6.x-2.10.tar.gz
tar -xvf views-6.x-2.10.tar
rm views-6.x-2.10.tar

gunzip advanced_help-6.x-1.2.tar.gz
tar -xvf advanced_help-6.x-1.2.tar
rm advanced_help-6.x-1.2.tar

gunzip xmlsitemap-6.x-2.0-beta1.tar.gz
tar -xvf xmlsitemap-6.x-2.0-beta1.tar
rm xmlsitemap-6.x-2.0-beta1.tar

That’s All!

Open your site in a broswer and follow Drupal’s straightforward setup instructions.


Comments are closed.

Spawn PHP Framework

Learn all about installing and working with this easy-to-use MVC framework.

Continue reading »

Coming Soon: Scaveng

Scaveng is a scriptable web scraper. Stay tuned for more.