Installing Drupal

WHAT YOU WILL LEARN IN THIS CHAPTER:

> Installing a Drupal website

> Installing Drupal using the Acquia Distribution

> Exploring the files, folders and structure of Drupal

> Reviewing the sites folder

> Exploring inheritance and overrides

> Overriding Drupal's default theme with one of your own

Now that you have decided to use Drupal the next step is to download and install it. In fact you might have already installed one or more Drupal websites. Even if you have already installed Drupal, a quick read through this chapter will help to clarify the process and help you better understand Drupal.

This chapter reviews the installation process of a single Drupal website. You will explore the files and folders of Drupal to better understand its structure and to learn what you can and cannot modify. You'll explore Drupal's system of inheritance and overrides and learn how to install Drupal in a language other than English.

After completing this chapter you can continue on in the book or skip over to Chapter 18, which covers advanced Drupal installations. Chapter 18 covers installing multiple websites with a single download of Drupal, sharing users between multiple Drupal websites, explores the settings.php file, and how to use CVS to simplify updates to your Drupal website.

GETTING STARTED WITH DRUPAL

The first step to getting started with Drupal is to make sure that you meet all of the requirements. Drupal 7 requires the following:

^ Database server: MySQL 4.1+ or Postgres 7.4+

^ PHP memory limit that is higher than 16MB (recommended 32MB)

NOTE Please visit http://drupal.org/requirements for more details on Drupal's requirements.

If you are using a web host that advertises compatibility with Drupal, most of these are likely already set up. Be aware however that many hosts use PHP 4 by default and not PHP 5. Often a quick call to their support line is all that is needed to get them to switch your account over to PHP 5.

