Monday, August 24, 2009

The Lost Weekend: IIS 7, PHP, and Zend

My plan for this weekend was to implement a new version of one of my web sites. I wanted to move from an old complicated build process to one based on using the Zend conventional modular layout. I estimated I could complete the task over the weekend. I was wrong.

Microsoft made a significant change by allowing IIS to run on the home versions of Vista. I could install IIS 7 on my new Vista 64 bit PC. I thought it would be a fun learning experience to use IIS 7 as a test bed while I implemented the changes. I was wrong.

Microsoft packaged up PHP and created an install using their new Web Platform Installer. This sounded like a quick way to get PHP up and running. If you want to get PHP up and running quickly on IIS 7, the Web Platform Installer will do that. However, if you want to use PEAR, the Web Platform Installer is a dead end. I have a problem with PEAR. I was unable to find any instructions on how to install PEAR manually. Everywhere I looked the documentation always said to run the "go-pear" script or batch file. Microsoft decided not to include that little file in their installation of PHP via the Web Platform Installer. When you install PHP via the Web Platform Installer on Vista 64 PHP is installed in the "\Program Files (x86)\php" directory. The installer then sets the include path to ".;c:\php5\pear" even though there is no php5 directory created. If you want PEAR and PHP on IIS, you want to avoid using the Web Platform Installer. Instead, use the "installer version" found at "windows.php.net". When you install, make sure you change the installation directory to "\php5". I also recommend you install PEAR, which is an option with the "installer version". I thought the Web Platform Installer quickly set up PHP and PEAR. I was wrong.

When you install IIS 7, it does not include a URL Rewrite Module. Only two things were quick and easy this weekend. The first was installing the IIS URL Rewrite Module and importing the rewrite rules from Apache. The second was downloading and installing the Zend Framework. The Zend Framework is a .Zip file you download, and decompress to anywhere you choose.

I used the Zend Framework before. I never started a project using MVC from scratch. I wanted to use the conventional modular layout to support three levels. There were tutorials that showed how to set this up. It looked very simple to me. I was wrong.

In previous entries, I mentioned "Practical Web 2.0 Applications with PHP" by Quentin Zervaas. Apress published the book in December of 2008. It is already out of date. About the time the book was published version 1.8 of the framework was released which deprecated the use of Zend_Loader's autoloader. I thought I could use the tutorial in the book by Zervaas to build a site from scratch. I was wrong.

I set up my site with a single controller. I kept getting the error "Invalid controller specified". I spent hours checking my directory structure. I googled the error message. Most web sites suggested that there was a problem with the file or directory casing. I am using IIS 7 on Vista. Files and directory casing should not be an issue. I thought I had some sort of typo in some file. I was wrong.

Finally, after much pain and cursing I found the problem. The problem is auto-rendering. The Zend framework automatically goes hunting for the template with auto-rendering enabled. Most of the sample code has a hidden assumption that auto-rendering is off. This is no longer true with the default configuration. I was getting the error "Invalid controller specified". The problem was not with the controller but with the view. Here is a situation where the MVC separation in Zend is poorly constructed. Zend generates an inappropriate error message.

Overall, I lost a weekend getting IIS 7, PHP, and Zend working. I did not finish redesigning my website. I still have a lot of work ahead. I was not expecting a major learning experience this weekend. I was wrong.

8 comments:

Joao said...

lol looks like I'm not the only one thinking that way! I'm always saying, hey this looks really easy probably I can do it quickly and after all I spend more hours just to get it working then I could imagine!

wirah said...

You're definitely a good candidate for a switch to desktop Linux! Check this complex installation process out:

apt-get install apache2 php5 mysql

Done - and a weekend of website-writing ahead! I don't know why anyone bothers with Windows anymore.

eliaspraciano said...

Yes, on Debian based distros it could be like:
apt-get install lamp-server^
[Don't forget the carrot at the end of the line...]. And you won't even need to reboot.

The Open Sourcerer said...

@Jeff, we call those "just jobs". It just this or that. And then the complications set in...

@ eliaspraciano

I've not see the carrot trick before, to install LAMP I've always used:

# tasksel install lamp-server

Cheers

Pierre said...

Guys (wirah, elia), what's about actually read the post and then reply? :)

The problem has nothing to do with windows but the Zend Framework.

I do not think it is harder to install php on IIS than on any linux. And if you use the web platform installer then it will take less than 2.5 mins :D (http://www.microsoft.com/web/)

opengeek said...

FWIW, I was able to run the go-pear php script from http://pear.php.net/go-pear in a command prompt with administrator privileges and PEAR is working fine with the Web PI PHP setup.

Markus said...

Of course it's easier to install PHP on linux.. Try install ASP.NET on apache and linux...

MARCUS VINICIUS NEGREIROS said...

http://blogs.iis.net/ruslany/archive/2010/11/22/how-to-install-php-pear-and-phploc-on-windows.aspx