Setting up localhost with Zend Server Free
Install and prepare
Install software in the following order:
- Mysql Community Edition 5.5 (do this first!)
- Zend Server Free Edition
After installing Zend Server Free edition the next step is to set it up for localhost and multi-site use. This way you can have several different virtual domains instead of viewing everything through “localhost”.
To edit files, we will use Terminal (
sudo nano /file/to/edit) on Mac OS X and Sublime Text on Windows.
Disable Mac OS X built-in Apache
Depending on the version, Mac OS X typically ships with its own Apache server. We usually need to disable this in order to use the Zend Server one instead. You can also just continue running Zend on an alternate port and keep Mac OS X’s built-in server as well.
First, let’s modify the launch daemon to start our own Zend Apache:
sudo nano /System/Library/LaunchDaemons/org.apache.httpd.plist
You’ll need to change the following line:
Next, in case it is not already done, you can enable the launch daemon:
sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist
Now, the next time you restart your computer, Mac OS X will fire up Zend Apache instead of its own.
Basic setup for Zend
We will first edit the http.con file:
sudo nano /usr/local/zend/apache2/conf/httpd.conf
[todo: add Windows path here]
First, let’s change the default port to 80 (unless you also want to use the built in webserver for whatever reason – skip this step if you do). Let’s change the line “Listen” parameter to 80:
Next, let’s change the DocumentRoot to our Sites folder. You should do this on single user machines where it’s fine if all requests go to your own Sites folder. Don’t forget to change YOUR_USERNAME to whatever your “short” user name is.
Another section a bit further down will also require a change:
# # This should be changed to whatever you set DocumentRoot to. # <Directory "/Users/YOUR_USERNAME/Sites/"> # Turn on debug mode in Mozajik SetEnv DEBUG_MODE "true" # Turn on rewrite engine, allow show of indexes, enable .htaccess override RewriteEngine On Options Indexes FollowSymLinks AllowOverride All .....
Disable site listing for your root folder
To make sure people on the same coffee shop wifi can’t freely browse your sites, you need to disable listing of your sites. You can do this a number of ways, but the easiest is to add an index.html file to your Sites folder. This method will still allow other people to access your sites, but only if they know the specific subfolders.
Add a friendly message and save.
Important! If you want to disable external access to your computer completely, you’ll need to use a more secure method such as setting the
Allow from directive.
Password protect network access
[todo: add docs]
Setting up multi-site use, virtual hosts
When you need to test Facebook apps, its best to set up virtual hosts which have the same domain as the final app. So an app on
app.outlast.hu should run locally on
local.outlast.hu – this will allow you to test and use the Facebook app locally without errors.
First, create the virtual domain by adding this to your /etc/hosts file as follows:
This will route the virtual domain “local.outlast.hu” to localhost (127.0.0.1).
Next, you need to enable vhosts conf file for Apache, so edit
/usr/local/zend/apache2/conf/httpd.conf and uncomment the following line by removing # from the beginning (this is towards the bottom):
Next, you need to set up your sites folder for use in Apache. So let’s edit the /usr/local/zend/apache2/conf/extra/httpd-vhosts.conf file:
<Directory "/Users/*/Sites"> # Turn on debug mode in Mozajik SetEnv DEBUG_MODE "true" # Turn on rewrite engine, allow show of indexes, enable .htaccess override RewriteEngine On Options Indexes FollowSymLinks AllowOverride All # Allow everyone to access this folder Order deny,allow # Uncomment below to allow only access from local computer (recommended if you dont want wifi coffee drinkers looking at your stuff :)) #Order allow,deny #Allow from 127.0.0.1 localhost </Directory>
You’ll need to set up virtual sites in Apache (this should go in the same vhosts file):
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName local.outlast.hu DocumentRoot "/Users/YOURUSERNAME/Sites/yoursite/" </VirtualHost>
Setting up MySQL for PHP
If you’re using MySQL, you may also need to modify the PHP.INI file so that it points to the right MySQL socket file. I installed the default MySQL package from the official website and it places the socket file in the /tmp folder. As such, you’ll need to search for each instance in /usr/local/zend/etc/php.ini where there is a mysql.sock file and update it to /tmp/mysql.sock – for example:
mysql.default_socket = /tmp/mysql.sock
Restart Apache to apply settings
On Mac OS X, restart Apache (you can also set up a symlink for this):
sudo /usr/local/zend/apache2/bin/apachectl restart
On Linux, you can use the service command:
sudo service apache2 restart
For Windows, start up the
Services.msc program from Start/Run… and use the UI to restart the Apache service.
If restart doesn’t work
If you get an error during restart you may have to first kill the built-in Apache. This will be necessary if it is running on the same port. You can do this in the Terminal:
sudo killall httpd sudo killall httpd sudo killall httpd sudo killall httpd sudo /usr/local/zend/apache2/bin/apachectl restart
In my experience, you have to run killall httpd quite a number of times before it kills all the processes properly. Not sure why, but running it 3-4 times should take care of it for good. If you’ve set up the Launch Daemon above you can also just restart your computer, but that seems like such a Windows-thing to do… 🙂
Setting permissions for folders
This is only required on Mac OS X and Linux. If you have existing projects in your Sites folder, it is possible that their permissions were lost during a system update.
You need to restore the permissions recursively for each existing project in each project folder as such:
cd ~/Sites/MYSITENAME/ sudo chmod -R a+w data sudo chmod -R a+w cache