Drupal 7

4 (1 reviews total)
By David Mercer
  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Introduction to Drupal

About this book

Drupal is an elegantly designed, well-supported and flexible open-source CMS platform that anyone can use in order to create their own website. What's more, the latest version of Drupal 7 includes a tremendous number of new features and new under-the-hood improvements for both users and developers. Drupal is a hugely popular and widely celebrated open-source Content Management System that is day-by-day becoming the first choice of people for a wide range of websites. The White house and the British government, to name but a few, turn to Drupal to fulfill their online requirements.

This book provides the best way to learn and master Drupal 7, enabling you to create virtually any type of website. It meets the booming demand for well presented, clear, concise, and above all practical information on how to design and build sites like a pro.

With such a powerful tool at your fingertips there is no longer any need to pay professionals to design a site when you can do the same job yourself absolutely free. All it takes is a bit of practice!

By clearly and concisely demonstrating the fundamentals of Drupal and combining this with practical and methodical coverage of more advanced subjects, this book paves the way for anyone to quickly become proficient at building and operating professional websites.

Online Web design tutorials will help you to consolidate and expand on what you learn in the book. It is an indispensable companion for anyone and everyone interested in building a website.

Experienced technical author David Mercer expertly guides the reader through all the stages of building a professional website in a plain, articulate manner. Aimed in particular at beginners to Drupal, this book will allow you to advance rapidly up the learning curve to the point where they can tackle any problem with confidence.

Publication date:
September 2010
Publisher
Packt
Pages
416
ISBN
9781849512862

 

Chapter 1. Introduction to Drupal

Until quite recently, the most important thing a newcomer to the Web could do in order to prepare for building a website was to buy a book on how to learn programming in any one of the major web-centric languages such as PHP or Perl. The not inconsiderable task of learning the niceties of the chosen language to a respectable degree would consume a fair chunk of time and patience. Once our hapless newcomer had sufficient mastery of the fundamentals, applying that knowledge to program efficiently and reliably, with the tenacity to stick with a job until the site was developed, could arguably be described as a Herculean accomplishment.

This state of affairs is, and quite rightly should be, entirely unacceptable to someone like yourself. It's like forcing lawyers to learn the intricacies of architecture, construction, and masonry simply because they require a courtroom to work in. It should be quite apparent that separating the technical task of developing the software for a website, from the function of that website is a very sensible thing to do; the main reason being that it allows people to focus on what they are good at without them having to devote time and energy to becoming good software developers too.

It's not surprising then, that in recent years the open source community has been hard at work pulling the programming world out of the software dark ages by providing us with flexible frameworks for building web-based enterprises. These frameworks free website creators from the intellectual burden of learning software development ideas and concepts, allowing them instead to focus more on goal/business-oriented configuration and customization tasks.

Drupal is one such result of this software development evolution, and this book seeks to provide you with the fundamental information needed in order to use it effectively. Because this book focuses more on beginner-level aspects of working with Drupal, you will be pleased to know that there will be little to no coding involved—you're not required to learn how to develop Drupal modules from scratch, for example. That's not to say this book will be elementary; on the contrary, the knowledge gained here will enable you to tackle problems beyond the scope of this material with confidence.

Note

To further consolidate your learning and expand on the practical aspect of the various topics covered throughout the book, each chapter will have an associated self-marking online quiz with additional exercises available at the author's website: http://www.siteprebuilder.com. It is highly recommended you take advantage of this additional resource to get the maximum benefit from this book.

Before we begin building anything that resembles a website, I'm sure you have plenty of questions about the how, what, where, and why of Drupal. Consequently, this chapter will not only provide a backdrop for the rest of the book, but will also serve as an introduction to the technology as a whole, incorporating brief discussions on the following topics:

  • Drupal—an overview

  • How Drupal came to be

  • What Drupal has to offer

  • Uses of Drupal

  • The Drupal community

  • The Drupal license

  • The server environment

  • Obtaining and installing XAMPP (Apache, MySQL, and PHP)

  • Obtaining and installing Drupal

  • A short tour of Drupal

Before we begin, there is one crucial bit of advice to be given:

Tip

Ensure that you have access to a good, preferably broadband Internet connection, as you will be downloading a fair amount of software.

If you already have a development environment set up and running, feel free to skip the web server sections and move to the Obtaining and Installing Drupal section.

 

Drupal—an overview


Drupal is an Open Source Content Management System. If you are new to both computing and Drupal, then this probably doesn't clear things up very much. First of all:

Tip

The term open source describes software whose source code is made available, most often subject to certain conditions, for use or modification by users or other developers, as they deem fit.

The specific conditions under which Drupal is made available will be scrutinized more closely in the section The Drupal license later in this chapter.

Besides that, what open source means for someone who intends to make use of Drupal is that there is no obligatory payment required for this unquestionably valuable software. You also join a large community (also to be discussed later in this chapter) of Drupal users, developers, and administrators who subscribe to the open source philosophy—in other words, someone out there will probably be willing to spend time helping you out, should you get stuck.

That's a pretty good deal for those who are still not convinced about open source technologies as a whole—not only do we not have to develop the entire site ourselves, but we also get to take advantage of the collective wisdom of thousands of other people.

Is there anything else we can say about open source? Sure, with an active community like the one associated with Drupal, development advances rapidly and flexibly because any problems can be spotted early and dealt with effectively. This means that you can expect a high level of stability, security, and performance from Drupal websites.

OK, but what is the Content Management System (CMS) part all about?

Tip

A content management system is software that facilitates the creation, organization, manipulation, and removal of information in the form of images, documents, scripts, and plain text (or anything else for that matter).

If you have a need to organize and display fairly large amounts of information, especially when it is likely that content will be created or delivered from a variety of different sources, then a content management system is undoubtedly what you need.

