Cygwin for Local Development

Since starting my job at WolfNet I have been exposed to a lot more Linux. Since all of our web servers are running on Ubuntu Server and we use Git for our code repository I have really been thrust into the world of Unix and in general I have found that I really like it. It is a very fast and flexible way of getting things done.

Prior to working at WolfNet I had started to explore using command line for performing more tasks. I was teaching myself Ant and had started to play around with Cygwin though a lot of the fundamentals still baffled me. It really wasn’t until I read “Unix and Linux: Visual QuickStart Guide” by Deborah S. Ray and Eric J. Ray, that things really started to click for me. Since then I find that almost always have at least one instance of Cygwin open and often several.

If you are not familiar with Cygwin or haven’t put much thought into using command line for your everyday tasks I highly recommend you look into it. Drop me a line if you have any questions and I will do my best to help out.

Once I understood the basics of Unix architecture I started playing around with changing configurations and even writing my own helper function and scripts. I followed up the Unix book with “Pro Git” by Scott Chacon at which point I moved from using a Git GUI to using Git entirely from the command line. My productivity went even higher and started asking myself what else I could do from within Cygwin.

The big step for me was when I sat down one day determined to get PHP running from within Cygwin. It wasn’t exactly easy but I read a lot of blog posts and pieced things together and eventually I had a fully functional install of PHP running locally within the Cygwin environment.

Since there is no PHP package provided as part of the Cygwin installer I had to compile the PHP source code manually and then install it. This ended up being a lot easier than I thought the tricky part was making sure that I had all of the necessary pre-requisites ensure that it would compile correctly. The biggest revelation was that when I received an error message from the compiler saying such and such library was missing it wasn’t the primary library I needed to have install but rather the “development” package. For example in order to the Curl library working in PHP I needed to have the “libcurl-devel” package installed rather than the standard “curl” package.

Ultimately here are the commands I used:

cd /usr/src
wget -O php-5.4.11.tar.gz
tar -xzf php-5.4.11.tar.gz
cd php-5.4.11
make test
make install

Here is what each line is doing:

  1. Change directory to the user source directory which by convention is used to store source files which are to compiled.
  2. Download the PHP source files in a “tar ball” file (required the “wget” Cygwin package)
  3. Extract the files from tar ball into a new directory with the same name.
  4. Change directories to the new source code directory.
  5. Run the configure script. This script actually has a whole bunch of switches which are used to determine what exactly will be included
  6. PHP build. Use the -help switch to find out more information.
  7. Run the make script to actually compile the source code. (requires the “make” Cygwin package)
  8. Test the compiled code to ensure there are no errors.
  9. Install the compiled binary files.

More than likely you will encounter a number of errors throughout this process. The best advice I can give you is look at the error message and determine if it matches up with a library which can be downloaded via the Cygwin installer. Chances are it will and as I mentioned before make sure you download the “development” version of the library before trying the compile again. Once you are ready to try again you only need to start from the ./configure command.

Once I had PHP available to me from within Cygwin I was able to start doing some awesome rapid PHP development. I was able to start using some great tools such as: phpunit, composer, phpDocumentor and even the built-in HTTP server that comes with newer versions of PHP. This meant I didn’t even need to have Apache running on my system. I could just cd to a directory and start-up an HTTP server locally running on whatever port I want.