(For more resources on Drupal 7, see here.)
There are a number of different ways to install Drupal on a web server, but in this recipe we will focus on the standard, most common installation, which is to say, Drupal running on an Apache server, which runs PHP with a MySQL database. In order to do this we will download the latest Drupal release, and walk you through all of the steps required to get it up and running.
Before beginning, you need to ensure that you meet the following minimal requirements:
- Web hosting with FTP access (or file access through a control panel).
- A server running PHP 5.2.5+ (5.3+ recommended).
- A blank MySQL database and the login credentials to access it.
- Ensure that register globals is set to off in the PHP.ini file. You may need to contact your hosting provider to do this.
How to do it...
- The first step is to download the latest Drupal 7 release from the Drupal download page, which is located at http://drupal.org/project/drupal :
This page displays the most recent and recommended releases for both Drupal 6 and 7. It also displays the most recent development versions, but be sure to download the recommended release (development versions are for developers who want to stay on the cutting edge).
- When the file is downloaded, extract it and upload the files to your chosen web server document root directory on the server. This may take some time.
- Configure your web server document root and server name (usually through a vhost directive).
- When the upload is complete, open your browser and in the address bar, type in the server name configured in the previous step to begin the installation wizard.
- Select Standard option and then select Save and continue:
- The next screen that you will see is the language selection screen; there should only be one language available at this point. Ensure that English is selected before proceeding:
- Following a requirements check, you will arrive at the database settings page. Enter your database name, username, and password in the required fields. Unless your database details have been supplied with a specific host name and port, you should leave the advanced options as they are and continue.
- You will now see the Site configuration page. Under Site information enter the name you would like to appear as the site's name.
- For Site e-mail address enter an e-mail address.
- Under the SITE MAINTENANCE ACCOUNT box, enter a username for the admin user (also known as user 1), followed by an e-mail address and password:
- In the Server settings box, select your country from the drop-down, followed by your local time zone.
- Finally, in the Update notification box, ensure that both options are selected. Click on Save and continue to complete the installation. You will be presented with the congratulations page with a link to your new site.
(Move the mouse over the image to enlarge.)
How it works...
On the server requirements page, Drupal will carry out a number of tests. It is a requirement that PHP "register globals" is set to off or disabled.
Register globals is a feature of PHP which allows global variables to be set from the contents of the Environment, GET, POST, Cookie, and Server variables. It can be a major security risk, as it enables potential hackers to overwrite important variables and gain unauthorized access.
The Configure site page is where you specify the site name and e-mail addresses for the site and the admin user. The admin e-mail address will be used to contact the administrator with notifications from the site, and the site e-mail address is used as the originating e-mail address when the site sends e-mails to users. You can change these settings later on in the Site information page in the Configuration section.
It's important to select the options to receive the site notifications so that you are aware when software updates are available for your site core and contrib modules; important security updates are available from time to time.
In this recipe we have seen a regular Drupal installation procedure. There are various different ways to install and configure Drupal. We will explore some of these alternatives in the following sections. We will also cover some of the potential pitfalls you may come across with the requirements page.
Uploading through a control panel
If your web-hosting provider provides web access to your files through a control panel such as CPanel, you can save time by uploading the compressed Drupal installation package and running the unzip function on the file, if that functionality is provided. This will dramatically reduce the amount of time taken to perform the installation.
There are other ways in which Drupal can be installed. Your hosting may come with an auto- installer such as Fantastico De Luxe or Softaculous. Both of these services provide a simple way to achieve the same results without the need to use FTP or to configure a database.
Database table prefixes
At the database setup screen there is an option to use a table prefix. Any prefix entered into the field would be added to the start of all table names in the database. This means that you could run multiple installations of Drupal, or possibly other CMSs from the same database by setting a different prefix. This method, however, will have implications for performance and maintenance.
Installing on a Windows environment
This recipe deals with installing Drupal on a Linux server. However, Drupal runs perfectly well on an IIS (Windows) server. Using Microsoft's WebMatrix software, it's easy to set up a Drupal site: http://www.microsoft.com/web/drupal
Drupal supports many different languages. You can view and download the language packs at http://localize.drupal.org/download.
You then need to upload the file to Drupal root/profiles/standard/translations. You will then see the option for that new language in the language selection page of the installation.
Verifying the requirements page
If all goes to plan, and the server is already configured correctly, then step 3, the server requirements page, will be skipped. However, you may come across problems in a few areas:
- Register Globals: This should be set to off in the php.ini file. This is very important in securing your site. If you find that register globals is turned on, then you will need to consult your hosting provider's documentation on this feature in order to switch it off.
- Drupal will attempt to create the following folder: Drupal root/sites/default/ files. If it fails, you may have to manually create this file on the server and give it the permission 755.
- Drupal will attempt to create a settings.php file by copying the default.settings.php file.
- If Drupal has trouble doing this, copy the default.settings.php file in the following directory: Drupal root/sites/default/default.settings.php and rename the copied file as settings.php.
- Give settings.php full write access CHMODD 777. After Drupal finishes the installation process, it will try to set the permission of this file to 444; you must check that this has been done, and manually set the file to 444, if it has not.
See Installing Drupal distributions for more installation options using a preconfigured Drupal distribution.
For more information about installing Drupal, see the installation guide at Drupal.org: http://drupal.org/documentation/install
(For more resources on Drupal 7, see here.)
Installing Drupal distributions
Drupal distributions are third-party Drupal packages where the official Drupal release has been re-packaged to contain extra features. Drupal distributions can configure a complete Drupal site ready for a specific task, eliminating the need to research and install third-party modules.
The requirements for installing Drupal distributions are the same as for installing the Drupal core, as described in the preceding recipe Installing Drupal. You will need the following:
- Web-hosting with FTP access (or file access through a control panel)
- A server running PHP 5.2.5+ (5.3+ recommended)
- An empty MySQL database and the login credentials to access it
How to do it...
- For this example we will use the Commerce Kickstart distribution. Download this installation package from here: http://drupal.org/project/commerce_kickstart
- Configure your web server's server name and document root.
- After the download is complete, extract the files, and upload the files to your web space document root using your FTP client of choice.
- Once the upload is complete, navigate to the root (using the server name configured in your web server) of your website, using your browser to start the installation wizard.
- Complete all the steps up to the Site configuration (see the previous recipe, Installing Drupal).
- After completing the site configuration step you will arrive at a screen entitled Example store that provides installation options specific to the Drupal Commerce Kickstart distribution. Select both of the boxes on this screen to generate sample content for the Drupal commerce site.
How it works...
Now that you've learned how to install Drupal distributions, the distribution world is your oyster! There is an increasing range of different Drupal distributions to choose from that cater for a wide variety of websites, from conference organization to e-learning.
- Installing Drupal
- There are a number of different distributions currently available. Visit the following page to explore the distributions listed on the official Drupal.org site: http://www.drupal.org/project/installation+profiles
Installing modules and themes
It is entirely possible to run a very successful Drupal website out of the box without adding any third-party modules. However, this approach is limited, and your needs may grow out of the built-in core functionalities. With just a few additional modules, the functionality of your site can be significantly expanded.
In this recipe, we will first see how to install the Link module from the Drupal.org website, followed by how to activate and configure it. The Link module adds a Link field to the list of available fields that can be used to create new content types.
How to do it…
- Go to http://drupal.org/project/link.
- Examine the available releases of Link, and find the most recent Drupal 7 release; copy the URL for the tar.gz file
- In Drupal, select Modules from the admin menu, followed by Install new module.
- Paste the URL into the Install from a URL field and click on Install.
- After the module is installed, select Enable newly added modules.
- Look through the list of installed modules for the FIELDS> fieldset. Select the checkbox for Link.
- Click on Save configuration to finish:
How it works…
We begin by going to the project page for the module we are installing. In this case, the Link module. We then look for the most recent recommended release of the module.
On the module's page it is likely that there will be two releases for both the Drupal 6 and Drupal 7 versions of the module. The files with the green background are the recommended releases. Be sure to use this version wherever possible. Sometimes there will only be an alpha or development release; try to get the highest version number.
After copying the link to the module's file, we go to the module installation page, and paste the URL to the module's file, and click on Install. Drupal then copies the file to the server, and extracts it into its own directory in the modules folder of the site.
After the module has been copied, we go back to the modules list, and enable the newly installed module by checking its checkbox and clicking on Save configuration to finish.
There are more ways to install modules in Drupal. It's up to you to decide which method you prefer, but some other methods are described in the following sections.
Manually installing a module
The preceding method described uses the install from URL method. You may want to install a module manually. In which case simply download and extract the module package and move the extracted files to the Drupal root/sites/all/modules directory.
Installing a module with the Drush command-line tool
The process of installing modules can be made even easier by using the Drush tool to issue installation commands.
(For more resources on Drupal 7, see here.)
Setting up site search
In this recipe, we will see how to configure Drupal's native site search. The search feature is a part of the Drupal core module set. We will start by enabling the module, and then proceed to set up the search index. Finally, we will move the search block to the header.
How to do it...
- Log in to your site and select Modules from the admin menu.
- Locate the Search module, which is under the Core category, and make sure the checkbox is selected.
- To enable the module, scroll to the bottom of the page and click on Save configuration.
- Select Configuration from the admin menu.
- Select Search settings from the SEARCH AND METADATA category.
- Under INDEXING THROTTLE leave the Number of items to index per cron run at 100.
- Under the INDEXING SETTINGS leave the Minimum word length to index as 3 and leave Simple CJK handling checked.
- Under Active search modules ensure that Node and User are checked.
- Under Default search module ensure that node is selected.
- Under CONTENT RANKING set Keyword relevance to 1.
- Click on Save configuration and close the admin panel when the save is complete.
- To place the Search form in the header, select Structure from the admin menu.
- Select Blocks from the Structure menu to go to the blocks management page.
- Search through the blocks list to find the Search form block and set its position to header by updating the drop-down menu.
- Scroll down the page and click on Save blocks.
How it works...
The site search works by periodically indexing the pages of a site. The indexing is activated by a cron job at a predetermined interval.
Cron is the process that periodically activates tasks such as search indexing, checking for updates, and clearing the cache. Drupal 7 has its own method to periodically call the cron script; however, it's more preferable to call Drupal's cron script directly from the server by setting up a crontab for optimum performance.
It is important that you ensure that the cron is configured to run at a suitable interval. If you have lots of frequently changing content, then you will want to configure the cron to run more frequently, or less frequently if your content changes rarely. It's a trade-off between server load and search results freshness.
The Indexing status category on the search configuration page displays the percentage of content indexed. This indicates how much of the eligible content is indexed for the search function. Don't worry if your content isn't immediately indexed. The indexer is configured to only index a finite number of pages per cron run. The number of pages indexed per run is set in the Indexing throttle category. You must be careful that the throttle is not set so high that it can overload your server.
You can manually activate the cron job, and therefore, activate the search indexing procedure, by going to Configuration | Cron | Run cron.
The Content ranking option will determine the prominence of each of the listed factors; a weight of 0 being no prominence and a weight of 10 being highest prominence. The actual settings that you choose for this should depend on the type of search results you or your organization favor.
The search form block will be set to display in the first column by default. Moving it to the header is just a personal preference, with the added purpose of demonstrating how easy it is to move the block.
Creating a multi-site Drupal installation
Drupal's multi-site feature allows multiple sites to run from the same core code, while having separate databases, configurations, and user files. Multi-site functionality removes the pain in managing multiple cores and multiple sets of modules, meaning that there is only one primary installation that needs to be updated and managed. It also reduces the amount of disk space that is required.
In this recipe, we will see how to prepare the secondary site's domain so that it points to the primary site's Drupal installation. We will then see how to activate and install the multi-site functionality on the primary site.
You will need the following:
- An existing Drupal installation for your primary site
- A domain name for your secondary site
- The ability to update your secondary domain to point to the name server of your primary domain
- You will need the ability to create an add-on domain for your primary site (we will see how to actually create the add-on domain in the recipe)
- A blank database
How to do it...
- Update your secondary domain's name server to be the same as the primary domain's name server.
- On your primary server, log in to your server's admin panel and create a new add-on domain. Add the URL of the secondary domain as the new domain name.
- Add a username and password. This is to enable you to provide specific FTP access to the secondary domain without providing FTP access for your primary domain. Set the document root to be the location on the server of your primary Drupal installation:
- On your primary site create a new folder inside your sites directory which has the same name as your secondary site, for example, /Drupal root/sites/ secondary-site.com/.
- Copy default.settings.php from the following folder: /Drupal root/ default/ to the /Drupal root/sites/secondary-site.com/ folder.
- Rename the newly copied file to settings.php and set its permission to 666:
- Under /Drupal root/sites/secondary-site.com/, create a new folder called files and set the folder permission to 777
- Go to your secondary site in your browser; you will see the standard installation screen.
- Complete the installation wizard as described in the first recipe of this article (Installing Drupal). On the database settings page enter the login credentials of your newly created empty database.
- After completing the installation, set the permissions of Drupal root/sites/ secondary-site.com/settings.php to 444
How it works...
Updating the name server is usually done through the domain registrar. The name server you need to enter for the secondary domain will most likely be provided by your hosting provider for your primary domain in the welcome e-mail. You may need to wait some time for the DNS records to propagate before your domain name resolves to the newly appointed server.
Creating an add-on domain allows you to set up a third-party domain to point to your hosting directory without having to redirect the user. This means that the URL in the address bar of the user's browser will remain constant, even though they are accessing the directory of another site. The setup procedure for configuring an add-on domain may be different with different hosting providers and control panels, and this example references the cPanel management panel. If you find diffculty getting this to work, reference your hosting provider's documentation for add-on domains.
- Drupal 7 Social Networking: Managing Users and Profiles [Article]
- Setting up the Basics for a Drupal Multilingual site: Languages and UI Translation [Article]
- Drupal 7: Customizing an Existing Theme [Article]
- Setting up an online shopping cart with Drupal and Ubercart [Article]