That's basically all you have to know. Drupal provides a free platform, along with its attendant community, for satisfying a wide variety of content-management requirements. Precisely what one can achieve is the subject of the What Drupal Has to Offer section, later in this chapter. For now though, let's turn back the hands of time and take a look at how we ended up with Drupal as we know it today.

 

How Drupal came to be


As with so many modern success stories, this one started in a dorm room with a couple of students needing to achieve a specific goal. In this case, Dries Buytaert and Hans Snijder of the University of Antwerp wished to share an ADSL modem connection to the Internet. They managed this via the use of a wireless bridge, but soon after, Dries decided to work on a news site, which would, in addition to the simple connection the students already shared, allow them to share news and other information.

Over time, the site grew and changed as Dries expanded the application and experimented with new things. However, it was only later in 2001, when it was decided to release the code to the public in the hope that this would encourage development from other people, that Drupal became open source software. It's clear that releasing the source to the public was the right choice because today Drupal has a well organized, thriving community of people ranging from contributors, administrators, a security team, and a global presence, to plenty of users who make invaluable additions to the Drupal project on a regular basis through bug reports and suggestions.

In only a few years, Dries and others have taken a small inter-dorm-room application and turned it into a technology that is contributing to the way in which the global society communicates through the Web. This is embodied in their brief mission statement that reads:

By building on relevant standards and open source technologies, Drupal supports and enhances the potential of the Internet as a medium where diverse and geographically separated individuals and groups can collectively produce, discuss, and share information and ideas. With a central interest in and focus on communities and collaboration, Drupal's flexibility allows the collaborative production of online information systems and communities.

Ultimately, where Drupal is going and how it came to be, are also driven by the philosophies that guide those responsible for developing this technology. As you will see throughout the course of this book, it is fair to say that the Drupal community has so far succeeded in meeting its lofty targets.

 

What Drupal has to offer


As users of technology and software, we should never be lax in what we demand from the technologies that serve us. It is fitting, therefore, at this stage, to discuss what we expect from Drupal in order to ensure that it will satisfy our needs.

There are three different aspects of Drupal we need to consider when looking at whether it is a good technology to use in general. Will it be:

  • Reliable and robust: Are there a lot of bugs in the code? Will it affect my site if I have to forever add patches or obtain updates for faulty code?

  • Efficient: Does the software use my server's resources wisely? Am I likely to run into concurrency problems or speed issues early on?

  • Flexible: If I change my mind about what I want from my site, will I be able to implement those changes without redoing everything from scratch?

While Drupal will always be a work in progress, it can be taken for granted that the source code, used to build your website, has been meticulously crafted and well designed. In fact, the previously listed points are taken so seriously by the developers of Drupal that they are written into their set of principles that are available at http://drupal.org/node/21945.

While it won't influence us much for the moment, it is worth noting the following:

Tip

A great advantage of Drupal is that the code itself is very well designed and written, which makes modifying it easy. This means that, as you attempt more advanced tasks, the very way in which Drupal is designed will lend you an advantage over other platforms.

The next thing we need to consider is: what Drupal is like for us, as administrators, to use. Naturally, things should be as easy as possible, so that we don't spend time bogged down with problems or complicated settings, or worse yet, have to modify the source code on a regular basis. Ideally, we want a system that is:

  • Easy to set up and run: Can I start creating a site with the minimum of fuss? Do I have to learn about other technologies before I am able to use Drupal?

  • Intuitive to work with: Once I have begun finding my way around, will it be easy to learn new things? If I am not a particularly technical person, will I struggle to administer my site?

  • Flexible and easy to extend: I know I can make a basic site, but I really want to create a unique and sophisticated, ground-breaking site—can it be done with Drupal?

  • Secure: Has the website been successfully used in real world applications? Are known bugs fixed quickly and regularly?

Again, these are precisely the attributes that Drupal is known for. If you have other questions that are not specifically mentioned here, try looking through the Drupal forums.

Finally, and perhaps most importantly, it is necessary to consider whether or not Drupal creates a good environment for site users. Obviously, a technology that is well designed and easy to administer would still not be very helpful if, for example, its use by visitors is prohibitively complex. The best way to find out what type of environment Drupal can provide is to go ahead and check out the Drupal home page at http://drupal.org—since it is built with Drupal and is a good example of what one can do.

It's a good idea to register an account if you have a moment or two. It's not absolutely necessary, but believe me, it will be of great benefit in the long run. Perhaps treat your registration process as a quick and easy way to see a bit of the site.

It stands to reason that if the main site that is developed in Drupal is easy to use, then you, in turn, will be able to create an easy-to-use site for your users. Ultimately, how easy a site is to use depends on how you, the creator of the site, present content and information.

 

Uses of Drupal


Any enterprise that requires a fair amount of working with content is a likely candidate for Drupal, but, because of its extensibility and flexibility, you are really not limited in any sense. The following list shows the most common uses at present and comes from the case studies page (http://drupal.org/cases) on the Drupal site:

  • Community portal sites: If you want a news website where the stories are provided by the audience, Drupal suits your needs well. Incoming stories are automatically voted upon by the audience, and the best stories bubble up to the homepage. Bad stories and comments are automatically hidden after enough negative votes.

  • News publishing: Drupal is great for newspapers and other news organizations.

  • Aficionado sites: Drupal flourishes when it powers a portal website where one person shares their expertise and enthusiasm for a topic.

  • Intranet/Corporate websites: Companies maintain their internal and external websites in Drupal. Drupal works well in these cases because of its flexible permissions system and its easy web-based publishing. No longer do you have to wait for a webmaster to get the word out about your latest project.

  • Resource directories: If you want a central directory for a given topic, Drupal suits your needs well. Users can register and suggest new resources, while editors can screen their submissions.

  • International sites: When you begin using Drupal, you join a large international community of users and developers. Thanks to the localization features within Drupal, there are many Drupal sites implemented in a wide range of languages.

  • Education: Drupal can be used for creating dynamic learning communities to supplement the face-to-face classroom or as a platform for distance education classes. Academic professional organizations benefit from its interactive features, and the ability to provide public content, member-only resources, and member subscription management.

  • Art, Music, and Multimedia: When it comes to community art sites, Drupal is a great match. No other platform provides the rock solid foundation that is needed to make multimedia-rich websites that allow users to share, distribute, and discuss their work with others. As time goes by, Drupal will only develop stronger support for audio, video, images, and playlist content for use in multimedia applications.

  • Social networking sites: Drupal has a lot of the common features used in social networking sites. You can build a collection of social networking applications for your site or use Drupal as a white label social networking service.

Drupal can be thought of as the Internet's jack-of-all-trades—it excels in many areas, but at heart, it is a generalist. So while you can use Drupal for a great number of things, you should perhaps limit its use to those things that complement its design—like those mentioned in the previous list.

 

The Drupal community


Drupal has coherent and in-depth support structures that are fairly easy to learn your way around. There are a host of categories ranging from information, polls, forums, and news to support, which can be found at the home page http://drupal.org.

It is strongly recommended that you regularly make use of drupal.org and constantly use different elements and sections in order to become proficient at extracting the information and software you require—especially because the Drupal site will change from time to time!

All the information contained in the site is well organized and easy to access from the main navigation bar at the top of the page, as shown in the following screenshot:

Each and every tab in the navigation bar has a host of its own links and pages; although there are some categories that contain inter-related topics. At any rate, let's go through each one quickly to see what they have to offer.

Documentation

This section is a great repository of information, catering for a wide variety of needs. The content is gathered into five main sections, some are shown in the following screenshot:

Each of these categories contains a series of links to informative pages (that, in turn, often contain links to other pages) that do a good job of explaining their respective topics. It's worth pointing out that a block appears on the left-hand side of these pages, containing links to related topics under the same category heading in order to help you navigate through the information with ease.

The following screenshot shows the Understanding Drupal page:

You are urged to look through at least the first section before moving on in order to learn as much about Drupal as possible. It is also a good idea to use these handbooks in tandem with this book, so that you can complement the practical advice and experience you gain here with reference-type material presented on the site.

Download

We will be visiting this section again in the following chapter when we begin to set up everything in preparation for site development. However, there are a few interesting points to note before we get there. The first is that you need to be quite careful about the Drupal version—or indeed modules and themes—you download, because each successive version makes changes and improvements on previous versions, and also sometimes messes up compatibility with other features.

If you decide to add a module (by this, I mean that at some stage you will want to add a module), then viewing the projects page at ht tp://drupal.org/project/modules or clicking the Download tab gives the following:

You can see from the notes presented on this page, if you happen to need a module that was developed for Drupal 5.x and you are using version 6.x (the same goes for Drupal 7), then you are shortly going to experience no small amount of frustration—this is especially valid at this time, given that 7.x is brand new, and hence many modules have yet to be updated.

Tip

Use the Filter by compatibility block to limit module results to only the version you require.

Problems like this can occur because modules are developed separately from the core, which means that it is up to the individual module developer to keep up to date with any changes coming from the main development team.

Naturally, not everyone will keep their modules up to date in a timely manner because, often, these developers are not getting paid and are under no obligation to do the work at all. They are simply providing us with the best code they can deliver when they can deliver it.

In terms of how to use the download pages, it is worth noting that there are four main links given in each downloadable item's box.

These are:

  • Download

  • Release notes

  • Find out more, and

  • Bugs and feature requests

The first option is pretty self-explanatory, but you should always take a look at the Find out more option before downloading anything to ensure that you are getting precisely what you want—often, this information will include download statistics, which can give you a good idea of how popular a module is.

For example, the Find out more page for the Views project contains information on history of Updates and plenty of material on Releases, Resources, Support, and Development—all of them are pretty useful if you are not sure what Views does to begin with.

Support

The Support section can be regarded as a kind of catch-all page, and actually contains a number of links to the various other community pages, many of which can also be opened by using their tabs in the main navigation bar. For example, you can navigate back to the Drupal handbooks (to be discussed shortly) from the Get documentation section to find out some basic information on Drupal.

Briefly, in this section:

  • The Get started section offers a get started guide, training resources, and videos

  • Documentation and help facilities are provided in the Get documentation section and include links to books and various guides

  • There are also links to forums, groups, mailing lists, and commercial support in the Get help section.

  • If you are not an English language speaker or your community predominantly speaks some other language, then it is worthwhile checking out some of the other language sites under the Other languages section, that includes German, French, Spanish, and Afrikaans.

If in doubt as to where to go, the Support page is probably the best place to start.

Forum

The forums are probably the single greatest problem-solving resource and information-based asset. Unlike the other types of information on the site (with the exception of the Freenode Drupal IRC), which are largely static, written answers or guides, the forums provide you with an interactive environment in which to learn. Of course, they also provide you with a medium for sharing whatever you have learned as well.

At the time of writing, there were in excess of 500,000 support-related posts alone. The following screenshot shows the Forum home page as well as the first few forum categories. It's easy to see that this is a fairly large repository of knowledge and hopefully you will take the time to add to it yourself:

Looking at the entire page, there are four main forum categories— General, Support, Services, and Newsletters—that in turn have a number of subcategories to make navigating the structure fairly easy. Notice too that there is a block on the right-hand side of the page containing a list of the most recent posts. As well as this, you can also use the search tool, shown at the top right-hand side of the page or at http://drupal.org/search/node, to search for relevant information or users.

Finally, assuming you are a registered (and logged-on) Drupal user, you can also post new topics to the forum using the link given under the page's main heading.

Before posting off hundreds of questions and salutations, please be aware that there is a certain etiquette to using these forums, and it should be followed at all times. Look at http://drupal.org/forum-posting before you begin writing any posts to the site:

A quick summary is as follows:

  • Search the forums for your intended topic, and use those posts instead of creating redundant information.

  • Make forum post titles informative and meaningful.

  • Submit a good amount of system-specific information in your support queries—for example, mention the Drupal version along with the database and database version.

  • Bear in mind that not everyone using the forum is a native English speaker; so some posts may be construed as rude or abrupt when that is not the intention.

  • Remain polite and reasonable—even if you are frustrated over a particular problem.

  • Donate some time to responding to and helping other posters.

  • If you would like, enable your contact tab so that people can offer support via e-mail. Do this by editing your contact information,

Some of you may have noticed the link entitled Recent posts on the right-hand side of the page (assuming you are logged in). Clicking on this link brings up a list of the topics that have recently been active:

If you would prefer to view the discussions that you personally have contributed to, then click the My recent posts tab on this page instead.

Contribute

At first glance, you might assume that there is very little to contribute to the Drupal community while you are still learning the software. This is not entirely true, so it is worthwhile seeing what is available to us:

For starters, the easiest way to support Drupal is by making donations—I can all but hear the sighs and groans, but bear in mind what you are getting is absolutely free. You can also help market Drupal by writing reviews, incorporating the Druplicon onto your site, and so on. There is also a constant need for people to help test, translate, support, and document Drupal.

Finally, once you have gained some experience and feel confident enough, look towards helping with Drupal development. Whatever you choose to do, any information or help you require in order to become pro-active within the community is readily available under the Contribute section.

Contact

The Contact page allows you to send an e-mail to the Drupal team, and you need to remember that no technical support queries will be addressed here—you must use the support forum for that. Select the most pertinent category from the drop-down list provided and away you go. An example is shown in the following screenshot:

That about wraps it up for our coverage of the Drupal community. You should feel fairly confident that you can use the site efficiently and find help if needs be. Before we start setting up our website, there is one more important issue we need to discuss, namely, the Drupal license.

 

The Drupal license


You should always be well acquainted with any legalities and responsibilities you have when it comes to using software developed by others. To this end, you will find that when you download a copy of Drupal, it will contain a license file for your perusal—it is actually required as part of the license that this copy be included.

If you're like me, then you find it challenging to remain awake when faced with the prospect of reading through licenses and other legal documents. So, instead of subjecting you to a verbatim recount of the entire license, I will instead give you the paraphrased version that is intended to provide you with the essence of what the license is for as it applies to Drupal.

Note

Please bear in mind that what I say here is in no way a legal document. You must read the whole license yourself if you wish to follow the letter of the law.

As odd as it may sound, one of the fundamental reasons for using the GNU GPL (General Public License) is to protect and help you—the people who use the software. The GPL is fundamentally different from the licenses of proprietary software, which, by and large, are designed to protect the rights of the corporate entities that developed and created the software.

Incidentally, the GPL is not tied specifically to Drupal; rather Drupal makes use of the GPL, which is a kind of generic license for distributing open source software. You can check out the GNU homepage http://www.gnu.org/home.html for more information on this movement.

The way things work is that the software is copyrighted and then licensed for everyone to use freely. This might strike you as a little odd at first because what is the point of copyrighting something if you are simply going to let everyone else make use of it? The reason for this is that copyrighting and licensing the software gives the developer the power to obligate people who use that software to afford everyone they hand it out to (with or without modifications) the same rights that are vested in the original software.

What this means is that, effectively, anyone who makes use of this software cannot create proprietary software from it. So, if you decide to build upon and improve Drupal in order to sell it as your own product, then you will be bound by the same terms and will have to release the source code to anyone who asks for it.

Remember though, the aim of the GPL is not to take credit for your own work by forcing you to release it under the GPL. If you have developed identifiable programs or code that are wholly your own and are independent from the original source code provided, then the GPL does not apply to your work.

A summary of some of the main points in the license is as follows:

  • You are free to copy the software covered by the GPL as well as distribute these copies however you see fit. The most important thing is not to remove the licensing

  • You can hack around with the source code and create whatever type of derived product you want. Again, you must pass on the same license (as you received it) with the original code, only this time you must make it very clear what changes you introduced

  • You mustn't break the terms of the GPL at any stage or you will find your current license to use the software terminated

  • You aren't forced to accept the conditions of the license. (You can tell this from the fact that you don't have to sign anything.) However, if you don't accept the terms of the license, you can't make use of the software

  • If you do decide to redistribute the software yourself, then you can't add restrictions or modify the license in any way. You also aren't required to ensure that the parties you distribute the software to comply with it

  • If you are compelled by a court ruling (or any other legal proceeding) to enforce conditions that do not meet the requirements of the GPL, then you must not distribute the software at all

  • Keep an eye on the version of the license that is distributed with the software. If there is one present, then you must use that version (in some instances of the GPL, a later one is also suitable, but never an earlier one)

  • There is no warranty on this software, and no one who modifies or distributes the software in terms of the GPL is responsible for anything—especially damages or failure to operate and so on

At the end of the day, the only time you do need to worry about the niceties of the GPL is when you decide to set up a business installing, configuring, and customizing Drupal websites for money, or modifying, and redistributing the original source code.

 

The Server environment


I know most of you will be eager to get going at the moment and might well prefer to dive straight into making modifications to your Drupal site. Before we do so, we can take a few moments to read over this section to gain an appreciation of how everything is put together behind the scenes.

Having a basic knowledge of how the various technologies co-operate in order to produce a working Drupal site will help immeasurably in the long run. While everything we need to run a server will be provided in a single package, let's take a look at each of the individual underlying technologies we will be using:

  • PHP: PHP, or PHP Hypertext Preprocessor, is the language in which Drupal is written. PHP is widely used on the Internet for a multitude of different projects and is renowned for its ease of use.

  • Apache: This is the web server we will use to serve web pages during the development phase. Apache is the most popular web server on the Internet, with millions of live sites using it every day. In fact, as the Apache website says: It is more widely used than all the other web servers combined.

  • MySQL: This is the database software that we will use to store all the information required to keep the website running. Everything from customer details to product information and a host of other things will be stored in the MySQL database. Keeping with the trend of popularity, MySQL is also the world's most popular bit of database software with over six million active installations worldwide.

The package that we will use to get a complete web server (that includes all the above mentioned technologies) for the purposes of this book is called XAMPP .

