Configuring Zend Server (Free Edition) on Mac OS X

Unlike Windows which doesn’t come with Apache by default, or distributions of Linux which (usually) have their own package management systems, Mac OS X comes with an outdated version of Apache which isn’t handled by package management. This means it’s a pain to either update or remove it. Any Mac PHP developer will probably have tried MAMP which gives you a relatively pain-free installation, but for anything complex it can be a bit tricky due to the way it’s self-contained. As a Zend Framework developer I use Zend Server and Zend Server CE at work now and figured now that I’ve got to do some work at home I should look to get it installed and configured…

Just to check that everything is working OK to start with, go to http://localhost/ and you should see the default Mac OS X homepage which will be located in your Sites directory.

Disable the default Apache installation

Make sure you stop the default Mac OS X version of Apache before you start the new Zend one, or it’ll conflict.

apachectl stop

Installation

Download Zend Server (apply for a Zend Server Free Edition license if needed) from Zend and install as usual.

Update your license

Open up /Applications/ZendServer.app which should launch the lighttpd web interface. You can enter your free developer license here to upgrade from Enterprise Trial to Developer Standard, which won’t expire after 30 days.

Replace the default apachectl with Zend Server’s apachectl

Easiest way to do this (without uninstalling anything) is to replace the default apachectl with Zend Server’s apachectl, that way it will just appear to be launching Apache as per usual when OS X starts up.

Firstly move apachectl to a safe place, such as your home directory:

sudo mv /usr/sbin/apachectl /Users/yourusername/

Then create a symbolic link to Zend Server’s apachectl:

sudo ln -s /usr/local/zend/apache2/bin/apachectl /usr/sbin/

Start Zend Server’s Apache:

sudo apachectl start

You should then see:

/usr/sbin/apachectl start [OK]

This will indicate that you are running Zend Server’s Apache as opposed to Mac OS X’s Apache (as the latter doesn’t output to the terminal when you start/stop it) although if you go to http://localhost/ you will notice that you will get a 404.

Configure Apache to use port 80

I’m assuming to avoid any conflict with the default Apache installation that Zend Studio’s Apache comes preconfigured to use port 10088. To change this simply edit the configuration:

sudo vi /usr/local/zend/apache2/conf/httpd.conf

… or if you dont use Vi, use another text editor such as Nano:

sudo nano /usr/local/zend/apache2/conf/httpd.conf

Look for the line Listen 10088, then either comment it out and add a new line or edit the port to be port 80.

#Listen 10088
Listen 80

You may also need to change the DocumentRoot and first Directory parameters to your webroot (/Users/username/Sites for example)

#DocumentRoot "/usr/local/zend/apache2/htdocs"
DocumentRoot "/Users/username/Sites"
#<Directory "/usr/local/zend/apache2/htdocs">
<Directory "/Users/username/Sites">

Save httpd.conf (Ctrl + x in Nano to exit then y to save) and restart Apache:

sudo apachectl restart

If you go to http://localhost/ in your browser you should now see the default Mac OS X homepage, as httpd.conf should already be setup to point to your Sites directory by default.

If you get any complaints about the FQDN when you start Apache, such as:

httpd: Could not reliably determine the server's fully qualified domain name, \
using iMac.local for ServerName

Then you need to explicitely set the name of the domain to be used (in this case, localhost)

#ServerName www.example.com:10088
ServerName localhost:80

Configure Zend Framework 1

sudo ln -s /usr/local/zend/share/ZendFramework/bin/zf.sh /usr/sbin/zf

Configure Pear

sudo ln -s /usr/local/zend/bin/pear ./
sudo pear upgrade pear

Configure MySQL

sudo vi /usr/local/zend/mysql/data/my.cnf

You will then need to change where it looks for the socket:

#socket = /usr/local/zend/mysql/tmp/mysql.sock
socket = /tmp/mysql.sock

If this doesn’t work (as it won’t for some programs) you will need to create a symbolic link for the socket:

sudo ln /usr/local/zend/mysql/tmp/mysql.sock /tmp/mysql.sock

If there isn’t a socket file there…

Configure Xdebug

First symlink PECL

sudo ln /usr/local/zend/bin/pecl /usr/sbin/pecl

Then you will need to install Xdebug with it

sudo pecl update-channels

sudo pecl install xdebug

Errors installing via PECL

You might get an error with autoconf (I have Xcode 4.3 installed which might have something to do with it)

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize’ failed

If so you’ll need to either compile it yourself, or grab a pre-compiled version. Luckily the nice folks at ActiveState provide pre-compiled extensions. Grab the latest version from their site and copy the extension in the directory ‘5.3’ (as in PHP 5.3)

cp xdebug.so /usr/local/zend/lib/php_extensions/

Configure Xdebug as a Zend Extension

You cannot enable Xdebug as a normal PHP extension as it won’t work properly; you need to enable it as a Zend extension. This means you’ll need to add the following line to php.ini

zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so

However this won’t work on it’s own as you will need to turn off the debugger that ships with Zend Server. The great instructions from the tailored installation instructions from Xdebug state “Open /usr/local/zend/etc/conf.d/debugger.ini and put a ; in front of the line that says zend_extension_manager.dir.debugger= so that it says ;zend_extension_manager.dir.debugger=”

If you have any problems configuring it, the Xdebug tailored instructions are a great help, just copy the HTML source of a phpinfo() script and it tells you what you need to do.

Configure phpMyAdmin

If you want to use Apache instead of Lighttp, you will have to create a Directory entry and Alias for phpMyAdmin:

sudo vi /usr/local/zend/apache2/conf/httpd.conf
Alias /phpMyAdmin /usr/local/zend/share/phpmyadmin
<Directory "/usr/local/zend/share/phpmyadmin">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Install PHPUnit

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
pear channel-discover pear.symfony.com
sudo pear update-channels
pear install pear.symfony.com/Yaml
sudo pear install --alldeps phpunit/PHPUnit
sudo ln -s /usr/local/zend/bin/phpunit ./

9 comments

Leave a Reply to Andrew Kirkpatrick Cancel reply