Aug 032011

Almost a year ago, we got very excited after looking into Drupal. Back then, version 7 of this Content Management Framework (CMF) was not yet available.

Today it is. And although not all modules are available for the new core, version 7 looks even better than its predecessor.

In this article we describe the complete installation of a multi-site Drupal system.

Download and Requirements

Installing Drupal requires some preparations, mostly the configuration of its operating environment and the setup of a directory tree.

We start by downloading the latest version from the Drupal website:

What you need for Drupal to run on is a basic LAMP or WAMP server (Linux/Windows, Apache, MySQL, and PHP).

Over here, we deploy Fedora en CentOS 5 systems. Installation and configuration of the standard packages did not give us any problems during the install.


First, check the PHP configuration on your system:


Make sure that the memory_limit is not too low. A production site including a dozen or more modules requires at least 128 Mbyte. For this installation we set the limit to 256 Mbyte.

Other settings in this file you should check:

register_globals = Off
error_reporting = E_ALL & ~E_NOTICE
safe_mode = Off
session.cache_limiter = nocache
max_execution_time = 60

Here is a list of the PHP extensions Drupal (and/or its modules) relies upon:

  • mysql/mysqli,
  • gd, imagemagic,
  • xml,
  • and specifically for version 7: hash, json, and pdo.

Use phpinfo() to find out which PHP extensions are installed and enabled.

Next to the file /etc/php.ini, you can find additional, module-specific configuration files in the directory /etc/php.d/.

MySQL Database

Now create a (MySQL) database for your Drupal system. We call the database drupal. And we have created a separate database user for it, also with the name drupal.

mysql -u root -p
ON drupal.* TO "drupal"@"localhost" IDENTIFIED BY "<user_password>";

If you do not yet have your MySQL database configured, you have to create the system tables first:

mysqladmin -u root password '<root_password>'
mysqladmin -u root -p -h localhost password '<root_password>'

On a production system, you would use the command mysql_secure_installation instead of mysql_install_db.

Software Installation

Since we want to build a flexible multi-site Drupal installation, we created a slightly more complex directory structure than would be strictly necessary.

In the web directory /var/www/ we first created a drupal subdirectory to hold "all" our Drupal sites. Here, we use a new user (drupal, who else) that will own the Drupal tree:

mkdir /var/www/drupal/
chmod 755 /var/www/drupal/
chown drupal:drupal /var/www/drupal/

Now we unzip the Drupal package file in the newly created directory:

cd /var/www/drupal/
tar -zxvf .../drupal-xxx.tar.gz

This leaves us with the directory drupal-xxx/, in our case drupal-7.7/. By creating a softlink to this version-specific directory, we make our setup version-independent and at the same time allow for parallel installations next to our current software tree.

ln -s drupal-xxx drupal7
ln -s drupal7 drupal

For people wondering about this plethora of symlinks: it is a typical Unix way of organizing things.

Apache Modsecurity Configuration

Now we have to tell the Apache security module that the new directory structure can be accessed for writing by the http server.

So we add to the file /etc/httpd/modsecurity.d/modsecurity_localrules.conf:

 SecDataDir /var/www/drupal/

This statement specifies that the /var/www/drupal/ directory will be used by the web server to write persistent data to.

Drupal Apache Configuration

Drupal comes with its own "hidden" Apache configuration file:


You should check the contents of this file.

We uncommented these two lines to redirect all visitors to the domain:

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

Since we are using a subdirectory of our http base directory for this installation, we set:

RewriteBase /drupal/drupal

And of course, we have to make sure that our Apache configuration does not forbid the use of (ignore) directory overrides (in the Apache or virtual host configuration):

AllowOverride All

Multi-Site Configuration

Drupal supports the serving of several sites from a single installation. Each site should (not strictly necessary but preferably) have its own database. Extensions and themes can be shared by placing them in the drupal/sites/all/ directory structure. Site-specific modules, themes and data are placed in subdirectories bearing the domain name.

Since we are creating a multi-site installation, we leave the drupal/sites/default/ directory alone. We just use a copy of the configuration file that is there for our own purposes.

cd drupal/sites/
cp default/default.settings.php
chmod 644
setfacl -m u:apache:rw-

The last command is to (temporary) open up the configuration file for writing by the web server. That way the final part of the configuration can be performed using the web interface.

We do the same for the base site directory, so the Drupal installer can create new subdirectories (i.e. files/) here

setfacl -m u:apache:rwx

For each domain we want to serve from this Drupal installation, we create the appropriately named subdirectory next to the default/ directory in /var/www/drupal/drupal/sites/.

