For those developers who spend most of their coding time with Microsoft development tools, the world of Linux/Unix is a scary place. In this chapter, I will cover various tools and configurations that make Drupal a friendly place for developers who prefer Windows.
There are systems out there that can make your Windows environment look like Linux. Cygwin comes to mind. But I, and a lot of Windows developers that I know, are not looking for that. People who develop on Windows are comfortable in their environment and don't want their beloved environment to look like Linux. They want to be able to use the tools they feel comfortable with and still get the benefits of the hard work done by the open-source community.
Windows developers have the same desires to give back to the community as the Linux-focused crowd, but the Windows zeitgeist is mostly fee for service. By showing the Windows developers that there's a community of openness and sharing in the Drupal world, they might have that incentive to give back and will expand the community as a whole.
So if you're a Windows developer, welcome to the wonderful world of Drupal!
If you prefer Linux, have some empathy for your brothers and sisters who prefer Windows. Don't discount them or force Linux on them. Rather, show them how they can live in their world and still be a part of a larger world of open-source developers.
I think Drupal 7 could be a way to introduce a massive group of really smart people into a mature open-source environment that they long for.
As you probably know, Drupal is written for the so-called LAMP stack, “Linux/Apache/MySQL/PHP.” While it is possible to substitute Windows for Linux, it is a bit more difficult to substitute IIS for Apache, and even harder to substitute SQL Server for MySQL. And don't even think about replacing PHP with C# or Visual Basic.
There are three different paths you can take to do your development in a Windows environment:
I'll cover the first configuration in this appendix. In my book, Pro Drupal 7 for Windows Developers, you can find more information about getting Drupal running on IIS and SQL Server.
I've been using Windows 7 running under VMWare, and so the screen shots and tools will be for that platform. Adjust for your system.
For my money, Visual Studio is the perfect development environment. Visual Studio, along with .NET reflection-based IntelliSense, fits my development habits like a glove; I can't imagine coding without it.
There are other development environments available for the Windows developer. Many of these, including Eclipse and NetBeans, were ported from the Linux environment and have a definite Linux feel to them. I tried these environments and, while they certainly have a richness about them, I found that none of them was as intuitive and easy to set up and use as Visual Studio. The problem was that Microsoft doesn't support PHP.
And then I discovered VS.Php from JCX Software (http://jcxsoftware.com/vs.php
). They sell a plug-in for Visual Studio that provides the same kind of environment for PHP as you would expect out of the Microsoft-supported languages C# and Visual Basic. VS.Php is less than a hundred dollars and can be used with the free Visual Studio shell.
VS.Php has all the goodness you would expect out of an add-in to Visual Studio. In addition to syntax coloring, you also get breakpoints, step-debugging, variable interrogation, and IntelliSense.
If you want to develop for Drupal (or any other PHP-based framework), then using VS.Php is a no-brainer. I'll be using this add-in to demonstrate the Windows-based Drupal environments.
After installing VS.Php into your existing Visual Studio environment, or creating a new implementation of the Visual Studio shell with VS.Php, you'll need to load a WAMP stack.
If you are using the VS.Php Visual Studio add-in, you've already got an instance of Apache, since VS.Php adds that on install. VS.Php also loads PHP. You don't, however, have a database instance. For a WAMP-based installation of Drupal, you'll need MySQL.
There are several freely available WAMP tools out there. I prefer WampServer (http://wampserver.com
), but you can use any other that you might already have installed or prefer for some reason.
Actually, all you need in addition to VS.Php is MySQL. You can install that by itself, but without a stand-alone Apache instance and PHP interpreter you will always have to go through Visual Studio to see your site. By having a full WAMP stack available, you can access your site without loading Visual Studio.
Tip By having a stand-alone WAMP server in addition to VS.Php, you can access your site simultaneously with Visual Studio/VS.Php and outside. This is handy, for example, if you want to test how a site would look in different browsers or even using different users logged on.
First, get the WampServer bits and start the installation. The version current as I write this is 2.1. Download the bits as shown in Figure F–1.
Figure F–1. WampServer bits from wampserver.com
When you install, you will be asked where to put the bits. It's probably best for now to take the default, which is c:wamp
, as shown in Figure F–2.
Figure F–2. Location of the WAMP bits
WAMP requires some administration privileges. Starting the WAMP server will probably require you to accept the UAC screen (see Figure F–3).
Figure F–3. UAC for WampServer Manager
Tip If you have Skype, you'll want to turn it off, as users have reported problems installing WampServer with Skype running. Skype uses port 80 (HTTP) as an alternative for incoming connections. If you want to use WAMP and Skype together, go into the Tools Options Advanced Connection panel in Skype and deselect the option “Use 80 and 443 as alternatives for incoming connections”.
To make sure everything has been loaded properly, go to a web browser and access http://localhost
. You should see the WampServer happy screen, as shown in Figure F–4.
This tells you that everything has been loaded, and it gives you the current versions loaded. If you have a problem, check to see if the WampManager icon is in the tool tray and that it is green. If it is not, then something in the stack didn't start.
The most common cause of this problem is that Apache didn't start. The most common reason for Apache not starting is that you have something else controlling port 80. The most common application that controls port 80 is Microsoft IIS.
If you have this problem, you can check to see who is sitting on port 80 by asking WampServer. Clicking on the icon will give you the WampServer control panel, as shown in Figure F–5.
Figure F–4. The WampServer default happy screen
Figure F–5. The WampServer control panel
On the Apache submenu, there is a selection to “Test Port 80” (see Figure F–6).
Figure F–6. Testing the HTTP port
This will bring up a command window so you can see who is using that port, as shown in Figure F–7.
Figure F–7. IIS is using port 80
If you want to fix this, you'll need to turn off IIS: go to Computer Management. I usually get there by typing iis
in the Search programs and files area of the Start menu. This will bring up the IIS control panel. On Windows 7 it looks like the screen shown in Figure F–8.
Here we can see that, indeed, IIS is using port 80. Clicking Stop should release that port so Apache can use it. It is possible to run Apache on a different port, but I would not recommend it, especially while you are possibly learning a new environment.
Now that your WAMP environment is set up, it's time to load the Drupal 7 core code. The most direct way is to go to http://drupal.org/project/drupal
. There you can see all of the currently supported versions, both in .tar.gz and .zip
formats. For Windows users, the .zip
format is probably the easiest (see Figure F–9).
Figure F–9. Current Drupal distribution on drupal.org
Windows Explorer will open the .zip
file, as shown in Figure F–10.
Figure F–10. The Drupal distribution as a .zip
file
Extract the folder into a convenient location. I use c:wampwwwdrupal-7.0
, but you can put it wherever it feels good to you (see Figure F–11). You'll need to reference this directory in the next step.
Figure F–11. Extracting the .zip
file
Now you'll need to tell Apache where to find Drupal. This is done by using Apache's configuration file, httpd.conf.
WampServer provides a convenient method to edit the file from the WampServer Manager application, as shown in Figure F–12.
Figure F–12. Editing Apache's configuration file
This will bring up Notepad and allow you to edit the configuration file (see Figure F–13).
Figure F–13. Setting Apache's directories to point to Drupal
There are two lines that you need to update in this file. One is DocumentRoot
and the other is <Directory>.
Set these both to the directory where you extracted the Drupal programs.
To do this, simply search for the two strings, one at a time:
DocumentRoot "c:/wamp/www/drupal-7.0/"
<Directory "c:/wamp/www/drupal-7.0/">
CautionThere might be more than one entry starting with <Directory.
Be sure to modify the one that has an attribute. Also be careful to properly quote the value. This is an XML document and is very sensitive to the XML well-formedness constraints.
Once this is done, save the file and restart Apache to read the edited file (see Figure F–14).
Figure F–14. Restarting Apache
Note If your service doesn't restart, the most likely culprit is a misplaced quote or angle bracket in your configuration file. As I mentioned before, the XML parts of this configuration file are pretty sensitive to syntax. Just open the file again and check to see if everything looks right.
Once this is done, go to http://localhost
again to see if everything is configured correctly. If so, you should get the Drupal installation screen (see Figure F–15).
Figure F–15. The Drupal installation screen
From here, configuring Drupal is the same as under a typical LAMP installation. See Chapter 1 for information about how to configure a standard Drupal installation.
Once you have your WAMP stack running, it's time to load Visual Studio and the VS.Php add-on, if that's the development environment you have chosen.
I use Visual Studio 2010, but VS.Php supports older versions of Visual Studio as well. Plus, there is a distribution of VS.Php that has the free Visual Studio shell in case you don't have a full license of Visual Studio installed. I'll cover that version in this section.
Get the VS.Php bits from http://www.jcxsoftware.com/download.php
. If you are using the free Visual Studio shell, you'll want to get the Web installer (see Figure F–16).
Figure F–16. VS.Php installer site
If the installer doesn't detect Visual Studio on your machine, it will offer to install the shell, as shown in Figure F–17.
Figure F–17. Installing the free Visual Studio shell
This is by far the cheapest way to get started with Drupal on Windows. As of this writing, VS.Php is a free 30-day evaluation.
Tip If you elect to install the Visual Studio Shell from the VS.Php installer, you may get a request for a restart. When you come back up, you'll have to start the VS.Php
installer again.
The VS.Php installation is pretty straightforward. It's probably safe to take the defaults for now. You should end up with the happy screen shown in Figure F–18.
Figure F–18. VS.Php happy screen
Once VS.Php is installed, you can start VS.Php, which will start Visual Studio and then add itself to the development environment. Now we need to tell VS.Php about the Drupal code. From Visual Studio, select File New Php Project from Existing Code.... You will probably get the nag screen for the 30-day trial. After that, you will see a wizard that prompts you for the location of the PHP code (see Figure F–19).
Figure F–19. New project from existing PHP code
You can pick PHP version 5.2 or 5.3; both are supported by Drupal 7.
Since you have a new language, you'll want to tell Visual Studio how to handle the source code. The settings that follow are compatible with Drupal's code formatting conventions. In Visual Studio, go to Tools Options, and then expand to Text Editor PHP Tabs (see Figure F–20).
Figure F–20. Making sure tabs are consistent with Drupal tab rules
Drupal's code formatting conventions require two spaces for indents and that the spaces should be kept instead of inserting the tab character. Now let's tell Visual Studio that there are some additional file extensions that it should know are PHP code files. That is found under File Extensions on the same screen (see Figure F–21).
Figure F–21. Adding filename extensions
Add the .info and .module extensions and click OK.
Note Coding standards for the Drupal community are consolidated in a single link, drupal.org/coding-standards
. As a new Drupal programmer, it would be a good idea for you to familiarize yourself with the standards so as to not be labeled a noob.
Now let's try to run the code from within Visual Studio. Set a breakpoint at line 21 of index.php
, as shown in Figure F–22.
Figure F–22. Setting a breakpoint in PHP
Now press F5
to debug. You might get an error indicating a problem with starting the web server. Just dismiss this and try debugging again. Once things start loading, you might get the screen shown in Figure F–23.
Figure F–23. Configuration error
There are two things to check to resolve this:
.htaccess
file that is not recognized by the Apache engine. Open the .htaccess
file, which is in the same directory as your base Drupal install, and comment the line that has the word Order
in it (see Figure F–24).Figure F–24. Correcting the .htaccess file
Putting a hash (#) in front of the line makes it a comment.
Tip VS.Php keeps its own set of log files. In Windows 7, the error log is found at C:Users{your user name}AppDataRoamingJcx.SoftwareVS.PhpApache2drupal-7.0logs.
Save the file and press F5
again to debug. If everything goes right, Visual Studio should stop at the breakpoint you set in index.php.
From there, you can step through the code, interrogate variables, check the call stack, and anything else you can do with your favorite .NET language (see Figure F–25).
Figure F–25. VS.Php turns Visual Studio into a PHP debugging environment
As I mentioned before, MySQL comes packaged with WampServer. MySQL comes with a tool that will allow you to manage your database server. You can create and delete databases, create and query tables, and manage users and permissions. This tool is called phpMyAdmin
and is available from the WampServer console (see Figure F–26).
Figure F–26. Accessing phpMyAdmin
This launches your default browser and presents your MySQL database, as shown in Figure F–27.
Figure F–27. phpMyAdmin screen
If you would rather use Visual Studio to manage your database server, you can install the MySQL Connector for .NET, which is available for free at http://dev.mysql.com/downloads/connector/net
. This will install itself into Visual Studio and give you the same kind of functionality you are accustomed to with the Visual Studio Server Explorer (see Figure F–28).
Figure F–28. MySQL Connector for Visual Studio
At this point, you are ready to start the learning process. Step through the code, interrogate variables, and watch how the database interacts with the code. I find this the best, fastest way to learn a new environment. And all from the comfort of your favorite Windows development environment.
In the next section, we will install a tool that has become indispensible to many Drupal developers. That tool is Drush.
Drush, the “Drupal shell,” is covered in Chapters 2 and 26. Drush is a set of PHP programs that will make your Drupal development experience a lot easier. Drush requires several Linux–y tools to run. On a Linux machine, these are probably already there and all you need to do is to download the Drush code.
Unfortunately, the standard Windows machine doesn't have all of those tools, so you'll need to install them on your machine. This is sort of a hassle, but I guarantee you, if you spend a few minutes now getting this environment set up, you will save far more time as you start developing your Drupal applications in a Windows environment.
Here is a procedure for getting those tools loaded and running.
First, download the Drush bits at http://drupal.org/project/drush
. Grab the latest version (see Figure F–29).
Figure F–29. Download the Drush bits
Unzip the files into a convenient directory. I use c:drush.
We'll add that to our environment path a little later.
Now, we need to get the Drush prerequisites. These are all open-source tools, and they each have Windows binaries with an installer. The download page for first one, libarchive
, is shown in Figure F–30. It is located at http://gnuwin32.sourceforge.net/packages/libarchive.htm
.
Figure F–30. Download page for an open source tool
Grab whatever flavor you want. I usually just download the Setup program for the complete package. Run the setup program and take the defaults (see Figure F–31). This will install your program but won't make changes to the path. We'll deal with that in a moment.
Figure F–31. Setup program for open source tools
You'll need a total of four GNU packages to make Drush work:
http://gnuwin32.sourceforge.net/packages/libarchive.htm
http://gnuwin32.sourceforge.net/packages/gzip.htm
http://gnuwin32.sourceforge.net/packages/wget.htm
http://gnuwin32.sourceforge.net/packages/gtar.htm
Now we need to set the PATH
environment variable to include the Drush, PHP, and binaries installed. To do this, you need to get to the Environment Variables screen. This is different depending on your OS. Right-click Computer and select Properties. Click Advanced system settings and then Environment Variables…. You will see the screen shown in Figure F–32.
Figure F–32. Environment variables dialog
Under User variables, click New…, and you will see the New User Variable window, shown in Figure F–33.
Figure F–33. User variable dialog
Enter path in the variable name and the new directories in the Variable value field. Be sure to include the path to a compatible version of PHP, since Drush will be using that. I used C:drush;C:Program FilesGnuWin32in,
but your system might be different.
The semicolon separates the paths. Paths are those to where the following files are located: php.exe
, drush.bat
, and the tar/gzip/wget
binaries.
If you have a command prompt window open already, you'll need to close it and open another one in order for it to read the new path.
Now let's test to see if we were successful in installing Drush and its prerequisites. Using a command prompt window, change to the directory just above the “modules” and “themes” directories. Mine is C:wampwwwdrupal-7.0sitesall
.
Type drush at the command prompt. You'll get a nice long list of the wonderful things you can do, as shown in Figure F–34.
Figure F–34. Drush help screen
Note I have gotten a message on some machines indicating that a particular DLL is missing.
I don't know exactly why this happens, but you can download the DLL at www.dll-files.com/dllindex/dll-files.shtml?msvcr71
.
If this works for you, you have just made your Drupal experience a lot more productive. Drush helps you do a lot of things that would otherwise require a lot of mousing around.
Drush knows where the Drupal projects are out in the ‘tubes. It also knows the database location and login information by reading the settings.php
file created by the installer. Because of this, it can perform these administrative tasks without requiring the GUI. That means, of course, that anyone who has access to Drush and your directory structure can do the same thing. Standard security precautions are applicable.
Drupal was originally designed to run under the LAMP stack. Much progress has been made in the standardization of the code to make it possible to move beyond that particular technology stack. With Drupal 7, it is possible to use different web servers and databases. In this appendix, we did just that, replacing the “L” in LAMP, Linux, with Windows. To learn more about working with Drupal on Windows, check out http://drupalforwindows.com
and check out my book, Pro Drupal 7 for Windows Developers. There is also a Drupal group dedicated to Windows developers and administrators. It is http://groups.drupal.org/drupal-windows
.
I expect that there will be a lot of demand for Drupal running under Windows with the WISP stack, and that a Windows-focused community will appear and champion this platform to make Drupal even more popular than it already is.
3.141.21.108