Note

The XAMPP distribution is available at http://www.apachefriends.org/en/xampp.html.

Now that we know what we are using, it is important to take a quick look at how it is used. The following diagram shows a simplified view of how everything works, with the shaded section denoting the package containing the Apache web server, PHP interpreter, and MySQL database, with Drupal installed on the system:

So whenever a user does anything with your Drupal site (hopefully like contributing meaningfully), here's what happens:

  • The relevant information is sent to the server in the form of an HTTP (HyperText Transfer Protocol) request.

  • The server receives the HTTP request and says, Ah! This is a PHP page that has been requested. I need to send it off for processing by the PHP engine. The PHP page then gets processed and executed appropriately, and any actions that are required as a result of the user's request are performed.

  • Once that is done, an appropriate response is returned by the server to the user's browser, and the cycle continues.

There are quite a few methods of providing dynamic web content that don't rely on PHP server requests. Instead, processing can be done on the browser itself (features like this are often loosely termed Web 2.0), but what you have been shown here is fundamentally how everything works, even if there are exceptions to the rule.

 

Obtaining and installing XAMPP (PHP, Apache, and MySQL)


As mentioned in the previous section, we are going to make use of a package installation in order to simplify the task of creating a workable development environment. You will notice that most software installation is really about learning a single process and repeating it for whatever software you need. More often than not, you will:

  • Go to the software producer's site

  • Find the download page and download the appropriate package

  • Unpack the software or run the executable file, depending on the method of installation

  • Install and configure the software—most often you will be guided through the process in one way or another

  • Test your setup

Easy enough! Head on over to http://www.apachefriends.org/en/xampp.html and select the appropriate download link (that is, for Windows, Linux, Solaris, and so on). Select the desired package—generally the latest stable release. At the time of writing, version 1.7.3 was the most appropriate release, but you should feel free to use a later version, if there is one, as this will not affect the installation procedure.

Tip

Note that you should ensure that any package you use comes with versions of PHP and MySQL that are compatible with the system requirements of your Drupal installation. Drupal system requirements are available at: http://drupal.org/requirements

The download section should look like the following screenshot:

Click the EXE file link and, depending on your PC's security settings, you may get the following message:

Click on Save File to continue. At this point, you may take a break for a cup of coffee or tea if you have a slow connection as it may take a while—the download is in excess of 50 Meg.

Once the file has been downloaded, double-click it to begin the setup procedure. Follow the dialogs and ensure that you set the XAMPP options, as shown here (Note in particular, the first two options in the SERVICE SECTION are selected), before clicking Install:

Once everything has been done, you should receive a success message and the option to reboot. Save and close whatever important documents are open before clicking OK. Once the machine has restarted, you should have a whole list of new and exciting options to explore from the XAMPP option under Apache Friends in the Start menu.

Just to ensure that everything is going according to plan, navigate to http://localhost in your browser:

