Windows Development Environment
Total Page:16
File Type:pdf, Size:1020Kb
A P P E N D I X A ■ ■ ■ Windows Development Environment For those developers who spend most of their coding time with Microsoft development tools, the world of *nix is probably a scary place. 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. This appendix provides a step-by-step tutorial for setting up a debugging environment on your Windows workstation. My goal was to duplicate the development environment of Visual Studio, and this set-up gets about as close as you can. Old habits die hard, and if you’re like me you’ve got some. I’ve been using a Windows-based computer since Windows was first available as an application that ran under DOS. As with most technologies, Windows and I have a love-hate relationship, but for some reason I keep coming back. Visual Studio is the perfect development environment. My development editor of choice was once VEdit, an emacs-style editor. I reluctantly switched to Visual Studio to do Visual Basic 6 programming, and learned to love IntelliSense. With Visual Studio 2010 and the .NET reflection-based IntelliSense, I can’t imagine coding without it. After the Windows Vista debacle, I seriously considered switching to Ubuntu or Macintosh. If Microsoft couldn’t get its core operating system right, how long would it be until everything else suffered? Windows 7 changed my mind. From what I see, it is as slick as Macintosh OSX and more secure.1 It is much better supported than Ubuntu, a Linux distribution that is growing in popularity. Windows 7 runs all of the software I already have, on hardware I already own. WAMP Stack Back to Drupal. The LAMP stack (Linux, Apache, MySql, and PHP/Perl) prefers Linux, and most developers have their development environment on some Linux GUI such as Ubuntu. I started there, but found I was missing some things I had become accustomed to in Windows. Fortunately, I’m not alone; others before me have gotten their Apache/MySQL/PHP stack working on Windows. They call this "WAMP" and it works quite well. I’ve worked with two different WAMP stacks, XAMPP and WampServer. Both use the same core packages (Apache, MySQL and PHP), but have different control panels. I prefer WampServer simply because it’s easy to switch between PHP versions 5.2 and 5.3. 1 http://lifehacker.com/5518787/famous-hacker-calls-windows-more-secure-than-mac 307 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT As far as a development environment goes, Microsoft doesn’t support PHP out of the box. There has been some talk over the years, and I’ve even seen some snippet libraries and at least one attempt at making PHP a .NET-compatible language. Development Environments I’m not so interested in using PHP as a .NET language because the most likely eventual target for my PHP code will be a Unix-compatible server. All I want is an integrated development environment (IDE) that lets me work quickly and debug, and provides a platform for documentation. I’ve explored several different tools, all of which are available on the Windows platform: • Eclipse: Eclipse is an open-source development environment designed for developing in almost any language you can imagine. It is written in Java and was initially designed to attract Java developers. There are hundreds of add-ons available, and that’s where I got stuck. Simply configuring an Eclipse environment required such a learning commitment that a lot of the time I had budgeted for learning Drupal was spent just figuring out the differences between all of the competing add-ons, and then getting them to work together. • NetBeans: NetBeans is similar to Eclipse in that it is an open-source solution and its adherents are strong supporters of the platform. Unfortunately, I found the same learning-curve problems with NetBeans as with Eclipse. • Komodo IDE: Komodo is a commercial product made by ActiveState. ActiveState provides support to get you up and running, so you don’t have to go through the learning issues to choose which peg fits into which hole. However, Komodo IDE is not free. At the time of this writing, the tool is US$295. That’s a pretty cheap price if you consider the time you’d have spent figuring out how to use a "free" tool. Another advantage of Komodo is that it runs on all popular platforms. You need just one license to run its code on Windows, Linux, and Macintosh, and the user experience is similar in all cases. • VS.Php: In doing my investigations, I stumbled onto this add-in for Visual Studio, and it became my preferred environment, by far. It is a commercial product, published by a small company called JCX Software. VS.Php takes advantage of all of Visual Studio’s features and provides step debugging, IntelliSense, team collaboration capabilities, and more. At the time of this writing, the software is US$99, but it requires Visual Studio. Fortunately, it can be used with Microsoft’s free Visual Studio Shell. The trick is to get all of these pieces to work together, on your preferred platform, with a development environment that allows you to debug and walk through the code. In this appendix, I’ll cover the prerequisites for getting Drupal running on your Windows development box. I’ve been using Windows 7, so the screen shots and tools will be for that platform. Adjust for your system. There are four parts to the LAMP stack, and we will be twiddling with the first three. First, we will replace Linux with Windows and get a system up and running with Apache web server, MySQL database, and PHP. As I mentioned before, this configuration is called WAMP and it is the most stable. After that, we’ll install the same Drupal code, but we’ll replace Apache with IIS and MySQL with SQL Server. 308 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT WampServer Many tools are needed to create the WAMP stack on Windows. Fortunately, someone has already put everything together. There are a number of WAMP server collections, all with the same open source pieces: Apache HTTP Server, PHP, MySQL, and phpMyAdmin, a MySQL database administration package. Some packages also have other tools we won’t be using here. The two most popular are XAMPP and the aptly named WampServer. Choosing one is a matter of taste. I like the WampServer collection because it seems to be the easiest to add in different versions of PHP, but you can use whichever feels comfortable to you. First, you’ll want to get the WAMP stack installed and running, a pretty straightforward task. You can get WampServer from http://wampserver.com. Download and install it; it’s pretty easy. ■ Tip If you have Skype, you’ll want to turn it off. Users have reported problems installing WampServer with Skype running, possibly because 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.” Installing WampServer is pretty straightforward. I installed the server on the root of the C: drive, just to make things easier, as shown in Figure A–1. Figure A–1. Default location for WampServer I’ll be using this directory for all the pieces. When you’re done, you’ll get the happy screen indicating success (see Figure A–2). 309 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT Figure A–2. WampServer set up complete Start the server and make sure it starts. If everything is successful, the WampServer icon will show up in your task tray (Figure A–3). Figure A–3. The WampServer icon Make sure the WampServer meter is green. If it is some other color, something is wrong. 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 Internet Information Server (IIS). If you encounter this problem, you can check to see who is sitting on port 80 by asking WampServer. Click on the icon to display the WampServer control panel, as shown in Figure A–4. 310 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT Figure A–4. The WampServer control panel On the Apache submenu, you’ll find a selection to “Test Port 80.” (See Figure A–5.) Figure A–5. Testing the HTTP port This brings up a command window so you can see what is using that port, as shown in Figure A–6. 311 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT Figure A–6. IIS is using port 80. If you want to fix this, just to go Computer Management and turn off the default web site—that is, if you have a generic site. Your mileage may vary. 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 brings up the IIS control panel. On Windows 7 it looks like the screen shown in Figure A–7. Figure A–7. IIS in Windows 7 312 APPENDIX A ■ WINDOWS DEVELOPMENT ENVIRONMENT Here we can see that, indeed, IIS is using port 80.