Installing Drupal

This section will walk you through the steps of installing Drupal, including evaluating the requirements, downloading the correct files, creating the database, and importing the database definition. Here is an overview of the steps:

1. Get the Drupal download from

2. Create a database for your Drupal site. Supported database management systems are MySQL, MySQLi, and PostgreSQL.

3. Import the database definition from the database/database.xxsql file that comes with the Drupal download.

4. Move the Drupal files to the web server.

5. Adjust the values for $db_url and $base_url in the appropriate settings.php file.

6. Access your Drupal site with the value given for $base_url.

I'll explain each of these steps in detail in the following sections. But before you can install Drupal, you need to make sure that your system meets its requirements.

Meeting Drupal Requirements

The most common configuration for running Drupal is on an Apache web server with PHP 4 and a MySQL database. Drupal can run on other web servers, with other versions of PHP (PHP 5), and with other databases, but the Apache/PHP/MySQL combination is still the most tested and trustworthy. Here are the specific requirements.

Web Server

You need a web server that can execute PHP scripts. The Apache server is the overwhelming first choice for most of the people currently running Drupal. Drupal's core distribution is always tested with the latest 1.3.x version of Apache, but Drupal is known to work with the 2.0.x versions as well. Less common, but also supported, is the use of the Microsoft Internet Information Services (IIS) server. (For more information about running Drupal with the Windows IIS server, see and

Drupal requires the 4.3.3 or greater version of PHP Drupal is PHP 5-compatible. PHP Extensions

When configuring PHP or choosing hosting, you need to make sure that the following PHP extensions are available:

• The PHP extension for the database you wish to use (MySQL, MySQLi, or PostgreSQL) is required.

• The PHP XML extension. It is enabled by default in a standard PHP installation. The Windows version of PHP has built-in support for this extension.

• The PHP mbstring extension is required to support Drupal in handling text in the UTF-8 character encoding format (Unicode).