This confirms that everything is up and running as expected. One thing to make note of as it pertains to the previous screenshot is that all pages that are visible via your local web server (at http://localhost) are contained in what is known as the root folder.

Traditionally in Apache servers, htdocs is the root folder, and all the web pages that are to be made available must be placed inside htdocs. If a webpage is not in htdocs, then it is not possible to browse it.

From this, we know that we will have to locate the actual folder called htdocs on the file system in order to know where to put Drupal once it is downloaded. Assuming that you have gone with the default setup, you will find htdocs in the following directory (on Windows machines) along with everything else that was installed and created during setup: C:\xampp\htdocs.

In addition, it is worthwhile taking a look at one other facility that has been provided as part of the XAMPP installation because we're going to need it when it's time to install Drupal.

phpMyAdmin is a complete database management tool for MySQL and should be available to you at http://localhost/phpmyadmin. It can make life a lot easier whenever it is necessary to deal with data directly.

Note

If you are struggling to log onto phpMyAdmin or any other part of the site, then try using root as the username without providing a password. Note that you will probably be warned that it is not good practice to have a root account with no password—remember to set a password for root (by editing it under the Privileges tab) as soon as possible.

If you have access to phpMyAdmin, then our work here is complete because we now have a platform from which to begin building the Drupal site. Of course, we still need Drupal, so feel free to skip the following section and get going if everything is working on your system.

Troubleshooting XAMPP installation

There is generally one major stumbling block that prevents XAMPP from serving web pages normally. It occurs because other applications hog the ports that XAMPP uses in order to operate. If you found that towards the end of the XAMPP installation process, a warning message like the following was displayed:

It is likely that something else is preventing the Apache server from starting up properly. Often, the culprits are instant messaging programs or VoIP like Skype. XAMPP comes with a utility program that can help identify which programs are using which ports, allowing you to turn them off and retry the installation.

Go to C:\xampp (or wherever you installed XAMPP) and search for the port check utility, entitled xampp-portcheck.exe, and double-click on this file to run it. If XAMPP is correctly installed, you will be able to see something like the following:

Note that Apache HTTP, Apache HTTPS, along with MySQL all have ports, exactly as required by the server. If, for some reason, the HTTP and/or the MySQL services are not displayed here, then your web server will not be able to operate correctly.

If you see any other program running on the required ports (80, 443, and 3306), then close these down and retry the installation—if the installation was successful, you might want to try starting the Apache and MySQL services before re-installing the whole thing. Use the XAMPP control panel to manage services. It is accessible from the Start menu in All programs under ApacheFriends | XAMPP | XAMPP Control Panel:

If the control panel is already active, it will be available from your process tray under the XAMPP icon.

Often, programs like Skype will use the default port (80) if it is available, but will simply use a different one if 80 is already in use. So, once XAMPP is correctly installed, simply turning the other programs back on should work just fine, and you should not suffer any ill effects.

 

Obtaining and installing Drupal


Earlier in the chapter, we covered the Download page on the Drupal site; so there isn't too much to present us with problems at this point. Head on over to http://drupal.org/project/drupal and click the Drupal version number you wish to download—generally, the latest stable release is the one you want. Click Download to grab the latest copy and save it to your C: drive or your My Documents folder (or wherever you want).

Note

Drupal bugfix versions are represented by an additional digit after the main release version (that is, 7.1, 7.2, and so on). Bugfix versions should be used over the initial release for obvious reasons!

Now, the Drupal download is different from the XAMPP installer in that we will install Drupal ourselves; it doesn't come with its own installer .exe file. Instead, we are asked if we would like to Save (or Open) a .tar.gz file. In the event that your PC doesn't recognize .gz files (this is for Windows users), then download a zip program like 7-zip (http://www.7-zip.org).

Once you are ready, open and decompress the downloaded tar.gz file, then extract it to the htdocs folder of your XAMPP installation. To make life easier, perhaps rename the extracted folder to something more memorable and shorter than its default name, for example, I have simply called mine drupal, as shown in the following screenshot:

With that done, open up a browser and navigate to http://localhost/drupal. Remember to exchange the bolded section for the actual name of your folder in the htdo cs directory. You should be presented with the first page of the installation dialog, which looks like the following screenshot:

The Standard installation profile is fine for our purposes, so go ahead and click on Save and continue. For the purposes of this book, we will deal with English, but that's not to say that you can't install Drupal in a variety of different languages—simply click the Learn how to install Drupal in other languages link and follow the instructions. Otherwise, click on Save and continue.

Next, we have to ensure that Drupal's requirements are met. Drupal will present a list of what it needs, and anything highlighted in red must be dealt with before continuing:

In this case, the only serious problem is the fact that The settings file does not exist and further instructions are given below this message—we are to copy default.settings.php to settings.php in the sites/default folder.

Tip

It is not sufficient to simply rename the default.settings.php file, it must be a copy.

With that change implemented, we can click on proceed with the installation. The next batch of settings relates to the database that Drupal will use to power the site. Initially, the database does not yet exist, so let's create it quickly before continuing.

Open up a new browser, and navigate to http://localhost/phpmyadmin. Then enter the name of the database you would like to use for the site. Give the database either the same name as your site, or, if that is not a suitable choice for some reason, give it a sensible nickname, as shown in the following screenshot:

In this instance, you can see that I have specified a database name of drupal, which matches the name of the folder in which the new site is contained. Clicking Create brings up the following page and confirms that the new database now exists (although it still possesses 0 tables, as shown in the left-hand frame).

We can now continue with the Drupal installation. The database settings page looks something like that shown in the following screenshot:

Notice that I have referenced the database just created, specified the user as root, and provided the password I supplied upon setup of XAMPP (since this is the only user that currently exists in our pristine environment).

Note

Generally it is not a good practice to use the root superuser—I do so for expediency here. phpMyAdmin makes it easy to create new users from the master Privileges tab, and you are encouraged to add a specific user to this specific database.

Since we are using our own personal machine for testing and development, we can ignore the Advanced options link at the bottom of this page because the default settings are appropriate as it is. If you are using a database server that does not reside on your own machine, then these settings can be used to specify the host, port, and table prefix as required.

Note

A table prefix is prepended to the front of each table name in the database to prevent one installation from overwriting the tables of another. This can happen if, for example, another package using the same database has table names in common with Drupal's.

The following page allows us to specify some general administrative and configuration parameters:

Ensure that you can remember whatever information is provided here because these settings specify the Site maintenance account details. Forgetting them could mean a real struggle to get back into the site (it's not impossible, provided you have root access to the database and can access all the information directly from phpMyAdmin). The e-mail address used here should be one that is convenient and active and does not necessarily have to be a part of your new site's domain—anything will do.

Note

The site maintenance account (User 1) is all powerful and has complete control over Drupal! Never use this account for everyday use of the site. Instead, create new users with specific access permissions to perform day-to-day tasks. More information on how to implement proper access control can be found in Chapter 4, Users and Access Control.

It's easy enough to decide on the server settings, and the final Update notifications section can be left activated for your convenience later on. With that, hopefully you are presented with a clean bill of health, as shown in the following screenshot:

It's also quite possible that there are some rather alarming warnings or errors written in red at this point and the most common of these are dealt with shortly in the Troubleshooting the Drupal Installation section.

Everything else henceforth is concerned with configuration and customization, and if you have not experienced any errors or difficulties so far, please feel free to skip the next section.

Troubleshooting the Drupal installation

In this section, we will take a look at two of the problems most likely to occur during the setup process. We will also take a look at how they manifest themselves and how to solve them quickly. It should be noted that at this early stage, there are not many things that can go wrong as the installation routine is fairly well used. This is good news because it is likely that any errors are the result of typos or something quite simple, which should be easy to rectify.

Unfortunately, we can't hope to cover absolutely everything in this section; so we will also outline a brief process that can be used to solve any problem, and not just the ones involved with installation. Having a sound process to follow is immeasurably more valuable than being shown solutions to each and every problem.

If, while setting up the database, you received a message like the one shown in the following screenshot:

It is likely that you have made a typo in the Database name field or have not correctly created a new database for Drupal to use. Check that you have not made a typo and that you have created a database with the desired name by revisiting http://localhost/phpmyadmin.

You might also have come across this rather ugly looking message towards the end of the installation process, as shown in the following screenshot:

This error occurs when Drupal attempts to send an e-mail to confirm that the site has been set up, but finds that it is unable to do so. This problem is not critical because it doesn't prevent Drupal from completing its installation, but obviously, you would like the system to be able to send e-mails because they are useful for testing (and, of course, if you forget your password). The problem here is related to the environment itself and is not one specific to Drupal.

PHP has reported to Drupal that it is not able to send out the e-mail because it cannot find a suitable SMTP server. This is a common problem on Windows installations because unless an SMTP server is specified, there is no way PHP can decide for itself. To rectify this, open up the php.ini file located in C:\xampp\php and search for the [mail function] entries. Modify it to match an SMTP server that you have access to (for example, if you use Outlook, you can find the address of an SMTP server by viewing your account server settings):

[mail function]
; For Win32 only.
SMTP = mail.mysmtpserver.com
smtp_port = 25

Once you have made the relevant changes, save the file, and then restart the Apache server so that it can pick up the new settings.

Note

Restart the Apache server by opening up the XAMPP Control Panel from the start menu and click Stop; then Start next to Apache.

But what if something else has gone wrong? Another common source of errors pertains to Permission issues—the settings.php file in sites/default makes use of certain properties of PHP, and it is possible that there are conflicts here. Follow the instructions provided in the comments of this file if you suspect the problem lies here.

Note

To see which PHP settings are possible, including whether they can be set at runtime (such as when ini_set() occurs), read the PHP documentation at http://www.php.net/manual/en/ini.php#ini.list and take a look at the .htaccess file to see which non-runtime settings are used there. Settings defined here should not be duplicated there so as to avoid conflict issues.

Further than this, the types of problems that can occur are not easily isolated, so we have outlined how to go about solving them. The following list of points highlight a process that can be used to troubleshoot any problems:

  • Scrutinize any error messages you get and attempt to solve the problem yourself

  • Visit the Drupal forums and search for similar problems

  • Look through the troubleshooting FAQ at http://drupal.org/node/199

  • View the bug list (http://drupal.org/project/issues) to see if your problem is a reported bug

  • If you can't find bugs, similar posts, or problems, then try posting a focused and informative query on the forums and ask someone in the community to lend a hand

  • To supplement this, get on Google and try using relevant keywords to locate a similar problem, hopefully a solution will be presented

For now though, you should be ready to continue with the final few tasks in the setup process, which will be performed in the following section.

 

Drupal's post-installation status


It's worth noting before we continue further that it is often beneficial to have several development sites in order to play around with different things without mucking up other work. The process outlined so far in this chapter can be repeated as many times as you like to set up as many development sites as you need—simply create a new database (or, alternatively, provide any new Drupal installation with a table prefix in the Advanced options section) and add the Drupal files to the htdocs directory (ensuring that they have a unique name) before browsing the new folder and repeating the installation process.

No matter what you decide, the next step is to click on the Visit your new site link to bring up the front page. By itself, the front page is not of much interest, since we haven't added anything to it. However, in the left-hand column, there is a link to the Dashboard. Click on this to bring up the following overlay and select the BY TASK tab:

The dashboard can be viewed either BY TASK, as shown here, or BY MODULE. At the moment, viewing the admin section BY TASK is probably more intuitive, but at a later stage, you might find that having direct access to specific modules is more efficient, and in this case, the BY MODULE view will probably be more suitable.

Note

The plus icon adjacent to any overlay title allows you to quickly add this page to the shortcuts menu (directly below the black toolbar menu at the top of the page). If you find that you are constantly using a specific page, it makes sense to add it to the shortcuts for quick access.

Since the Dashboard is where the business of building and running a Drupal site occurs, let's take a look at what that page provides and how it is organized before we quickly look at how to make use of a section by way of demonstration.

The dashboard tasks are broken up into seven default categories that cover all the aspects of running the site (note that you can click on the actual category names to bring up their default pages and not only the sub-categories), namely:

  • Content: Search and administer all the site's content, including comments

  • Structure: Handle content classification with taxonomies, work with layout of content and functionality via blocks, manage menus, and create and manage different content types

  • Appearance: Work with the site's themes to produce unique interfaces

  • People: List and administer site users

  • Modules: Manage core and contributed modules including configuring, enabling, disabling, and uninstalling them

  • Configuration: Access all the configuration settings for your Drupal website—including people, content, system, media, and more

  • Reports: Keep your finger on the pulse with logs, error reports, updates, and other important report data

The price one pays for having a powerful and flexible system like Drupal is that it comes with, necessarily, a huge amount of options and parameters that need to be understood and implemented. Spending time learning and experimenting with these is one of the things that will take you from novice to pro. Ultimately, I'm sure you will agree that the organization of this array of features within Drupal makes it quite intuitive.

Right now, it's time to a have a quick look at one of the options just to get a feel of how things work. To get started, scroll down the dashboard page and check out the Status report—you will no doubt be presented with something that looks similar to the following screenshot (hopefully with no red involved):

This page displays information about the fundamentals of the Drupal installation. Anything showing in red needs urgent attention and action, while anything showing in yellow needs some attention. At the moment, the Drupal core update status is showing up in yellow, but with a close inspection of the reasons for the error, you will see that the problem is not that difficult to solve—the cron has not been run.

Note

Cron tasks are automated chores that Drupal needs to perform regularly in order to make sure that everything continues to run smoothly. In Drupal 7, they are handled automatically, but can also be run manually, if need be.

To deal with the cron issue, click on the Run cron link. This executes the cron script, and this section of the status page will now show up in green or red depending on what it finds out.

Tip

During development, it is a good practice to periodically run the cron so that Drupal can perform its internal maintenance tasks.

While we will be going over most, if not all, the elements of the dashboard at various stages in the book, I recommend you spend a few minutes familiarizing yourself with how and where various tasks are presented. It will save you a bit of time in the future.

 

Creating a basic Drupal page


Let's make some modifications to the site via the admin page to confirm that everything is working normally and to highlight how easy it is to implement very powerful features at the click of a button. We'll run through a few quick steps to get some interesting features along with some new content on the site and then view it all as any visitor to the site would.

Go ahead and follow these steps:

  1. Click on Modules in the toolbar menu. This will bring up a long list of modules that are available.

  2. Select Search, Poll, and Blog, then scroll to the bottom of the page and click on Save configuration.

  3. Click on Add content in the shortcut menu and then select the Poll option.

  4. Fill out an arbitrary question with some options, as shown in the following screenshot, and then click Save (don't worry about any of the other options available for now):

  5. Click on Add content again, but this time select the Blog entry option.

  6. Fill out the fields available with any info that pops into your head, and click on the Save button (again, don't worry about any other settings or options for now).

  7. Return to the Dashboard and select the Blocks option under STRUCTURE.

  8. Scroll down the page and make changes to the table shown in the following screenshot by dragging-and-dropping a BLOCK to a desired REGION.

  9. In particular, notice that the Most recent poll has the Right sidebar region selected, as does Recent blog posts.

  10. For convenience's sake, make sure you set User login. If you don't specify a REGION for this BLOCK, it will not show up when you log out and you have to manually navigate to http://localhost/drupal/user to get back in.

  11. For now, don't worry too much about taking this all in, we will cover it in detail at a later stage—this exercise is simply going to give us our first look at a basic Drupal web page and its layout.

  12. Once these changes are made, click on Save blocks and then Home.

The site should now look something like the following screenshot (minus the numbering):

There are several main areas of interest numbered in this screenshot, and we should look over them here in order to get a feel of what to expect in the chapters to come. Bear in mind that Drupal really doesn't impose many limitations on where and what you can place on any part of a web page, so the following explanation is really only a guide:

  1. The toolbar menu contains links to the main administrative areas of the website.

  2. The shortcuts menu can be used to add temporarily important links to help speed up navigation during administration. It can also be used by non-administrators to bookmark their favorite links.

  3. The page header contains your site's logo and slogan, among other things. It also provides a link to the landing or home page.

  4. (& 5) Left and right sidebars are predefined regions that contain blocks. Blocks are effectively containers of information or navigational links (or pretty much anything else you care to think of). Notice too that we now have blocks on the right-hand side (Most recent polls and Recent blog posts) because we set some of them to appear in the right sidebar earlier on. We told Drupal to display the User login in the left sidebar, but this is not visible because the screenshot was taken after login.

  5. Content is generally displayed in this region of a site and the method of display is customizable and selective as we will see in due course. Since we did not specifically tell Drupal otherwise when we created some content, what we created is displayed automatically—we could have told it not to make the post visible here at all if we liked; we will talk about how to control content in greater detail in Chapter 6.

  6. The footer often contains information that is not immediately the most important on a page but is still relevant and useful. You might get Drupal to display who is online here, but equally you could add a copyright notice, or terms of use, and so on.

This section has touched upon the power and elegance of Drupal by adding impressive features at the touch of a button and with little to no experience and certainly no programming skills required. However, it is quite possible that you don't want anything like what we have just seen. Perhaps you only want a single sidebar or none at all. Maybe you want advertising across the top of the page or content displayed in drop-shadowed boxes, whatever it may be, the coming chapters will see to it that you are equipped with the requisite information to implement your goals.

 

Summary


This chapter has served as an introduction to the world of Drupal as well as a backdrop for the rest of the book. The foundation from which to build a live site in the coming days and weeks has been laid. Having taken the time to set up a working development environment, you can be assured that any needless time wastage has been prevented.

With the facilities provided by XAMPP (Apache, PHP, and MySQL) installed on a test machine, we turned our attention to obtaining and installing Drupal itself—hopefully, you found that quite easy with the much improved installation features of Drupal 7.

Finally, we became acquainted with Drupal itself by adding new modules, posting some content to the site, and specifying where this content could be displayed on a typical page. In doing so, we were able to briefly discuss the anatomy of a basic Drupal page.

If you have gotten this far, then congratulations, you are ready to begin developing a new site. It's time to get your hands dirty.

About the Author

  • David Mercer

    David Mercer was born in August 1976 in Harare, Zimbabwe. Having always had a strong interest in science, David came into regular contact with computers at university where he graduated "cum laude" with majors in applied math and math.

    His technical books are now sold worldwide and have been translated into French, German, Polish, Greek, Spanish and many more. His book on Drupal 6 was reviewed on Slashdot and went on to become a best seller. Mercer's books are recommended reading at higher learning institutes like MIT, and he has a write-up on Wikipedia.

    He also maintains SME Pals, a blog dedicated to helping entrepreneurs and startups thrive online. SME Pals has become a recommended entreperneurial resource with many leading educational institutions because it has a strong focus on innovative business ideas and how to convert them into profitable startups.

    When he isn't working (which isn't that often) he enjoys playing guitar (generally on stage and unrehearsed) and getting involved in outdoor activities ranging from touch rugby and golf to water skiing and snowboarding.

    Browse publications by this author

Latest Reviews

(1 reviews total)
Good general information about Drupal 7
Book Title
Access this book, plus 7,500 other titles for FREE
Access now