Note that there is no need to create a separate directory for the domain. However, if you want to create a (different) subdomain for another website, simply use a directory name like this:

Beware that since Drupal uses the directory names internally (i.e. in the database), you cannot change the directory name of a particular site after the installation has been completed. If you later on decide to move the site to another domain or make it available on an additional domain, you simply create a symlink for the new domain:

cd drupal/sites/
ln -s

Test Systems

If you are currently building a local installation for testing and evaluation purposes, you can create several localhost sites, naming these for example localhost, test1.localhost, test2.localhost, etc. These sites can then be made directly accessable from your browser by adding their host names to your /etc/hosts file:

# Drupal hosts    test1.localhost    test2.localhost

Now edit or create the Apache configuration file /etc/httpd/conf.d/drupal.conf:

# Drupal is an open-source content-management platform.

Alias /drupal /var/www/drupal

<Directory /var/www/drupal/>
  Order Deny,Allow
  #Comment the following line and uncomment the next for public use
  Deny from all
  #Allow from all
  #Uncomment the following line for setup
  Allow from
  AllowOverride All
  #Uncomment the next line if using with SSL/TLS
  #php_flag session.cookie_secure on

This configuration is based on the drupal.conf file that comes with the Fedora Drupal package. It installs a basic Drupal system in the directory /usr/share/drupal/ and the site-specific files in /etc/drupal/.

Note that this configuration leaves the directory structure in the URL necessary to access our Drupal system as is, i.e. This allows us to deploy other versions and configurations of Drupal, or even completely different CMSes, next to this Drupal install without having to reconfigure the directory structure. For a production system, you would make the underlying directory structure completely invisible, for that might result in better search engine performance (SEO).

Apache Virtual Hosts

Although you could do without, on a production system, requiring more site-specific configurations, the use of virtual hosts would be highly recommended.

<VirtualHost *:80>
  DocumentRoot /var/www/drupal
<VirtualHost *:80>
  DocumentRoot /var/www/drupal

After changing its configuration files, don’t forget to restart the Apache web server:

/etc/init.d/httpd restart

Drupal Configuration

Now we are ready to open the Drupal installer in our web browser:

Here we first select the Standard profile, and then the language.

In the next screen we enter the access information for the MySQL database we created before.

You need to adjust the Advanced Options only if you are using a database on another system or on a non-standard port. You can even share the database with other applications or other Drupal installations by setting a database table prefix.

Now, all the necessary information is created in the configuration files and the database.

As you can see, Drupal installed without any difficulties.

Now we set the site’s name and an email address, and we create an account for the administrator (that being us :-)

Since we are building an international site in the English language, we leave the Default country set to None. And we select Amsterdam (where we are based) as our Default time zone.

That’s it!

Now we can move on to our home page, to work on the functionality and content of our freshly installed Drupal site.

Securing Your Installation

That is: almost. Since Drupal stores all information in the database, there is no need to keep the configuration file and directory accessible for writing.

As you can see, if you go to the Administration screens, Drupal will complain about this.

So here is what we do:

setfacl -m u:apache:r--
setfacl -m u:apache:r-x

Loose Ends

Finally, there are some loose ends we have to take care off.

Drupal requires an administrative script to be run every now and then. You can have it done "automatically" as part of the processing for users visiting your website. But that might negatively impact the performance of an occasional page request. So a far better way is to install a cron job for this task:

crontab -e
# Drupal cron jobs
50 * * * * lynx -source

This runs the cron job every hour at x:50. Note that this does not imply that the Drupal tasks are performed every hour. The Run cron every setting at Configuration -> System -> Cron determines how often the periodical tasks are actually run. For this to work, just make sure that the granularity of your Drupal cron job is at least as fine as this setting.

You can find the (secured) link for your own cron job in the Administrator’s interface when clicking Reports -> Status report.

If you don’t want to install a cron job for each site, there are solutions (i.e. scripts) available that will run the administrative script of each site for you.

Finally, the new (but empty) website can be accessed through:


That was all there is to it. If you made it this far without any problems, you currently are the proud owner of a clean basic installation of Drupal.

The next step will be to configure the site, extend the functionality (modules), the layout and decoration (themes), the users, and the content. Furtunately, you can use the intuitive web interface for almost all of these tasks.

Finally, documentation for further tasks can be found here:

  3 Responses to “Installing Drupal Version 7 on Linux/Apache/MySQL/PHP”

  1. […] Building Professional Portals Skip to content HomeAboutContact ← Installing Drupal Version 7 on Linux/Apache/MySQL/PHP […]

  2. […] leaves us with a directory containing the following subdirectories and symbolic […]

Leave a Reply