Setting up Zend Server 6 on OS X for PHP development

I recently decided to upgrade my Mac's PHP to 5.4. One of the available options is Zend Server 6.1, Free edition. These are my notes how to set it up so that it works the way I develop.

Installation

Mount the disk image and follow the installation wizard. On OS X, Zend Server installs PHP, Apache and MySQL inside /usr/local/zend.

The Zend Server admin interface is at at http://localhost:10081. On first run you have to go through a wizard. I picked development for my Launch Option. You have to set an admin password – as it's my dev machine, I picked something simple :)

More information is available from Joe Stagner's guide on devzone. Ignore the bit about editing php.ini though as you can do that via Zend Server's admin system.

Apache

Like Joe, I also want the Apache running on port 80. Edit /usr/local/zend/apache2/conf/httpd.conf and replace Listen 10888 with Listen 80.

Note that the default localhost directory is /usr/local/zend/apache2/htdocs and the Apache processes run as user daemon with group daemon.

Zend Server admin

Once logged in, you can configure Zend Server:

Configuration -> PHP:
Set your PHP settings are required. Then press Save. To restart the server, click the button with two arrows in a circle on the toolbar.

You must set the date.timezone to stop the PHP warning. I also set sendmail_path as I like to redirect email on my development box.

Configuration -> Components:
Look down the list and turn off what you don't need. I turned off Zend Data Cache, Zend Job Queue and Zend Page Cache in addition to what is already off.

Command line control

Add the relevant Zend Server paths to your environment. Edit .bash_profile and add

export PATH=/usr/local/zend/bin:/usr/local/zend/mysql/bin:$PATH 

to the bottom. This will give you access to the php, mysql and other Zend Server related CLI tools.

zendctl.sh

The main CLI tool to control Zend Server is zendctl.sh. The most interesting commands are:

  • sudo zendctl.sh restart-apache to restart Apache
  • sudo zendctl.sh restart-mysql to restart MySQL

MySQL

Zend Server supplies MySQL version 5.5.27 rather than 5.6 for some reason. If you want 5.6, then grab it from MySQL's website or homebrew.

If you use your own MySQL, then stop Zend Server from starting its one by editing /etc/zcd.rc and changing MYSQL_EN=true to MYSQL_EN=false.

If you're using Zend Server's MySQL, then set a root password:

$ mysqladmin -u root password {new-password}
$ mysqladmin -u root -p{new-password} -h localhost password {new-password}
$ mysqladmin -u root -p{new-password} reload
$ history -c

I also had to link mysql.sock to /tmp so that some mysql CLI applications would work:

  • sudo ln -s /usr/local/zend/mysql/tmp/mysql.sock /tmp/mysql.sock

Apache vhosts

I couldn't work out how to configure Apache virtual hosts in the Zend Server admin unless you had an "application package", so I did them manually.

Apache is configured to look in /usr/local/zend/etc/sites.d/ for files names globals-*.conf and vhost_*.conf.

I created globals-vhost.conf:

NameVirtualHost *:80

LoadModule vhost_alias_module modules/mod_vhost_alias.so

And then I have vhost_dev.conf to configure my virtual hosts:

<virtualhost *:80>
    ServerAdmin webmaster@akrabat.com
    DocumentRoot "/www"
    ServerName localhost
    <directory "/www">
	    Options Indexes FollowSymLinks MultiViews
    	AllowOverride All
        Order allow,deny
	    Allow from all
    </directory>
</virtualhost>

<virtualhost *:80>
    VirtualDocumentRoot "/www/dev/%-2+/public"
    ServerName subdomains.dev
    ServerAlias *.dev
    UseCanonicalName Off
    LogFormat "%V %h %l %u %t "%r" %s %b" vcommon
    ErrorLog "/www/dev/vhosts-error_log"
    DirectoryIndex index.php index.html
    <directory "/www/dev/*">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
        
        SetEnv APPLICATION_ENV development
                
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]        
    </directory>    
</virtualhost>

This allows me to put my development files in /www and sets up automatic virtual hosts for http://*.dev.

Fix sending email

Sending email doesn't work out of the box. To fix:

$ sudo mv /usr/local/zend/lib/libsasl2.2.dylib /usr/local/zend/lib/libsasl2.2.dylib.old
$ sudo ln -s /usr/lib/libsasl2.2.dylib /usr/local/zend/lib/libsasl2.2.dylib

See here for details.

Logs

The Zend Server admin displays your logs via Overview -> Logs. There is a list of log files down the left hand side. The interesting ones for me are:

  • error: Apache error log (/usr/local/zend/var/log/error.log)
  • access: Apache access log (/usr/local/zend/var/log/access.log)
  • php: PHP log (/usr/local/zend/var/log/php.log)

That's it. Zend Server now works as a development stack and you get the nice diagnostics features like code tracing and the events list.