Programming Drupal Part 1 - Setting up your environment
1 - 2
IntroductionConventionsStep 1. Install a minimal DrupalStep 2. Install DrushStep 3. Install some useful modules for developmentStep 4 - Final tweaksStep 5 - Explore the interface and DBStep 6 - Install a more development like theme (optional)Step 7 - ExercisesUseful links
Introduction
The goal of this series is show PHP developers the basics of programming Drupal. You will learn how to make pages, get data into and out of your own database tables, do forms, ajax and more. You will also learn to use some Drupal APIs and how Drupal does things. Developers like to do things themselves to understand how software works and that's what I want to enable. You're going to learn by doing.
In the first part of this series is about installing drupal and I'm going to focus on setting it up on Windows for two reasons, if like me you primarily develop on linux anyway, you'll be able to get this going easily enough yourself, and secondly I do not have an Apple computer. We'll install a minimal Drupal version then add some modules that are good for development, turn a few settings on and get to know one useful tool.
Conventions
I will write links to pages in this format
/admin/config/development/devel
Step 1. Install a minimal Drupal
Out of the box, Drupal is a PHP, MySQL/MariaDB/SQLite application so we just need a web server that supports PHP and a MySQL database.
If you are a windows user, then read my post install Drupal 7 on WAMP - but follow the instructions with one difference, namely install the minimal version of Drupal. WAMP will also give us phpmyadmin and webgrind which will be useful tools later on.
If you don't want to use WAMP, you could install Drupal on XAMPP a similar but cross platform installer, or just set up a apache vhost and get going. If you install Drupal following my other blog post, at Step. 5 remember choose minimal (see below).
When you have finished installing Drupal you will see this screen:
Click to enlarge
Note: You can see that I am running apache on port 81 because I had a port clash with Skype which also uses 80. I talk about this in the post Drupal on WAMP. Probably your apache is running port 80, it makes no difference to what we are going to do.
And looking in the webroot directory we have the following:
Click to enlarge
Step 2. Install Drush
Drush is a Drupal command line tool that will make Drupal development and maintenance much easier and you should get to know it from the beginning. Use the handy drush windows installer which will set everything up and put a shortcut on your desktop.
Drush works exactly the same way under linux, it just has a different installation. Clicking on the Drush desktop shortcut will start the 'Drush shell' which we will use shortly:
Step 3. Install some useful modules for development
Drupal has a quite a few modules that aid development, we are going to install some basic ones at this stage. I'll provide links to more advanced ones as we progress through this series. I'd like to outline two ways to install modules then choose one of the methods:
Method 1
Navigate to a module project page like this one for the Admin menu module, find the latest stable release:
and just click to download either a tar.gz or a zip file, then unzip this in the
C<span style="color: #339933;">:</span>\wamp\www\d7\sites\all\modules
directory of your Drupal installation. Then navigate to the page /admin/modules in your web browser, scroll down and activate the module you just downloaded by checking the check box and then saving the page.
Click to enlarge
OR
Method 2
Use drush which lets you download and enable modules from the command line. Drush makes it easy to update modules too, and when you're running many modules, trust me this is incredibly useful.
So let's use drush to install these useful developer modules. If you didn't start the drush command prompt already, find the drush shortcut on your windows desktop and click it. Then change to your drupal modules directory like this:
cd C<span style="color: #339933;">:</span>\wamp\www\d7\sites\all\modules
Listing the directory with
<a href="http://www.php.net/dir"><span style="color: #990000;">dir</span></a>
will show it to be empty. Now we'll use drush to download some useful modules namely:
- devel - essential developer module
- schema - useful when we come to do database work
- admin_menu - my preference over the standard Drupal administration toolbar, purely since I got used to it from Drupal 6 days and I like the development shorts on the left
- advanced_help - gives you easy access to module readme text. Some modules like Views have excellent API information in those help files, worth being able to see easily
Run this command which will download and unpack the code:
drush <a href="http://www.php.net/dl"><span style="color: #990000;">dl</span></a> admin_menu devel schema advanced_help
then enable them with
drush en admin_menu devel schema advanced_help
Enabling them this way is exactly the same as checking their checkboxes in the module list page and submitting that page. Let's now see what is in the module folder, from the shell type
<a href="http://www.php.net/dir"><span style="color: #990000;">dir</span></a>
which reveals our new modules to be there:
Now log in to your drupal development site again if didn't already. Remember the login url is /user/login and you should see this:
Click to enlarge
Incidentally, if you just type:drush
from the command line you can see a list of drush commands are available to you. Worth exploring.
So what do we now have?
- We have a minimal drupal install with some developer modules turned on but not yet fully configured
- We don't have a content type set up
- We have a default theme called Bartik
- Two user roles, anonymous and authenticated user
- Some simple features turned on by default from the theme settings page such as site name and logo
- Default blocks for the most basic functionality, i.e. top navigation, left navigation and a login form
- Database logging of events e.g. errors, users logging in, is turned on by default
Step 4 - Final tweaks
We've installed the devel module but the useful features aren't turned on yet, go to the devel settings page:
/admin/config/development/devel
And check these options:
Click to enlarge
refresh your Drupal page and scroll to the bottom where you should now see this:
We're in business.
Step 5 - Explore the interface and DB
My final suggestion is to have a look around the admin interface, trying logging in and out, see the differences and have a look inside some of the database tables. For example:
Admin interface url
Shows content from table
/admin/people/permissions/roles
role
/admin/people/permissions
role_permission
/admin/reports/dblog
watchdog
/admin/structure/block
block
Step 6 - Set up a more development like theme (optional)
This part isn't really necessary but it is possible that your Drupal installation still looks a bit too CMS like to you, and not like a raw development environment. Let's change that by setting up a different theme. Open the appearance page at this URL:
admin/appearance
and you could switch the theme to Stark which is a basic development theme included in the default install, it looks like this:
Or install a so called starter theme such as a href="http://drupal.org/project/basic">basic which is perfectly good for starting theme development.
We'll use Drush to install basic, navigate to the themes directory:
cd C:\wamp\www\d7\sites\all\themes
drush dl basic
drush pm-enable basic
if you look at the themes page, you can now see the new theme available to you.
Click to enlarge
We can set it as the default theme from there, or do it with drush.
drush vset theme_default basic
Refresh the page you're on and you should see something like this:
Click to enlarge
Starter themes like Basic are excellent for new site design. https://www.distribly.com, was based on the basic theme which enabled rapid theme development. Every theme has a settings page where you can tweak further and you can access the basic theme settings from this url:
/admin/appearance/settings/bartik
Incidentally, have another look in the block table now:
SELECT <span style="color: #339933;">*</span> FROM `block` LIMIT <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span>
and notice that we have entries now for the Bartik and Basic themes.
Step 7 - Exercises
These aren't programming tasks but you could try the following at this stage just to get to know the default installation a little more:
- Change the theme back to Bartik from drush and the admin interface
- Go to the blocks page and move a few blocks around
- Go to the blocks page, make a simple text block and set it to appear somewhere
- You could also make two blocks that appear for logged in and logged out states
- Turn the logo off and tweak other theme settings
- Have a good look around the database tables
That concludes part one of this series. In part two we start programming.
Useful links
Internal links
Drupal as an enterprise web application frameworkInstall Drupal 7 on WAMP
External links
http://drupal.org/documentation/develophttp://drupal.org/developing/moduleshttp://www.drupalgardens.com - set up a Drupal site or free online
Books
These books are more aimed at development:Programmer's Guide to Drupal - a good more high level introduction to Drupal developmentPro Drupal Development edition 1 for Drupal 6 - if you're doing Drupal 6 development, this is the only book you need, it is simply excellentPro Drupal Development edition 2 for Drupal 7. A bit of a let down in my opinion after the first edition, lots of copy and paste of new features without the excellent explanations there were in the first edition. The fonts and figures are smaller too.Drupal 7 Module Development - this is a great book for understanding what is new Drupal 7. You still need to get up to speed on Drupal development first though. I feel it is aimed at Drupal 6 developers who are moving to Drupal 7The Definitive Guide to Drupal 7 - a big book covering many areas including some good chapters on development
PHP IDEs / editors
PHPStorm - my favourite. Using the debugger just works.NetbeansNotepad ++Eclipse PDT
Next: part 2
Blog tags:
Link tags: