Chris Tankersley

Developing On Windows, 2015 Edition

Posted on 2015-07-01

Earlier today, Juan Treminio sent out this tweet, and I injected myself into the conversation.

The short and the long of it was Windows hampering web developers because of some lacking functionality, namely Linux file permissions, a proper CLI, tooling, etc. Linux and OSX have great tooling and setups that are familiar to developers, and Windows falls short.

I respectfully disagree with Juan on this. I've been working as a web developer on Windows for years, though I will gladly admit that there are things that I miss from Linux and OSX (and I'd even go so far as to say I'd rather just use Linux than OSX for general web development). Of course, I run Linux servers and am a Linux sysadmin, and I have a MacBook Pro. I don't consider myself a fanboi of any OS (and not that I think Juan is one either).

In an effort to show that Windows doesn't really have as many shortcomings as it seems, I'll document my setup and pitfalls that there are.

The Command Line - Powershell

I spend most of my time in Powershell. It's always open. Now, I'll admit that Powershell is not anywhere near as nice as an actual Unix terminal, but most of that is because of the way that it handles text selections, and it's inability to actually go full screen. This does not hamper my ability too much and there are ways to make it better, which I've done.

First and foremost, I install git from http://git-scm.com/ and let it add itself to my path. I don't add the full GNU toolset, just git and it's associated stuff. Now I can use git from Powershell just like Linux and OSX. git clone and all the git functionality is there.

I usually add the bin directory of git to my PATH after, this way I can get ssh access directly from Powershell. You may get some weirdness SSHing some servers since Powershell (and CMD) act slightly different than a traditional shell, so keep that in mind. I've seen apps like vim or screen not behave correctly as Powershell doesn't handle resizes or screen clears properly through SSH. It's minor, but it can happen.

Part of the reason OSX and Linux have such a great command line experience is not completely because of the terminal itself, but because of the tools behind it. Unix operating systems tend to ship with either a BSD or GNU suite of tools like grep, sed, awk, etc, that make working with text files and the system much nicer. Powershell does have some of these same things built in, they just aren't named the same. They also work a bit differently than GNU/BSD toolsets, so I normally install GnuWin32.

There is also cygwin. I have a love/hate relationship with cygwin. Most of the time I end back up at Powershell. You might try it out, but don't think it's the end-all-beat-all of terminals on Windows.

I would also recommend learning Powershell in general. It can do many basic things that are found in the GNU/BSD tools, like grep. The commands are just different. When in doubt, google for it and you'll probably get something back. Worse case, use GnuWin32.

As for other Powershell goodies, look into extensions like posh-git. This makes working with git in Powershell much nicer. There's a ton of extensions available for PsGet, so I would browse it's directory for things you might find useful.

Using PHP

There is a lot of things we do as PHP developers that are just glorified PHP scripts. PHP has had native Windows builds for a long time, and it generally works just fine. Head over to http://windows.php.net/, download the latest Non Thread Safe version, extract it somewhere (like c:\php56), and append it to your PATH. You now have PHP available in Powershell.

If you need to modify it, copy a version of the php.ini that the download has and enable different extensions that PHP comes with by uncommenting them.

If you need an extension that doesn't ship with PHP... you might be out of luck. If you need to compile extensions on Windows manually you're going to need Visual Studio, all the correct libraries, and some crossed fingers. Most of the projects I work on generally do not cause me to need to install extensions in Windows directly, most of them are running in vagrant.

Most PHP scripts work just fine in Powershell using PHP. I use Composer all the time, and even the Sculpin phar works. drush used to have some issues but it's rare whenever I'd run that directly under Windows. Your mileage may vary.

IDEs and Text Editors

Time to start the flame wars.

For Windows, my two go-two things to write code are PhpStorm and Sublime Text 3.

I use PhpStorm only because it works well for what I do. Getting xdebug to work with a vagrant box is normally easy, and it has a lot of conveniences that work for me. There isn't anything wrong with other IDEs like Zend Studio, I just like PhpStorm better.

Sublime Text does have a release cycle that is outpaced by glacial movements, so I've also been looking into Atom and Visual Studio Code. Atom is OK, but I find it stalls pretty frequently and is very CPU heavy no matter what I'm doing. Visual Studio Code is nice but exists in this weird area where it's more than a text editor but not a full IDE for PHP, so it lacks. Neither handle huge files well, so I keep coming back to Sublime Text.

I will say that, while I love vim, it's not so great on Windows, so I don't use it there. I use it all the time on Linux and OSX though, but the Windows experience isn't there. Sublime Text is miles ahead.

Development Stacks

It's vagrant. There's nothing special there. Since I have git and SSH available through Powershell I can use vagrant ssh, but vagrant has always worked well for me under Windows. My only complaint is only having SMB mounting support for shared volumes. NFS doesn't work, and I've never gotten vagrant to recognize when I have rsync installed.

Install Virtualbox and vagrant like normal. Develop like everyone else. When you have stuff that needs to run under Linux, SSH into the VM and do it there. This is not any different than when I work on Ubuntu or OSX. I do almost everything for my project inside the VM, even if I have everything installed in the host OS.

If you really want to, you can install your database locally and use IIS Server. There is nothing wrong with that, especially since IIS 7. PHP works great with it. I don't deploy to Windows though, and vagrant is pretty much the standard nowadays.

Don't use a *AMP stack like XAMPP or WAMP though. They won't replicate developing on a Linux machine and can have their own weird quirks. Just use vagrant.

Other Random Stuff I use

The above takes care of almost everything I do day to day. I use HexChat for IRC, which connects to a ZNC server sitting on an Ubuntu box. I use the venerable PuTTY when I need a better SSH client than Powershell. Slack has a Windows client now, so I'm connected through the various Slack teams I'm in. I still use FileZilla (the version without all the crapware) when I need a graphical interface for FTP or SFTP.

And I'm Happy

That's about it. I spend almost all day in Powershell, PuTTY, and PhpStorm and I get all my work done without any hassle. It's not Linux, and I'd rather run Linux 24x7 if I could, but I don't. I can, and sometimes do for short periods of time. When I travel, I take a Macbook Pro with me because it has way better batter life than most of the Windows laptops that I've had.

I know many PHP developers that happily use Windows as well. It doesn't make us any less productive as developers. It doesn't make us any better as developers either. Every developer finds a toolchain and workflow that works for them. This is my Windows toolchain. I hope whatever toolchain you use works well for you.


Comments