IIS with Zend Server: Zend Controller and URL Rewrites

I have always been a fan of LAMP.  In fact, in the past it was the only good way to get your hands on real server apps.  Apache has served me well over the year and was the first HTTP server I knew.

Over the years I have worked at many mixed OS shops, but IIS always seemed to be around and I ended up configuring it in one way or another.  It didn’t take long for me to find that configuring IIS was much simpler than Apache.  If you have used Apache for any length of time you know that it is a bit of a black art at times.  I don’t know anyone that considers themselves an Apache configuration expert.

Historically speaking  PHP with IIS performance on Windows has been dismal.  Microsoft recognized this and started working with the PHP community to enhance IIS support for Fast-CGI and now there are an endless supply of Microsoft interactions with PHP.  I don’t think I am the only one that thought it odd to see M$ at Zend Con the first time. (Thanks for the ASP book by the way)

I still hadn’t any use for IIS on any real PHP development or hosting.  The biggest draw back left was the lack of support for URL Rewriting.  While one of many things offered in Apache, it was a deal breaker in many of my situations.  So 12 years after I started developing websites and web apps, Zend encouraged me to use IIS once again.  “How did Zend encourage you to use IIS?” you may ask.  Well they distribute Apache in Zend Core, but they also offer IIS support in Zend Core, Platform and now Server.  To start with my current dev box runs Windows Vista Ultimate.  So when I got the new Zend Server beta, I decided to use it with my IIS installation.

There are dozens of tutorials out there on how to install Zend Server, the only difference in the install is that you pick to use the existing IIS install.  This will install and configure IIS fore use with your IIS.  If you open ‘inetmgr’ you will notice a virtual directory in your default site called ZendServer.  The only problem I had with the install is that my Default Weg Site is listening on port 8080 and the Zend Server installer failed to figure this out, so all my links in the start menu and such refer to flat http://localhost/ instead of http://localhost:8080/.  Being a beta I suppose that will be fixed by the time it is released.  I have had good experience and responsiveness from the Zend teams in the past.

Once Zend Server is installed it offers a much more organized tool set than Zend Core + Zend Platform.  Some features though may not be useful for all.  One of which is the output caching.  Depending on how you use it the caching in IIS may be better for you, especially if you or your admin are familiar with it.  Zend Server comes with a nice web interface to the php.ini satisfying those mouse using admins.  The Zend Server Dashboard presents you with events that were tracked, and that may be of interest.  Thins like slow script execution and errors, and you can drill right down to where it is coming from.  There are plenty of places that talk about the features of Zend Server and they probably explain it more in depth.

The install also comes with a little standalone utility that you can find in the Zend Server install directory in the ‘bin’ folder.  It is called Zend Controller (zendcontroller.exe).  It holds some links directly to various places in the ZendServer web interface, launching your default browser.  It also has a quick search form for PHP Documentation, Zend’s Website, Zend Framework documentation and MySQL documentation.  The neat thing it houses is a ultra simple bench mark tool.  Simply set the url and the request duration in seconds and hit start and it will see how many requests per second it can handle.  I may post some results a little later with IIS vs. Apache using this simple tool.

So all seemed to be well until I remembered I like to use Rewrite Rules to keep my urls clean.  I don’t like to see ‘http://www.example.com/somefoo.php/somestuff/here/?key=value&someotherjunk’.  I figured that there should be some good way to do this now with IIS7.  Sure enough, an ‘I feel lucky’ click later I had the Microsoft URL Rewrite Module for IIS 7.0 (x86) : Download.  All is hopeful.

So I installed it.  Opened IIS Manager, selected the website I wanted, and clicked the URL Rewrite icon. |ICON| I was presented with an empty list, so I clicked the “Add Rules…” link on the right-hand side.  I noticed “Import Rules”, interesting.  I will check this out later.  I tried “User Friendly Url” icon.  This only offered simple shortening that didn’t fit my need.  What i needed was to rewrite ‘/index.php/list/foo/?orderby=bar’ from ‘/list/foo/?orderby=bar’.  This isn’t too dificult in Apache, although every time I do it I end up hacking arround with it a bit until I get it working.  So the one I want is “Blank rule”.

RewriteI named it ‘Index’ and set the pattern to match everything like ‘^(/*)’ because I saw below additional conditions.  Then I clicked Add Conditions since I thought I should not run images, css and js through the rewrite and thus the index.  My code is not set up to handle that.  I selected “{QUERY_STRING}” for the Condition input, and under ‘Check if input string’ set to does not match the pattern “.*.jpg” and clicked OK.  I then did the same for png, gif, css and js files.  Alternately, if you dont mind people accessing everything under the web root, you could set your conditions to {REQUEST_FILE} “Is not a File” and “Is not a Directory” to avoid having to put an acception for every file type you need to access directly.  Or you may be able to use your Front Controller as a catch all for those types of requests too.

I then clicked apply and restarted the site.  Now we have nice clean secure urls that a malicelious visitor would not think is even PHP (cause who runs PHP on Windows? hehe).

IIS with Zend Server: Zend Controller and URL Rewrites

One thought on “IIS with Zend Server: Zend Controller and URL Rewrites

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s