Studio without Server

I’ve been using Zend Studio for many years now and think that it is a great IDE for building sites with PHP and JavaScript. IIRC I started with ZS 5; until this week I used version 9. I also ran a free Zend Server package, including Apache 2.2 and PHP 5.4. All this on an ordinary Windows 7 machine.

As my production web server now runs on Apache 2.4 and PHP 5.6, an upgrade on the dev machine seemed appropriate. Also, Zend recently launched Studio 13, with support for PHP 5.6 and even PHP 7. I decided to upgrade everything at once.

So I uninstalled the old Studio and Server, inluding the Apache/PHP stack. Getting the new Studio and Server to run together was quite easy, and I worked with them for a couple of days without any problem. But then I decided to stop using Server. Why? Because of the toolbar.

ZS 9 came with a Firefox toolbar that enabled launching PHP debug sessions from within the browser. Debugging scripts is perhaps the most important feature of an IDE, and starting a debug session should be as simple as possible. The toolbar enabled debugging the current page, posted forms and even XHR requests. Unfortunately Zend has decided drop it. It just won’t work with the Apache/PHP stack that comes with Server.

Server now comes with something called Z-Ray that provides all sorts of debugging information and also has a browser bar to launch a debugging session. However to me a license for Zend Server is way too expensive, so after the free trial expires I would not be able to debug from the browser. Exit Server.

I now needed to get my own Apache/PHP stack. There are plenty of packages out there, including WAMP packages that come with a single installer. But in order to make Studio communicate with PHP, another tool called Zend Studio Web Debugger is required. It can be downloaded here.

The readme file actually contained some very important information: Windows debuggers are built with VC11-NTS. It would have saved me quite some time had I read that before installing Apache and PHP. It means that the debugger will only run on a non thread safe version of Apache/PHP, built with VC11.

Setup Apache and PHP

VC11 PHP 5.6 for Windows is available here. Pick the NTS version.

VC11 compiled binaries of Apache can be downloaded at ApacheLounge.

The NTS version of PHP can’t be used as an Apache module, so we’ll need some sort of (Fast)CGI implementation. I used mod_fcigd provided by ApacheLounge.

I copied the Apache and PHP files to C:\webserver\Apache24 and C:\webserver\php56, and put mod_fcgid.so in the apache\modules folder.

Now, edit httpd.conf (it’s in Apache24\conf\). First make sure that directives such as DocumentRoot match your path structure. In my case: DocumentRoot "c:/webserver/Apache24/htdocs". Also add index.php to DirectoryIndex :

<IfModule dir_module>
     DirectoryIndex index.html index.php 
</IfModule>

Add these FCGI configuration lines somewhere at the end of httpd.conf:

# first load the module
LoadModule fcgid_module modules/mod_fcgid.so

FcgidInitialEnv PATH "c:/webserver/php56;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
# FcgidIOTimeout determines how long a PHP script can run before a timeout occurs. 
# Set it to something high; otherwise debug sessions will break. (value in seconds)
FcgidIOTimeout 601
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000 
FcgidMaxProcesses 50 
FcgidMaxRequestLen 8131072
# Location of the folder with php.ini:
FcgidInitialEnv PHPRC "c:/webserver/php56"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

AddHandler fcgid-script .php
FcgidWrapper "c:/webserver/php56/php-cgi.exe" .php

One very important setting in httpd.conf is the Options directive. We need to add ExecCGI; otherwise requests for .php files will throw an error 403 Forbidden.

<Directory "c:/webserver/Apache24/htdocs">
    Options Indexes FollowSymLinks ExecCGI
    ..
</Directory>

My projects all live under C:\projects, so I have a directory container with Options for them as well:

<Directory "c:/projects">
    Options Indexes FollowSymLinks ExecCGI
    AllowOverride All
    Require all granted
</Directory>

AllowOverride All means that the Options directive can be overridden in .htaccess files. Make sure that you don’t break the ExecCGI option…

Next, copy php56\php.ini-development and rename it php.ini. Edit it:

  • uncomment extension_dir = "ext"
  • uncomment the extensions you’ll be using, such as php_mysqli.dll
  • under [Date], put something like date.timezone = Europe/Amsterdam

Run Apache and PHP

Let’s see if things work. Launch a Windows Command Prompt window (click Start, type cmd, hit enter). Go to the Apache24\bin directory and type httpd. It there are no error messages, Apache is running. Open http://localhost/ in your browser; there should be a page with “It works”.

The Apache process can be stopped by pressing Ctrl-C in the command window. I noticed this may take a while.

Try to run a PHP script too. For example, create a script called test.php in the Apache24\htdocs directory, and put <?php phpinfo(); ?> in it. Open http://localhost/test.php in the browser.

Adding the debugger and the toolbar

Copy ZendDebugger.dll to php56\ext. Edit php.ini, add this:

[zendDebugger]
zend_extension=ZendDebugger.dll
zend_debugger.allow_hosts=127.0.0.0/8,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12
zend_debugger.expose_remotely=allowed_host

Restart the web server.

Install the toolbar from the Studio download page. It’s hidden under “Older versions”. Installation instructions are here. In my Firefox toolbar settings I have manually set the Studio debug port to 10137 and IP address to 127.0.0.1.

From the zip file that contained ZendDebugger.dll, copy dummy.php into the web root of the site you want to debug. (Edit: it seems like this is not necessary.)

You should now be able to launch a Studio debug session from the toolbar. Also, Zend Debugger should now be listed in phpinfo()‘s output.

Apache service and monitor

In order to have Apache launched every time Windows is restarted, add it as a service. Launch the Command Prompt from the Start menu: right click the menu item and choose “Run as administrator”. Cd to Apache24\bin and run httpd -k install.

Apache comes with a handy tool that can monitor, stop and start the Apache service. Just double click on ApacheMonitor.exe in Apache’s bin folder, and it will from then on live in the notification area, bottom right of the Windows taskbar.

Final note

This is probably not the fastest way to run Apache and PHP on Windows. In fact, I find it reacts rather slow to PHP requests. Please leave suggestions for improvements in the comments. (Edit: It had to do with MySQL and IPv6. Found solution here.)

Leave a Reply

Your email address will not be published. Required fields are marked *