Over the last few months I have spent more time getting in to php development, this has been mainly for WordPress themes thou I also have written a few simple Web Services. Whilst the live versions of these are hosted externally I like to be able to develop on my laptop disconnected from the internet, eg whilst traveling on trains. This mean I have configured a number of sites using virtual hosts on my laptop.
Working with .Net developers who use Visual Studio my biggest frustration is issues I have is the pain in debugging PHP code, having to put excessieve manual code and logging which can be time consuming. Thou I do include logging for general fault finding. What I was missing was the ability to step through code in a similar fashion to Visual Studio. After some research I discovered that Zend Server CE (free) in conjunction with Zend Studio (€299) appears to do this.
So with a 30 day trial of Zend Studio installed I decided to set up an environment on my laptop with the hope it would deliver, and I would then justify the €299 spend against the time I will save.
So this article discusses how I configured Apache under Zend to use the default port of 80 with host headers on my MacBook Pro running MacOSx 10.7 (Lion). The first thing to be aware of is that the Zend Server CE install, installs its own version of Apache under /usr/local/zend/apache2 so it is highly likely that you already have a default version under /private/etc/apache2. In addition it installs its own light wieght web server for the administrive web site, so you can access the config via a browser even with Apache stopped.
Adding Zend to the Path
To make things easier and allow your system to find the Zend executables and scripts add the Zend Bin folder to the Path.
The Path file is located at
Now add the line
Apache httpd.conf changes
Set the port number
The Apache config file httpd.conf for the Zend installation is installed at
/usr/local/zend/apache2/conf/httpd.conf. I recommend you first make a back of this either from the command line using
sudo cp httpd.conf http.conf.org
or just using ‘Save As’ with a Gui based tool such as Textwrangler.
At around line 40, comment our the original line enabling port 10088 and add a line for port 80 as shown below
Change the Documents Folder
In this example my Sites folder is under my user name of rob. This should be changed to your username in the examples below.
Also change the documents folder as shown below, again I just comment out the original line at 134, the rest of the listing is just shown for completeness.
# This should be changed to whatever you set DocumentRoot to.
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
# The Options directive is both complicated and important. Please see
# for more information.
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
# Controls who can get stuff from this server.
Allow from all
Enabling the Virtual Host file
Finally uncomment the include statement for the virtual host file.
# Virtual hosts
Now exit and save the httpd.conf file
Adding Virtual Host Entries
Next we need to edit the file enabled in the previous section, backup then open the file
Set the port number
First change the port number that Apache will use in the virtual host file from 10088 to 80
Add your site entries
Now we need to disable or delete the 2 default site entries provided by Zend and add our own entries. The example below shows the original entries just commented out and my 3 new sites added to the end
# ServerAdmin email@example.com
# DocumentRoot "/usr/local/zend/apache2/docs/dummy-host.example.com"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
# ServerAdmin firstname.lastname@example.org
# DocumentRoot "/usr/local/zend/apache2/docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
CustomLog "/Users/rob/Sites/logs/intranet-access_log" commonvhost
CustomLog "/Users/rob/Sites/logs/hello-access_log" commonvhost
DocumentRoot "/Users/rob/Sites/florida-paradise-villas (Wordpress)"
CustomLog "/Users/rob/Sites/logs/fpv-access_log" common
You will see in my config above I use server aliases such as fpv and hello so I can access my local sites with http://fpv and http://hello. In order for these addresses to resolve to localhost you need to add them to your host file located at /private/etc/hosts
#Custom Settings - R Langley
# web sites
Auto Starting Zend Apache
The final step is ensure the Zend Version of Apache starts as opposed to the default Mac version. This is to prevent confusion and also a conflict as they are now both configured to use port 80.
I achieved this by effectively repointing the default apachectl to the Zend version of Apache so when the system start Apache it starts Zend version as opposed to the default.
First stop the current version of apache if its still running
Next you need to move the current version to a safe place in case you need it in the future. The file is located at
/usr/sbin/apachectl and can be moved with
sudo mv /usr/sbin/apachectl /Users/rob/SafePlace
Where ‘rob’ above is my personal user folder and should be changed to yours or an alternate location.
Now with the original version of the file removed we can create a link too Zend
sudo ln -s /usr/local/zend/apache2/bin/apachectl ./
Now you should be able to start the new version of Apache with
Update for Mountain Lion
After getting a new laptop with Mountain Lion, I followed these instructions to find I could not get Apache to start, apachectl reports success but nothing is served. I noted an error in the error.log and a quick google took me to http://www.andrew-kirkpatrick.com/2012/07/apache-not-starting-in-zend-server-with-mac-os-x-10-8-mountain-lion-upgrade/
sudo cp /usr/lib/libxslt.1.dylib /usr/local/zend/lib/.
All now working again