To use Drupal locally on your computer you will need to install these items separately. I highly recommend the XAMPP software for Windows (http://apachefriends.org) or the Mac OS X equivalent, MAMP (http://mamp.info). These free software packages provide everything you need in a single download. This chapter and the remainder of the book will assume that you are using XAMPP or MAMP for your Drupal website. The chapters and exercises will work the same if you choose to use a web host instead.

Another option that is great for evaluating Drupal is Acquia's DAMP stack installer (DAMP = Drupal, Apache, MySQL, PHP). Discussed later in this chapter Acquia's stack installer provides a ready-to-go Acquia Drupal website with only a few clicks. You may use the Acquia Drupal distribution to follow along in this book.

INSTALLING A SINGLE DRUPAL WEBSITE

You'll start with a generic installation of Drupal and then take a look at each step and explore how it all works. To begin you need to have a database as well as a username and password with access to this database. If you are working with XAMMP or MAMP, you can use the included phpMyAdmin application to create the database as well as a username and password. phpMyAdmin is a popular open source application for managing the databases and users of a MySQL server. If you are using a web host, consult their documentation to determine how to create these items.

The following set of activities will walk you through creating a database and a username/password for use with Drupal. If your host has supplied you with these items you may skip ahead.

Installing a Single Drupal Website | 11

TRY IT OUT

Creating a Database using phpMyAdmin

This exercise walks you through creating a database for Drupal by using phpMyAdmin included with XAMPP/MAMP.

1. With the XAMPP/MAMP application running navigate to phpMyAdmin with your web server; http://localhost/phpMyAdmin.

2. Login to phpMyAdmin using the credentials provided with your XAMPP/MAMP installation.

3. Click Databases from the front menu.

4. At the bottom of the Database page type "drupal" into the Create new database form then click Create as shown in Figure 2-1.

FIGURE 2-1

FIGURE 2-1

How It Works

The phpMyAdmin application makes it easy to create a new database on a MySQL database server. If you created your database from a tool provided by your web host or if your web host simply gave you the name of a database the result is the same as creating one with phpMyAdmin. You only need a few items in order to install Drupal.

^ A Database name

^ A Database username and password

^ The type of Database server (MySQL, PostgreSQL, etc.)

^ The URL of the database server

TRY IT OUT

Creating a Username and password for your Database

This exercise walks you through creating a username and password for Drupal.

1. Navigate back to the front page of phpMyAdmin, then click Privileges.

2. On the Privileges page click "Add a new user" near the middle of the page, shown in Figure 2-2.

3. Fill in a username and password, as shown in Figure 2-3, then near the bottom right of the screen click Go.

i Add a new User

Do not assign permissions on this page. The permissions listed on this page are global permissions and will apply to all databases.

FIGURE 2-2

Login Information-

User name: i Use text field: ~iT| drupal

Host: 1 Local T1 localhost

Generate Password: (Generate) (c^T) RbmflyXCXW|X2

FIGURE 2-3

4. On the resulting page, the user's property page, find the Database-specific privileges form in the middle of the page and choose Drupal from the drop-down menu as shown in Figure 2-4.

Database Privileges Grant Table-specific privileges Action FIGURE 2-4

5. Select the following permissions, as shown in Figure 2-5, SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, CREATE TEMPORARY TABLES, and LOCK TABLES, then click Go.

FIGURE 2-5

You now have a new user for your Drupal database and you are ready to move onto installing your first Drupal website.

How It Works

In the previous exercise you created a database and in this exercise you created a user account with access to that database. Web hosts often combine these two actions using the same name for the user and the database but it is important to understand that these are separate items. A user may have access to multiple databases and multiple users may be able to access a single database.

Note that the permissions granted in step 5 (Figure 2-5) are the bare minimum permissions required by Drupal. It is a good security practice to only grant the permissions that are necessary for Drupal. Never use the phpMyAdmin account for your Drupal website as this could cause a security breach.

During the installation you may have noticed an option to create a database for the user as shown in Figure 2-6. This can be useful and will save you an extra step but be aware that it will automatically grant all permissions to the newly created user, which are more than what is necessary for Drupal to function.

INSTALLING DRUPAL

Installing Drupal is as simple as placing the files in the web directory, copying a settings .php file, and then navigating to the Drupal website. Drupal will automatically detect if the database is not configured and prompt you to install your first Drupal website. The site will be configured and ready for use within a few minutes.

Database for user-

Q None

@ Create database with same name and grant ail privileges Q Grant all privileges on wildcard name (username\_%)

FIGURE 2-6

Installing Drupal

In this exercise you will be installing your first Drupal site.

1. Download the latest version of Drupal from http://drupal.org and place it within your web root directory and decompress it. If you are using MAMP (Mac) your web root directory is /Applications/MAMP/htdocs, if you are using XAMPP (windows) use a web root directory at C:\XAMPP\htdocs.

2. Within the newly created Drupal folder copy the file /sites/default/default.settings.php to /sites/default/settings.php as shown in Figure 2-7.

3. Open your web browser and navigate to your new Drupal website that is located at http:// localhost/Drupal7. Substitute the word Drupal 7 for the name of the folder you created in step 1.

4. Drupal will automatically detect that you are installing a new site and ask you to select an Installation profile as shown in Figure 2-8. Select Drupal and then click Save and continue.

Copy defaull.settings.ohp settlngs.php

Select an installation profile

Create a Drupal site with the most commonly used features pte-lnstalled.

Q Drupa! [minimal)

Create a Drupal site with only required modules enabled.

Save and continue

FIGURE 2-7

FIGURE 2-8

5. Click the Install Drupal in English link.

NOTE At this point in the installation you may be presented with a Requirements problem screen. Commonly this is due to not copying the settings.php file, described in step 2, or a problem with the file or folder permissions. Simply follow the instructions on this screen to continue.

6. On the Database Configuration screen, type the database name, usemame, and password that you created earlier as shown in Figure 2-9 then click the Save and continue button located at the bottom of the page.

Drupal will automatically configure the database as well as a default set of modules based upon the installation profile selected, which in this case is Drupal.

7. After Drupal has configured the database your next step is to configure your basic site information as show in Figure 2-10 as described below.

^ Site name — Also known as a site title, this will appear on the header of a web browser.

^ Site e-mail address — This address is the sender e-mail address used for all e-mails sent by the website, which includes new user notifications and password requests.

8. Below the Site information, configure the first administrator account as shown in Figure 2-11.

This administrator account is a security sensitive account as it bypasses all permissions available in Drupal, this account has an all-access pass to your website that can not be taken away. Be sure to set a strong password on this account and place it in a safe place.

BASIC OPTIONS

Database type 1

0 MySQL 0 SQLiie

The type of database your Drupal data wilt be stored in.

Database name *

drupal7

The name of the database your Drupal data will be stored in. It must exist on your

server before Drupal can be installed.

Database usemame

drupal

Database password

► ADVANCED OPTIONS

Save and continue

FIGURE 2-9

My First Drupal site

Site e-mail address 1

[email protected]

Automated e-malls, such as registration information, wilt be sent from this address. Use an address ending in your site's domain to hetp prevent these e-mails from being flagged as spam.

FIGURE 2-10

SITE MAINTENANCE ACCOUNT

Username 1

itSMng

Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.

E-mail address *

j ac [email protected] d i ng. info

Password 1

Password strength: Strong

Confirm password "

•••••• Passwords match: yes

FIGURE 2-11

FIGURE 2-11

9. The last settings on Configure site screen are your default site settings. Configure the following server settings:

Default country — Defines the country for your site.

^ Default time zone — This setting is the site default for users who have not yet chosen a time zone to match their geography.

Update notifications — This keeps your site up-to-date by checking with drupal.org for updates to both core and contributed modules.

Receive e-mail notifications — When an update is found for your website Drupal will send an e-mail to the e-mail address you entered earlier.

10. Click the Save and Continue button.

Congratulations — you now have a new Drupal website!

How It Works

Drupal's installation automates as much of the process as possible. The database is automatically installed and populated and many of the most commonly used modules are enabled. On the last page you configure your site's name, date and time settings, as well as set the first administrator account. In the next chapter you'll explore how to change these settings after installation.

NOTE Downloads from drupal.org are compressed tar.gz files. If you have SSH command line access to your server you can use the command tar -zxvf drupal-7-x.tar.gz to uncompress and unpack the files. If you only have FTP or SCP access to your server you will need to uncompress and unpack them before uploading by using an application such as WinZip on Windows or by double-clicking the files on a Mac OS X.

Installation Profiles

The first page you encountered during the installation process asked you to choose an installation profile. In a default Drupal package you are presented with two options: Drupal and Drupal (minimal). An install profile is an automated way to install a customized Drupal website that includes themes, modules and a preset configuration. For example you could create an install profile for your local little league teams or the Boy/Girl scout troops in your region.

Read more about Install profiles at http://drupal.org/project/installation+profiles.

Installing Drupal in Different Languages

One of the many reasons why people choose the Drupal platform is for its multiple language support. Drupal has been translated into many languages and includes built-in support for Chinese/Japanese/ Korean (CJK) character set languages as well as Right to Left (RTL) languages such as Hebrew or Arabic. To install Drupal in a different language first visit http://drupal.org/project/ translations to download the appropriate translation. Extract the contents into Drupal's root directory and then begin the installation process as normal. You'll be able to select the new language during installation.

Don't worry, however, if you did not select a translation during the installation process. You can install a translation or translate your website at anytime.

ACQUIA'S STACK INSTALLER

Although a repeat of what you have already done in this chapter it would be a crime to not mention Acquia's drop-dead simple Drupal installer. Acquia's stack installs Acquia Drupal + Apache + MySQL + phpMyAdmin. The Stack also known as DAMP provides a very quick and easy local installation of Acquia Drupal. Acquia Drupal is a distribution of Drupal that comes preloaded with selected themes and modules from http://drupal.org as well as a few custom items from Acquia to connect in with Acquia's support network. It is 100 percent compatible with Drupal as well as this book but keep in mind that Acquia's default theme might differ from what is shown in this book.

You can download the DAMP stack from Acquia at http://acquia.com/downloads. Once downloaded run, the installer and you'll be greeted with a welcome screen as shown in Figure 2-12. The defaults provided are sane so you can whip through the installation accepting the defaults. After the legal agreement you'll be asked where to place the files (Figure 2-13), what ports to use (Figure 2-14), and finally for a username and password (Figure 2-15).

Q ^ Acquia Drupal stack installer

A

Welcome to the Acquia Drupal Stack installer

n acquia

1 Drupal

The Acquia Drupal Stack provides the fastest way to get

started using Acquia Drupal.

B

Click next to begin!

( Cancel ) < t r Next > )

