easy-peasy-lemon-squeezy drupal installation on linux

installing drupal is pretty easy, but it's even easier if you have a step by step guide. i've written one that will produce a basic working configuration with drupal5 on debian etch with php5, mysql5 and apache2. it might be a help on other configurations too. see the scalability overview for related articles.

my examples assume that you are bold (or stupid) enough to do this as root. if you are a scaredy-cat or just plan sensible, make sure you use sudo. there. i said it.

this recipe assumes that you want to install everything on the same server. if you want to install your database on another server, skip the database install below and instead follow the instructions for a separate data server. i recommend just following the instructions below and then moving off the data server later, to keep things simple.

install the dependencies

i used php5, mysql5 and apache2. i don't know what you've got installed. here's a set of dependencies that worked for me:
ii  apache2.2-common       2.2.3-3.3     Next generation, scalable, extendable web se
ii  libapache2-mod-php5    4.4.4-8       server-side, HTML-embedded scripting languag
ii  libmysqlclient15off    5.0.32-3      mysql database client library
ii  mysql-client-5.0       5.0.32-3      mysql database client binaries
ii  mysql-common           5.0.32-3      mysql database common files (e.g. /etc/mysql
ii  mysql-server           5.0.32-3      mysql database server (meta package dependin
ii  mysql-server-5.0       5.0.32-3      mysql database server binaries
ii  php5-common            4.4.4-8       Common files for packages built from the php
ii  php5-mysql             4.4.4-8       MySQL module for php5

in addition, to get the graphics stuff working, you'll want to:

# apt-get install php5-gd

download and extract drupal

go to http://www.drupal.org and download the latest install e.g. http://ftp.drupal.org/files/projects/drupal-5.3.tar.gz. now cd to /var/www. and wget and untar it e.g.:

# wget http://ftp.drupal.org/files/projects/drupal-5.3.tar.gz
# tar xvfz drupal-5.3.tar.gz
# mv drupal-5.3 drupal

at this point you should have a directory called /var/www/drupal with lots of good stuff in it.

set the permissions to these files appropriately by:

# chown -R www-data.www-data /var/www/drupal

fancy footwork

i had to do the following to get my install to work. you might too. don't do this if you don't need to. edit /etc/php5/apache2/php.ini and uncomment the line extension=mysql.so

setup mysql

In my example, I created a database called drupaldb, a user called drupal and a password called password. you might want to too.

to create the db, as root do:

# mysqladmin -p create drupaldb
just hit return at the pwd prompt.

now setup permissions to the db. As root do:

# mysql
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE
TEMPORARY TABLES, LOCK TABLES
ON drupaldb.*
TO 'drupal'@'localhost'  IDENTIFIED BY 'password';

mysql>   FLUSH PRIVILEGES;

point drupal at your new database

editing the settings file /var/www/drupal/sites/default/settings.php, to point drupal at your new database:
$db_url = 'mysql://drupal:password@localhost/drupaldb';

finish the setup with the web tool

go to your browser and hit http://localhost/drupal, you will get redirected to http://localhost/drupal/install.php?profile=default, the install and db config page. follow the instructions. type in user=drupal, database=drupaldb, password=password. go on to create the initial (super admin) user and you are good to go.

creating a cron entry (optional)

you'll also want to add a cron entry (you'll need wget installed, apt-get install wget) like the following. it doesn't matter what user. you could put it in the root crontab (crontab -e as root):
45 * * * * /usr/bin/wget -O - -q http://localhost/drupal/cron.php > /dev/null 2>&1

hitting cron.php allows drupal to do it's housekeeping including keeping your site content-index up-to-date and trimming database logs.

enabling clean urls in apache (optional)

it's nice to enable drupal's clean urls. first, allow apache to access the .htaccess in the drupal directory. Add the following to your file in /etc/apache2/sites-available/ e.g. /etc/apache2/sites-available/default

<Directory /var/www/drupal>
   Options -Indexes FollowSymLinks MultiViews
   AllowOverride All
   Order allow,deny
   allow from all
</Directory>
now make sure that mod-rewrite is enabled:
# a2enmod rewrite

don't forget to reload/restart apache:

# /etc/init.d/apache2 force-reload

now go the URL http://localhost/drupal/?q=admin/settings/clean-urls, take the test (hopefully you'll pass) and, when you do, turn on clean urls.

memory limits (optional, but might save you some pain)

i had a problem with drupal administration (and some other) pages intermittently showing as completely blank. this is often a php memory issue. check your apache error log (/var/log/apache2/error.log) to know for sure. adding the line:

ini_set('memory_limit', '12M');

to the settings file /var/www/drupal/sites/default/settings.php will fix the issue. you might want to add more than 12M.

setting up an apache virtual host (optional)

it's nice to setup an apache virtual host for your drupal site. this allows you to create custom logging, remove the /drupal/ from your urls and nicely encapsulate the directives for drupal. here's how you can do it.

create a virtual host specification in /etc/apache2/sites-available called myserver.mydomain.com that looks something like this:

<VirtualHost *>
   ServerName myserver.mydomain.com
   DocumentRoot /var/www/drupal
        <Directory />
                Options -Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
</VirtualHost>
now go ahead and enable the new site:
# a2ensite myserver.mydomain.com
you'll probably want to disable the default site:
# a2dissite default
and then restart apache:
# /etc/init.d/apache2 restart

sounds like a lot of work?

if you can't be bothered doing all this configuration and you've got xen setup. ask me nicely and i'll send you a pre-configured xen machine with a this base install pre-configured. if you don't have a xen configuration, consider setting one up. i've got another quick and easy recipe for xen on linux.

scalability and redundancy

this recipe produces an installation that is neither scalable nor redundant. for information on solving this, see my scalability blog: scaling drupal - an open-source infrastructure for high-traffic drupal sites

tech blog

if you found this article useful, and you are interested in other articles on linux, drupal, scaling, performance and LAMP applications, consider subscribing to my technical blog.
Please note, this entry has been closed to new comments.