After working a new project for awhile (I’m working with PHP and Java). As a quick background story, I’m using Symfony2 and Guzzle to make my calls to my Java webservices. This was working out great except for one minor issue. Well, minor if you count not being able to call my REST services through Guzzle. My problem was that IIS is running my PHP application on port 80 while my Glassfish REST services were running on port 8080 (the Glassfish default). I needed to set up my applications forward requests to Glassfish. So I’ll quickly guide you how to set this up. This will work for any application server, not just Glassfish.
- Make sure you have Glassfish and IIS installed. I’m using Glassfish 3.1.2 and IIS 7.5. Any other versions should work with a few modifications. You can download the latest version of Glassfish here http://glassfish.java.net/ and all your latest IIS needs can probably be found here http://www.iis.net/.
- Download Microsoft Web Platform Installer 3.0. You can find a download here http://www.microsoft.com/web/downloads/platform.aspx. After you’ve finished your download install it.
- After you’ve install Microsoft Web Platform Installer 3.0 you need to install Web Farm Framework. To do this launch IIS (Click start, run, then type IIS).
- You should see Web Platform Installer installed in the bottom pane of IIS. Double click on it and then do a search for Web Farm Framework.
- Click add and then Install. You might have a few other components that need to be installed. Go ahead and click accept.
- Woohoo that was awfully easy. Now navigate to the main screen of IIS. You should have a Server Farms node. Click on Create Server Farm in the right panel.
- Enter the name of the server farm and click next. Click finish without adding a server. Click yes to add routing rules for the server.
- Select Servers then click Add Servers on the right pane.
- Enter the IP address or server name of the server you’re adding to the farm. In my case this is localhost. Click on Add and this will add the server to your farm.
- Click on Advanced settings and select the server you’ve added. You should see the ports that you can assign to your server. Enter your port number for HTTP and HTTPS. I’m entering 8080 because that’s what my Glassfish Server is running on.
- Great we’re almost there. All we have to do now is set up some routing rules. I only want certain URLs getting routed to Glassfish. Select your server farm and then double click on Routing Rules.
- Now just add the rules you want to exclude. Everything else will be forwarded. I don’t want any PHP extensions forwarded nor do I want anything that’s URL contains app_dev.php (Development purposes with PHP). My rules look like this.
- You’re all set! Now you can hit your Glassfish URL’s without entering the port. This fixed one of the issues I was having with Guzzle.
Now that we’ve set this up I’ll show you how to set up Symfony2 and Guzzle so you can start writing a PHP application that makes REST calls.