FIGURE 2-12

Acquia Drupal stack installer

^^ 1 Drupal

Choose install locations

Stack location (Apache, MySQL, etc):

/Applications/acquia-drupal Site location: /Appllcations/acquia-drupal/Sites

Cancel ) ( < Back ) ( Next > )

FIGURE 2-13

«OQ_

Acquia Drupal stack installer

A

Port settings

1 Drupal

The ports listed below will be used. For example:

http://localhost: 8082/drupal

Leave the ports unchanged, unless you have a reason to

change them.

ill

Apache web server port: 8082

E

MySQL database port: 33066

Cancel J Q < Back ) ( Next > )

FIGURE 2-14

Acquia Drupal stack installer

A

Drupal settings

/i acquia

1 Drupal

This Drupal user, also known as user 1, will have all

privileges and permissions to manage your Drupal site.

Site name: My Acquia Drupal Site

Username: administrator

Password: ************

/w

Confirm password: ************

E-mail: [email protected]

It's important to keep this information for future

reference.

( Cancel J ( < Back J ( Next > )

FIGURE 2-15

Once installed you can stop and start Apache and MySQL (and thus Drupal) by using the provided Acquia control panel as shown in Figure 2-16.

FIGURE 2-16

NOTE You can use both MAMP/XAMPP and Acquia's DAMP on the same computer because they each use different default port settings for Apache and MySQL. This can allow you to easily explore and compare Drupal and Acquia Drupal. Note that you can also use Acquia Drupal on MAMP/XAMPP.

Breaking It Down

Now that you have a basic installation of Drupal up and running take a closer look at how it all works. Figure 2-17 shows the default Drupal folder structure. Notice that all folders and files have locks over them except for the Sites folder. These locked folders and files are collectively known as Drupal's core. The Drupal community has agreed upon a Golden Rule known as "Don't hack core." This means that you should never add files, remove files, or modify any files outside of the Sites folder.

Don't Hack Core

Modifying files within the core folders is considered taboo because it makes your site hard to maintain and troubleshoot. Drupal provides an API and a method of overrides allowing you to fully customize your site without the need to modify any core files. The exercise in the Inheritance and Overrides section of this chapter demonstrates how this works. All customizations are to be kept within your site's folder.

Utilizing the Sites folder for all of your customizations is to your advantage. The idea is simple: Whenever an update of Drupal is released, you download, unpack, and replace the default Sites folder with yours. A Sites folder can contain multiple websites, which enables you to update one, two, or hundreds of websites at the same time.

FIGURE 2-17

Core Files

Curiosity killed the cat but it shouldn't kill your website. To help you along with deciphering Drupal here is a brief list and description of the files and folders you should never modify.

^ Includes — This folder contains common functions used in Drupal, such as the bootstrap process, caching, database, and session management. Collectively, this folder contains the central nervous system of the Drupal system. One wrong move in this folder and your entire system can be paralyzed.

^ Misc — This folder is used to store core image files as well as JavaScript files (such as jquery).

^ Modules — This folder contains the core modules that make Drupal tick. Additional modules should not be added here — place those in your site's folder.

^ Profiles — This folder contains installation profiles, which are sets of modules, themes, and instructions to automate the installation of Drupal to a preconfigured state. These files are used during Drupal's installation process.

^ Scripts — This folder is used to store a few administrative command-line scripts for cleaning up code, running cron, and testing Drupal core. These files are not part of Drupal's execution cycle but are useful for advanced administration.

^ Themes — This folder contains core themes that are included with the Drupal download to make getting started with Drupal easier. If you'd like to modify a core theme you can copy it to your site's Themes folder or consider creating a sub-theme. The Theming chapter has all the information you need to start customizing your site's theme.

Sites Folder

The Sites folder is where your Drupal website stores database settings, modules, themes, files, and any other items specific to your website. This is also the folder that makes it possible for Drupal to handle multiple websites. The multi-site functionality is handled by bundling each site's information into a unique site folder. When Drupal loads a website it searches Sites for a folder named after the website. For example, if the URL is http://mysite.com then Drupal would look for the folder sites/mysite.com. If one is not found the Default folder is used.

A much broader example is contained in settings.php. Consider the URL http://www.drupal .org/mysite/test. The search order would be as follows:

1.

sites/www.drupal.

org.mysite.test

2.

sites/drupal.org

mysite.test

3.

sites/org.mysite

test

4.

sites/www.drupal

org.mysite

5.

sites/drupal.org

mysite

6.

sites/org.mysite

7.

sites/www.drupal

org

8.

sites/drupal.org

9.

sites/org

10. sites/default

Note that the default folder is last in the list and therefore will only be used when no other folder matches the requested URL. If you will not be hosting multiple sites with Drupal it is appropriate to use the default folder, this is the folder used by Drupal's installation process.

You will also notice an All folder within Sites. This folder contains only modules and themes that are shared amongst all websites. The All folder does not contain a settings.php file, because it is not site-specific. If you would like to share a single theme or module across multiple website this is the place to put it.

What's in a Site's Folder?

Figure 2-18 depicts a typical site's folder.

The items within a Site's folder are as follows:

^ Themes — This is a manually created folder that contains downloaded or custom themes specific to a website.

^ Modules — This is a manually created folder that contains downloaded or custom modules specific to a website.

^ Files — This folder is created by Drupal during installation. It contains uploaded images, documents, and other files that are available on the website.

^ Private — New to Drupal 7 this folder will contain any files that are restricted to members only and not available to the general public for download. This is great for sites that require users to login before they can view or download a file.

^ settings.php — This is automatically managed by Drupal's installation and contains database connection settings as well as advanced PHP and Drupal settings. You can read more about this file in the Advanced installation chapter of this book.

themes modules

private private

FIGURE 2-18

Inheritance and Overrides

Drupal is designed to give individual websites ultimate control. When Drupal is looking for modules and themes it first searches the core folders, then sites/all, and finally the individual site's folder. In Drupal, modules and themes must be uniquely named eliminating the possibility of having two versions of the same module or theme installed.

For example, consider the core theme Garland. If you copy this theme from / themes/garland to /sites/all/themes, then Drupal will use the version in /sites/all/themes/garland and not the core version. If you then copy this to your individual site's folder (ex. sites/default/themes/ garland), Drupal will use that version instead of the version in /sites/all/themes. Ultimately your individual site is the winner. This is how Drupal allows you to customize without having to modify the core files. Remember Drupal's golden rule is "Don't hack core".

TRY IT OUT

Overriding Drupal's Core Garland Theme

Follow this exercise to learn how to override Drupal's default theme with your own theme.

1. Copy the folder /themes/garland to sites/default/themes/garland.

2. Visit the theme administration page by clicking Administer C> Appearance or selecting Appearance from the top administration bar, shown in Figure 2-19.

A

Dashboard Content Structure "^Appearance People Modules

Configuration Reports

Add content Find content

Administer o

Hide descriptions

DASHBOARD

CONTENT

View and customize your dashboard

Comments

\

List and edit site c

\

4 APPEARANCE

Configure default and theme specific settings.

STRUCTURE

FIGURE 2-19

Verify that the theme location has moved by checking the URL path of the theme's screenshot. You can do this by right clicking on the screenshot and choosing Open/View image. The URL to the image should read /sites/default/themes/garland/screenshot.png. This indicates that the core theme is no longer being used.

How It Works

Drupal allows individual websites to override any of Drupal's core modules or themes. When you copied the core theme to your site's folder, Drupal recognized the change and switched to using your copy of the theme instead of the version in core. The hierarchy of inheritance in order of use is:

^ Your site's folder (for example: sites/example.com)

^ The sites/all folder

^ Drupal core

A theme in sites/all/themes will override Drupal core and the same theme in your site's folder will override all of them.

SUMMARY

At this point you have walked through a basic installation of Drupal and explored Drupal's folder structure. You learned that Drupal's core includes everything outside of the Sites folder and that these core items should never be modified. This unsaid rule is known as "don't hack core." The remainder of this chapter dives even deeper into the installation of Drupal exploring multi-site installations, sharing users and content between sites, and harnessing the power of settings.php. If this is your first Drupal website it is recommended that you skip this section and revisit it later once you are familiar and comfortable with Drupal.

In the next chapter you will configure your new website by adding content to it, adding users, configuring permissions and adding a contact form so that site visitors can get in touch with you.

EXERCISES

1. What version of PHP does Drupal 7 require?

2. What is the Sites folder in Drupal used for?

3. How do you install Drupal using a different language?

5. Why should you not modify Core?

6. If your Drupal site is at the URL http://www.wiiey.com what is the name of your Site's folder?

7. Why is setting a strong password on the first user account created important? Answers to the Exercises can be found in the Appendix.

► WHAT YOU LEARNED IN THIS CHAPTER

> Drupal's installer will automatically install and configure your database.

> Drupal can be installed in a language other than English by simply downloading a translation from http://drupal.org/project/translation.

> Your site's database settings, modules, themes, and uploaded files are stored within the sites folder.

> Your site's folder should be named are your site's URL without the http:// (for example: example.com).

> If Drupal does not find a folder for your site's URL it will use the settings found in the default folder.

> The word "Core" represents all files and folders outside of Drupal's sites folder.

> You should never modify Core.

+2 0

Responses

  • philipp bader
    Can you run xampp and damp both?
    8 years ago
  • medhanie
    How set timezone in install profile Drupal 7.x?
    7 years ago
  • Maxima
    What ports does drupal use?
    7 years ago
  • swen
    Where is mysql database stored in aquia drupal?
    7 years ago

Post a comment