• In order for Drupal to be able to manipulate images (such as for making thumbnails), you need to have a PHP extension to support it. You can use either the GD library (included with PHP or ImageMagick (

PHP Directives

Drupal requires PHP to be configured with the following specific directives in order to function correctly:

• session.save_handler: user

• session.cache_limiter: none

• memory_limit: 24M (recommended)

The 24M memory limit is the upper limit of what will ever be used; the average usage is much lower. However, PHP's default limit of 8M is too low for some Drupal operations and will cause problems.

You can configure these directives directly in the php.ini file, or if you are using an Apache web server, through the .htaccess file (included with the Drupal installation). Setting the directives using an .htaccess file also requires that the Apache web server be configured to allow this (see the AllowOverride directive for Apache at ATusing-htaccess.html). PHP will also need to be installed as an Apache module for .htaccess support.

Database Server

Drupal requires a SQL database server that is supported by PHI! The recommended server is MySQL, version 3.23.17 or later, including MySQL 4.x. Drupal now supports the PHP MySQLi extension (, as well.

PostgreSQL 7.4 and higher is officially supported and maintained for the core Drupal installation. The level of support that is given to PostgreSQL among the contributed modules is less consistent. If you choose to run Drupal on PostgreSQL, you may find yourself in the position of tweaking the SQL scripts used to create database schemas for contributed modules in order to make them compatible with your database server.

Mail Server

Many of Drupal's features, including user registration, depend on the server's ability to send email. Your web server needs to have a mail server available for these functions to work. Drupal uses PHP's mail() function to send e-mail (see These two php.ini directives are needed to support mail:

SMTP = localhost smtp_port = 25

Fortunately, this is par for the course for professional LAMP (Linux, Apache, MySQL, and PHP) hosting services, and you will rarely need to worry about this when installing Drupal.

Obtaining Drupal

You can download the latest Drupal releases from Place the files in the download package somewhere in the document root of the web server. They can be either at the top level or in a subdirectory. If you are running other web applications on the same server in the same document root, putting Drupal in a subdirectory is the better choice.

For GNU/Linux users, the quickest way to get Drupal onto your server is to open a shell and use the wget tool to download the Drupal archive directly from You can then unpack the archive using the tar command:

wget tar -zxvf drupal-x.x.x.tar.gz

Alternatively, use a File Transfer Protocol (FTP) or Secure Copy Protocol (SCP) client to move the archive from your local machine to the web server and unpack it into the web directory.

Setting Up the Database

Drupal does not create the database for you. For this, you will need to become familiar with the tools provided by the database management system that you have chosen to use. For MySQL, the PHP-based web application phpMyAdmin ( is popular. For PostgreSQL, phpPgAdmin ( is a common choice. Both are often included as standard fare by web hosting companies selling hosting packages.

Note All of the examples for working with the database server in this chapter are MySQL-specific.

No matter which database manager you choose, you need to take the following steps to prepare the database for use by Drupal.

Create the database: It is not particularly important what you name the database. It is important that you know what the name is. Some hosts will prefix the name you provide. Similarly, some web hosts will truncate the name to fit into a certain number of characters. So, make sure to double-check what the database is actually called, because you will need to know this when you're configuring Drupal.

Create the database user and assign rights: Access to any database is granted on a databaseuser basis. Do not use the root user or the database admin user to access your database, as this presents a security risk. Instead, you need to create a user who has permissions to access the Drupal database. This can usually be done with the same tools that you used to create the database. Create the user account and grant it SELECT, INSERT, UPDATE, DELETE, CREATE, and LOCK TABLES privileges. If you're using a command-line tool, don't forget to use FLUSH PRIVILEGES as well.

Import the schema: Once the database is created and a user is assigned, with the appropriate privileges, it is time to import the schema for the core Drupal database. The SQL instructions to do this are found in the database/database.mysql and database.pgsql files that come with your Drupal distribution. In order to import the schema, execute the instructions in the file appropriate to your database. There are command-line methods for doing this, and the database management tools mentioned earlier can help you do this as well.

As an example, let's go through the GNU/Linux command-line versions of these steps for a MySQL database. First, create the database:

$ mysqladmin -u db_user -p create db_name db_user is an existing MySQL user who has the rights to create databases. This will often be root. The db_name is the name of the database you wish to create.

You also need a database user who is allowed to connect to the database you just created. This might be the db_user from the previous command, in which case you can skip this step. Otherwise, to create a new database user, connect to the MySQL server as root and use GRANT to create a new user:

$ mysql -u root -p mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,LOCK TABLES^ ON db_name.* TO 'db_user'@'localhost' IDENTIFIED BY 'password';

db_name is the database name, db_user is the name this new user will have, and password is the password that will be used when making a database connection. This example assumes that the user will be accessing the database only from the current machine, or localhost. Replace localhost with the appropriate domain or IP address if the connection will be made to a different machine.

Finally, import the database schema from the database/database.mysql file that came with the Drupal distribution:

$ mysql -u db_user -p db_name < database/database.mysql

Setting the Database and Base URLs

Now you must edit the sites/default/settings.php file that is part of the Drupal installation you downloaded from You must give values to the database URL ($db_url) and the base URL ($base_url) variables. The database URL is the single most important configuration setting that you are asked to make while installing Drupal. You need four pieces of information to do it correctly:

• The database management system you are using; MySQL, MySQLi, or PostgreSQL

• The name of the database

• The name of the database user

• The database user's password

Once you have these four pieces of information, you can begin to set the database URL. Find the section in settings.php where the database URL is set:

* Database URL format:

* $db_url = 'mysql://username:[email protected]/database';

* $db_url = 'mysqli://username:[email protected]/database';

* $db_url = 'pgsql://username:[email protected]/database';

$db_url = 'mysql://username:[email protected]/database'j

Pick the variant that applies to your database. By default, MySQL is given as the suggested example, and all the supported systems are given as examples in the comments. Next, replace username in the URL with the name of the database user, replace password with the database user's password, and replace database with the name of your database. In some cases, if the web server and the database server are running on different machines or have different domains or IP addresses, you will need to replace localhost with the name of the host on which the database is running.

With the database URL set, the second task in settings.php is to set the $base_url variable. The $base_url variable is used to make all of the relative paths on your Drupal site into absolute URLs. As such, it is essential for the site to work. The $base_url variable is composed of the domain of your site ( plus the path to the subdirectory where you installed Drupal, (/sub/directory). Here is the section of settings.php where $base_url is set:

* The URL of your website's main page. It is not allowed to have

* a trailing slash; Drupal will add it for you.

The following are some examples of valid $base_url settings:

$base_url = ''; $base_url = '';

These examples are fine if you installed Drupal directly at the top of the document root. If you installed Drupal in a subdirectory, the $base_url setting will look like this:

$base_url= '';

Never add a forward slash at the end. These $base_url values are wrong:

$base_url = ''; // Wrong!

$base_url = ''; // Wrong!

Accessing the Drupal Site

To access the Drupal site, open your browser and navigate to the value that you set for the $base_url. If you've done everything correctly, you'll see the screen shown in Figure 1-1.


Welcome to your new Drupal-powered website. This message will guide you through your first steps with Drupalj and will disappear once you have posted your first piece of content.


Welcome to your new Drupal-powered website. This message will guide you through your first steps with Drupalj and will disappear once you have posted your first piece of content.

User login

The first thing you will need to do is create the first account. This account will have full administration rights and will allow you to configure your website. Once logged in, you can visit the administration section and set up your site's configuration.


Drupal comes with various modules, each of which contains a specific piece of functionality. You should visit the module list and enable those modules which suit your website's needs.


Themes handle the presentation of your website. You can use one of the existing themes, modify them or create your own from scratch.

Log in

We suggest you look around the administration section and explore the various options Drupal offers you. For more Information, you can refer to the Drupal handbooks online.

* Create new account

• Request new password

Figure 1-1. Drupal, freshly installed

Troubleshooting Installation Problems

The most common problems that people have when installing Drupal include not being able to connect to the database server and an incorrect base URL.

Unable to Connect to the Database Server

If you see the message shown in Figure 1-2, you need to review your database configuration and the value that you entered for the database URL. As the message indicates, Drupal is not able to connect to the database server.

Here is a list of things to check to solve this problem:

• Is the database server running?

• Did you create a database for your Drupal site?

• Did you create a database user for the Drupal database?

• Are the username, password, and database name correctly entered for the $db_url variable in the settings.php file?

• If the database server is running on a server other than localhost, is the host entered correctly in the $db_url variable in settings.php?

• Are you using the correct database connection type for your database server? MySQL should use mysql://, MySQLi should use mysqli://, and PostgreSQL should use pgsql://.

Unable to connect to database server

This either means that the usemame and password information in your settings. php file is incorrect or we can't contact the MySQL database server. This could mean your hosting provider's database server is down.

The MySQL error was: Access denied for user 'xxxx'@'Iocaikost' (using password: YES).

Currently, the usemame is xxxx and the database server is localhost.

* Are you sure you have the correct usemame and password?

* Are you sure that you have typed the correct hostname?

* Are you sure that the database server is running?

For more help, see the Installation and upgrading handbook. If you are unsure what these terms mean you should probably contact your hosting provider.

Figure 1-2. Drupal cannot connect to your database server.

An alternate cause of Drupal not being able to connect to the database is that the version of PHP being used doesn't have the requisite database extension activated. PHP needs special libraries to connect to different database servers from different vendors. To diagnose whether this is preventing the database connection from being made, consult the details of a phpinfo(); page and look for the section corresponding to your database.

Tip phpinfo() is a PHP function that "Outputs lots of PHP information" ( It is very useful for assessing whether PHP is installed correctly and whether the appropriate directives and settings to support Drupal are in place. To execute phpinfo(), place a file in your document root named phpinfo.php with the following line: <?php phpinfo(); ?>. Request the file from the server with your browser to see the information.

Incorrect $base_url

If your site appears as shown in Figure 1-3, without the Drupal icon and the pretty shades of blue, and if all of the links lead to Page Not Found errors, the culprit is likely the $base_url variable in settings.php. Correct that setting, and your site should work.

edit secondary links P^j | :il primary links admin

Welcome to your new Drapal-powered website. This message will guide you through your first steps with Drapai, and will disappear once you haye posted your first piece of content.

The first thing you will need to do is create the first account. This account will haye full administration rights and will allow you to configure your website. Once logged in, you can yisit the administration section and set up your site's configuration.

create content

Drapai comes with yarious modules, each of which contains a specific piece of functionality. You should yisit my account the module list and enable those modules which suit your website's needs. administer log out Themes handle the presentation of your website. You can use one of the existing themes, modify them or create your own from scratch.

We suggest you look around the administration section and explore the yarious options Drapai offers you. For more information, you can refer to the Drapai handbooks online.

Figure 1-3. Setting the $base_url incorrectly results in this display.

Creating the First User

The very first step once you arrive intact at the initial screen is to make the administer (admin) user. The admin user is the user whose ID number is 1, and who has "superuser" rights to administer the entire site.

■ Note Creating the first Drupal user is a critical step in the installation. The first user has superuser privileges and is the account that will be used to configure and administer the site. Make sure to complete this step immediately, and keep track of the username and password details.

To create the admin user, click the create first account link. You will be asked for the username and e-mail address of this user. When you provide this information and click Submit, Drupal will attempt to send a message to the e-mail address you provided. The e-mail will contain the randomly generated password for your admin user account. This password will also be displayed on the screen. Write down (or copy) this password, in case something goes wrong in the following steps (if you close your browser at an untimely moment, for example).

Drupal will also display a button that says Log in. Click this button now to log in as the administrator. You will be taken to the admin user's details page, where you can set some user preferences for the account. The important step you should take now is to change your password. Then you can ignore the e-mail that Drupal sent to you with the random password.

■ Note If you are setting up a site on your local Windows machine, it is likely that an error will be displayed at the point when Drupal tried to send an e-mail to the administrator's account. The error results from the fact that PHP isn't able to find an installed and configured mail server on your machine. This will be the common experience for people who are installing Drupal on their local machine running Windows, since it is somewhat unusual to run mail servers on your workstation.

Creating the files Directory

Drupal needs a place to store uploaded files. These files range from user pictures, to files attached to postings, to images and music files. These are all typically stored in a folder in the root Drupal installation called files and a subdirectory therein called pictures. If these directories don't exist, Drupal will create them for you. If you are installing Drupal on Windows, all is fine, and you can skip this section.

If you are installing Drupal on a flavor of *nix (a UNIX or Linux system), you will want to take an extra moment now to create the directories manually. The reason for this is that the files directory is the one place where web site users will be able to interact directly with the file system on your server; this is where their uploaded files will be stored. You therefore want to pay special attention to the permissions of this directory. Letting Drupal create the directory for you may not result in the best configuration, and may not even be possible, depending on how your system is configured.

The first step to creating the files directory with the optimal permissions is to determine the username of the web server process. To find out what user the Apache web server is running as, look in the httpd.conf file, which is responsible for the Apache configuration. There you will find an entry like this (from Debian 3.1):

User www-data

The actual name of the user depends on the operating system and distribution. Other common names for the user include wwwrun, www, apache, and wwwuser.

■ Note Some Apache servers run using suPHP (, and others are run as a CGI module. In both of these cases, the name of the process running the web server will be different. If you are unsure, contact your hosting service.

Once you know the username of the web server, you can create the files directory:

$ mkdir files $ mkdir files/pictures

Change the permissions so that the user is the web server and the group is a user group to which any of the developers working on your site will belong. I'll call the web server www-data and the users' group developers:

Finally, make sure that these directories have the proper permissions: $chmod -R 755 files

Using Other Installation Methods

It isn't always necessary to install Drupal by hand. Depending on your hosting company, the operating system of your server, and the Drupal distribution that you have chosen, many tools are available to aid in the installation process or eliminate it altogether.


An alternative to installing Drupal completely manually is to download and use CivicSpace (available from CivicSpace Labs, at CivicSpace is a distribution of Drupal that packs many useful modules together and helps you to install and configure them. Almost everything distributed with CivicSpace can be found at, so the information in this book applies to CivicSpace as well as Drupal.

The CivicSpace installation script takes care of some of the initial user creation, database connection, and configuration tasks, as shown in Figure 1-4. You will still need to manually create the database and database user, as well as assign the user rights.


CivicSpace Installer i. Server check-up 2. Install 3_ Database Setup 4- Finishing up

5. Configure your site

IMPORTANT: As a precaution you may want to clear your browser's cookies before submitting this form. In certain server/browser environments, you may get a session management error if you don't clear your cookies at this point. CivicSpace Database settings User name:

Tip: Allowed characters include letters, digits, and '-' with a maximum of 16 characters.


Tip: Allowed characters include letters, digits, and any of the following:

Host: localhost

Tip: If your database is on the same machine as your CivicSpace installation, just enter "localhost". Leaving this item blank will default the value to "localhost".

Figure 1-4. The CivicSpace installer

Fantastico and Debian

Two options for completely automated installations of Drupal include Fantastico (offered by many web hosts) and the Debian operating system. Fantastico is a set of scripts to install web applications (such as Drupal) on a server, and Debian is a GNU/Linux distribution that allows you to install Drupal using the apt-get tool, which installs and updates Debian packages. If you're using one of these tools, make sure to check that they are installing the latest stable version of Drupal, or you risk missing out on features and security measures.

Managed Drupal Services

If you don't want to mess with the hosting and installation aspects of Drupal, Bryght (http:// is a company that offers turnkey managed Drupal hosting. You sign up for this service and get access to a completely installed Drupal site. The service takes responsibility for upgrades, compatibility of modules, security issues, and stability of the servers, leaving you with the task of creating your online community using Drupal. You can even use your account as a reseller platform, selling further Drupal installations to your clients.

Was this article helpful?

0 0

Post a comment