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 /private/etc/paths
Now add the line /usr/local/zend/bin
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
40
41
| #Listen 10088
Listen 80 |
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.
105
106
| #DocumentRoot "/usr/local/zend/apache2/htdocs"
DocumentRoot "/Users/rob/Sites" |
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.
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
| #
# This should be changed to whatever you set DocumentRoot to.
#
#<Directory "/usr/local/zend/apache2/htdocs">
<Directory "/Users/rob/Sites">
#
# 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
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# 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
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory> |
Enabling the Virtual Host file
Finally uncomment the include statement for the virtual host file.
391
392
| # Virtual hosts
Include conf/extra/httpd-vhosts.conf |
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 /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf
Set the port number
First change the port number that Apache will use in the virtual host file from 10088 to 80
391
392
| #NameVirtualHost *:10088
NameVirtualHost *: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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| #<VirtualHost *:10088>
# ServerAdmin webmaster@dummy-host.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
#</VirtualHost>
#<VirtualHost *:10088>
# ServerAdmin webmaster@dummy-host2.example.com
# 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
#</VirtualHost>
<VirtualHost *:80>
ServerAdmin rob.langley@me.com
DocumentRoot "/Users/rob/Sites/intranet"
ServerName localhost
ServerAlias intranet
ErrorLog "/Users/rob/Sites/logs/intranet_error_log"
CustomLog "/Users/rob/Sites/logs/intranet-access_log" commonvhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin rob.langley@me.com
DocumentRoot "/Users/rob/Sites/helloWorld"
ServerName localhost
ServerAlias hello
ErrorLog "/Users/rob/Sites/logs/hello_error_log"
CustomLog "/Users/rob/Sites/logs/hello-access_log" commonvhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin rob.langley@me.com
DocumentRoot "/Users/rob/Sites/florida-paradise-villas (Wordpress)"
ServerName localhost
ServerAlias fpv
ErrorLog "/Users/rob/Sites/logs/fpv_error_log"
CustomLog "/Users/rob/Sites/logs/fpv-access_log" common
</VirtualHost> |
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
12
13
14
15
16
| #Custom Settings - R Langley
# web sites
127.0.0.1 intranet
127.0.0.1 fpv
127.0.0.1 hello |
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
apachectl stop
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
cd /usr/sbin
sudo ln -s /usr/local/zend/apache2/bin/apachectl ./
Now you should be able to start the new version of Apache with
apachectl start