Although several books have been written about Drupal 7, most have been written for developers to help them program sites using Drupal coding standards, enhance sites by using custom modules, and change the appearance of Drupal sites by using themes. In this book, we take a different approach. Throughout the book, we will develop a website for a (fictional) business and meet the needs of this business.
We have included an explanation of all the key features in Drupal that most small-to-medium-sized businesses would want to use on their sites. A thorough step-by-step description of how to integrate each piece of functionality into your website is included, along with an explanation of the business need that is being satisfied by using the functionality.
After reading this book, you will be able to adapt the techniques used in this book to either develop a site for your company on your own, or work with a development firm to create a website that truly meets the needs of your business.
In this chapter, we will introduce our client, the Artisan Bakers Collective and discuss their plans to build a website. We will also introduce Drupal 7 and describe why it is a good fit for our client's website.
In this chapter, we will cover the following topics:
Plans for the Artisan Bakers Collective website
The advantages and disadvantages of simple, static web pages
Advantages and disadvantages of customized PHP and MySQL sites
Deciding on Drupal for building the website
Getting started with Drupal
Baker James is the owner of the Artisan Bakers Collective, a popular artisan bakery, cafÃ©, and store. The past few years have been very good, and he has expanded from one bakery to three. Each bakery is decorated in a retro theme and Baker James is extremely proud of the decor. The Artisan Bakers Collective offers a wide variety of breads and baked goods, but specializes in creating sourdough bread using traditional European-style slow-rise recipes handed down over generations.
Baker James wants to add an e-commerce component to his business, so that he can reach a larger clientele, which he feels will bring in additional revenue. He also gives baking classes and would like to promote this.
Baker James had a website designed for him several years ago, but it has proven to be difficult to maintain and is therefore several years outdated. James would like to build a new website for his businesses that is easy to update and maintain. He would like to provide a destination for his customers where they can visit his bakery online, learn more about the bakery, find out about classes, events, and the featured breads, and receive discounts, if they are loyal customers.
Baker James has several key goals for his site, which are as follows:
The site must provide an easy method for updating its content so that it's always current
Baker James should be able to make updates to the website without having to pay a consultant to do so
He should be able to run a secure and stable website that uses current website development standards
The overall website should be easy to maintain in terms of keeping Drupal modules updated and keeping the site secure and stable
It should be possible to add new functionalities to the website without requiring a complete start over
After Baker James came to us expressing his desire to have a new website built, we sat down with him to determine what pages and sections should be added to the website, so that we can plan our development. Based on these discussions, we decided on the following features for the site:
Pages : This includes pages highlighting bread, other baked goods, and coffee. There will be one method for creating pagesâa simple method where each page is developed independently, using a form (in Drupal), that is simple to complete.
Guest Book : This allows visitors to comment on the bakery and give feedback. Baker James can see when new comments are added, and he can optionally remove comments if they do not meet the site's standards.
Monthly Newsletter : This is a newsletter that visitors can subscribe to. Baker James will be able to create the newsletter content on the site. Customers can also view the previous editions of the newsletter.
In this section, we will explore a range of possible technologies that could be used to build the Artisan Bakers Collective website. The pros and cons of each method will be discussed, and we will choose the final technology that will be used to build the website.
Many websites continue to be built by simply creating standalone HTML pages that do not change frequently over time. These pages can be created with a dedicated website design program or with a simple text editor. These pages are then uploaded to the web server, using an FTP client or another transfer client provided by the web host.
There are several advantages of using this method of web development, listed as follows:
HTML web editor software can make creating web pages as easy as writing a letter, since the interface is similar to Microsoft Word
Website editors may provide pre-built themes to make the website appealing, without any graphical design experience
It is a very easy way to get started
For simple sites, simple techniques are sometimes appropriate
A website can be created relatively quickly
Websites can be built for free or for the cost of a website design program
The hardware requirements are very low, so the website will run on nearly any host
Although static web pages can be easy to develop, there are a number of disadvantages that appear after you deploy the website and try to make revisions to it later. The disadvantages are listed as follows:
Adding a new page to the website may require changes to all of the existing pages on the website
Changing elements that are common to all pages, such as the header or the footer, may require changes to every page on the website
When major changes are needed to the website, it may be easier to rebuild the entire site
It is easy to have errors within the website, leading to pages that cannot be reached, or errors that the visitor may encounter. These errors can include broken links and images, and broken navigation menus
Advanced functionality cannot be added without custom programming
Created code can be inefficient or incorrect, leading to websites that do not display properly in all browsers
Security and optimization techniques created by other developers are not automatically applied to your site
You could also build a fully-customized website, built entirely from scratch, using a programming language such as PHP and a database such as MySQL. In this type of system, one or more programmers build custom code specifically for your website. Some common libraries may be used to speed up development, but the majority of the site will be custom-created.
There are several advantages to developing a completely custom-built website for your company, which are listed as follows:
The final website will be fully customized to meet the exact needs of your company
New functionality can be added by another programmer, who is skilled in the same programming language, at a later date
Complex functionality may be easier to develop, when starting with a clean slate
Unfortunately, developing a completely custom website is a difficult, time-consuming process and has several disadvantages. They are listed as follows:
Relatively lesser-skilled programmers may create a website that is difficult to maintain and enhance
Changing the look and feel of the website may require significant re-work, unless the site is designed to allow customization
The website may require a great deal of work by programmers to create and maintain
Security flaws may be inadvertently introduced, which could compromise the overall server or private data of your customers
The site may require more hardware resources than simpler sites and may require significant resources to run at acceptable speeds
Creating all of the functionality from scratch can prove to be very costly
Drupal is an open source content management framework based on PHP and MySQL. To use Drupal, you need to install it onto your web server. After it's installed, you use Drupal to create and edit pages. Drupal handles most of the common functionalities that are needed to build websites of any size, and also handles many complex functionalities with the help of plugin Drupal modules, including:
Although these features alone are sufficient to handle many sites, Drupal also offers a powerful module system that allows developers to create modules that plug in to the core Drupal framework to seamlessly provide new capabilities. Many modules have been created by the Drupal open source community and released for use under open source licenses, free of charge. Modules are available for nearly every conceivable task, but if you don't find what you are looking for, a custom module can always be created to handle your exact needs.
Drupal also provides a powerful theme system that allows you to change the look and feel of your website and have all of the pages changed throughout the entire website, instantly. Hundreds of free themes are available on the Drupal website, and these can be customized to fit your needs. Alternatively, you could develop a custom theme for your own website. Commercial themes can also be purchased.
Drupal offers a number of benefits not found with the other methods of building a website. Many of these are related to the ease of maintenance and the ability to concentrate on business functionality rather than building common, repetitive functionality. The benefits of Drupal are listed as follows:
You are free to concentrate on building content and functionality to support your business rather than creating basic functionality already provided by Drupal
The look and feel of the website can be easily changed without rewriting the entire site or changing all of the pages
All changes to the website take effect immediately, so you can ensure that the changes are correct
Changes can be previewed prior to the website being updated, to make sure that it works properly
Revisions to pages can be tracked, and you can require pages to go through an approval process prior to being made viewable
You do not have to use FTP or other methods to deploy pages to your website. You can also use more stable and secure methods of deploying entire Drupal sites, using tools and software, including git and SVN.
Development costs are low, as Drupal is available free of charge
There is an active community that can help to answer any questions that you may have
Drupal is actively maintained and enhanced, which helps to ensure that potential security issues are rapidly found and fixed
Drupal can be used effectively by a wide range of people, even if they do not have any programming experience
Site management can be delegated to a team of people, who can share responsibility for the entire website between them or take individual responsibility for specific areas within the site
As Drupal is constantly being maintained and updated, you can gain access to new technologies more rapidly
Although Drupal is a very powerful tool, its very power causes a few disadvantages:
A short learning curve is needed to get started and use the system effectively.
It is more hardware-intensive than basic static pages. As it's more hardware-intensive and can create performance issues on a server, you may need to make sure that your organization or business can handle the expense of upgrading a server and the overall server infrastructure to support the site. This may include more expensive hosting options
Additional programming may be needed to customize Drupal modules to do exactly what you want. Alternatively, you may have to compromise on desired functionality, based on what is actually available
Drupal may be more vulnerable to security issues as there are a large number of sites that use Drupal, and hackers may target Drupal sites as it's a popular open source software used by many site developers
Along the same lines as security, Drupal sites require frequent module and software updates in order to keep the website secure and stable. This is extremely important in order to keep your Drupal codebase secure
There may be limitations to the framework, which could make building custom functionality more difficult
As you may have guessed from the title of the book, we are picking Drupal, and specifically the latest version, Drupal 7, to build the Artisan Bakers Collective websites. Drupal gives us the best combination of functionality, flexibility, security, and ease of use, for our website. In fact, Drupal is an appropriate choice for a range of websites from small sites to large sites and everything in between. Many large-scale enterprise businesses, non-profit organizations, and private companies are using Drupal to power their website. For example, the White House is using Drupal. Chances are, if you are planning to build a website, Drupal will fulfill all of your needs.
At one point it was more complex to search out modules to use on a Drupal site, and this was looked upon as a disadvantage, but in this book, you'll see that it's actually much easier to locate good stable modules to use in Drupal 7.
In this book, we will jump straight into using Drupal to build a practical website, and not spend a lot of time talking about basic functionalities, the design of Drupal, or theoretical aspects related to Drupal. We will use Drupal 7, the most recent active version of Drupal, throughout this book. Drupal 7 is continuously in development, while Drupal 6 is also still supported and available for use on sites. The roadmap for Drupal already shows that Drupal 8 is in the planning stages.
To start using Drupal, we recommend setting up a development environment on your local desktop (either on your PC or on your Mac). You can develop the website for the client on your local computer using a local server, powered by MAMP (MySQL, Apache, and PHP for Mac) or WAMP (the same for Windows). This allows for quick and robust local development. When you're ready to show the client the site, you can easily transfer the Drupal site files and the database over to the client's web host.
You can also install the Drupal Development Desktop Stack that Acquia provides for download. They call this the Dev Desktop (http://www.acquia.com/products-services/dev-desktop), and it packages the entire Drupal core with PHP, MySQL, and an Apache web server.
This section will assume you have chosen either MAMP or WAMP to install on your local computer. We'll be installing Drupal into the web root of your local environment, which is usually
You're also going to need to set up a database for your Drupal 7 site to use, since Drupal is database-driven. To do this, navigate to your localhostphpMyAdmin application. In MAMP or WAMP, this is easily located through the MAMP or WAMP control panel.
Follow the given instructions for setting up your database:
Open phpMyAdmin and click on the Privileges tab.
Click on Add a new User:
Type in a User name (here I'll enter the username drupal7); set Host to localhost; and type in a password. Re-type the password.
Select the Create database with same name and grant all privileges radio button.
Then click on the Check All link.
Click on the Go button, to create the database:
Jot down the credentials from above, as you'll need them when you install Drupal.
Your blank database is now created and you can now move on to installing Drupal.
You can use the following steps to install Drupal:
Navigate to http://drupal.org, through your web browser. Click on the Get Started with Drupal button.
On the next page, click on the Download Drupal 7.8 button. This will launch a Download & Extend page. You want to download the 7.x version of Drupal, so click on the
tar.gzdownload link to start the download. Save the
tar.gzfile to your web root directory. At the time of this book's release, the Drupal version is 7.8. It may be a different 7.x version when you go to download it.
After you download the Drupal installation, you will need to unpack it. The installation is delivered in
tar.gzformat, to unpack which you may need a specialized tool, such as 7-Zip or WinZip. 7-Zip is a freely-available program designed to work with a wide variety of compressed file formats. On the Mac, you should be able to unzip the file by default, without having to download any tools.
You can rename the
drupal-7.8folder to be more specific to the site you're building. Let's rename the folder
You can now browse to the location where you have installed Drupal in a web browser, to begin the installation process. If you are installing on your localhost environment the URL of the install will be something similar to
http://localhost/artisanbakers/install.php. You should see a screen similar to the following screenshot, asking you to Select an installation profile.
Leave the installation profile Standard selected, and then click on the Save and Continue button:
Leave English set as the default language and click on Save and continue:
The next screen will ask you to add your MySQL database credentials for the database you originally created for the site. First, make sure to leave the MySQL, MariaDB, or equivalent radio button selected. Now, add your credentials, including Database name, Database username, and Database password, here. Once you add the credentials, click on Save and continue.
There may be a case where you need to add Advanced Options for your database connection. If you are going to be installing and hosting the database on an external server you'll want to expand this Advanced Options fieldset and add the path to the externally-hosted server. In our case, we're hosting the database on the same localhost server, so we do not need to expand this fieldset now:
Drupal will now proceed with the install.
The Configure site screen will load next. This screen is split up into various fieldsets. First, you want to give your site a Site name and Site e-mail address. The site name can be Artisan Bakers Collective. For the site e-mail address, type in your e-mail address, for now:
Now, you need to set up the Site Maintenance Account. This first user account on the site is the super-user administration account. You'll use this account to do all the site development and, later, to maintain the site. For now let's call the super user "admin", so type in
adminas the username. You can use the same e-mail address you used previously. Add a password.
The password should be strong and include special characters, such as, # or @. You may also want to use capital letters mixed with lowercase ones and also add numbers to the password. Drupal will check the password, using the password strength visual prompt, and this will assist you in constructing a strong password. This is essential for keeping your site secure.
For Server Settings, choose the Default country and Default time zone for where you are located. This will automatically use the time zone of your country for all date- and time-related functionalities on your website.
Lastly, leave the checkbox next to Update Notifications ticked, to check for updates automatically and receive e-mail notifications.
Click on Save and continue.
The installation will complete and you'll see a congratulations screen. Click on the Visit your new site link, to launch your Drupal 7 website:
You've successfully installed Drupal 7 and actually already have a fully-functional core Drupal 7 website for your client's business. In Chapter 2, Creating the Artisan Bakers Collective Website, we'll dive right into the Drupal 7 interface and start adding our client's content and setting up the website, as per our client's requirements.
If you want to see an example of the techniques used in this book as well as a live example of the complete website, you can visit http://variantcube.com/artisanbakers/. This site contains all of the examples developed throughout the course of this book. If you have questions about how to use Drupal, please post them on the forum at http://variantcube.com/artisanbakers/forum, and I will try to answer your questions, as quickly as possible. You can search on Drupal.org, using the site's default search box. Alternatively, you can visit the Drupal forums at http://www.drupal.org/forum, to see if you can find an answer to your question; if not, you can post the question to the Drupal.org community.
In this chapter, we developed the requirements for Baker James' Artisan Bakers Collective website. We also looked at some of the possible methods of building the website, before deciding that Drupal is perfectly suited for this type of site.
Now that we have our requirements for the website and have decided to build it using Drupal, it's time to get our hands dirty and begin building the website. In this chapter, you successfully installed and configured a development server environment and also installed Drupal. Congratulations! You should be proud of the work you have accomplished so far!
We will start with the basic functionalities that 99 percent of the websites need and then gradually move on to more complex tasks. We will use a step-by-step approach to building the site, so that you can follow along with the examples.