Apache on your Mac
Apache comes ready installed on a Mac, so it is reasonably quick and easy to set it up to serve up static resources for your collective.xdv theme. This configuration is intended for development purposes only and simply configures Apache to deliver your Plone site via http://localhost/ (i.e. through port 80) and to deliver your images, style sheets and JavaScript via http://localhost/staticresources. You'll still be able to get to plain vanilla Zope and Plone through http://localhost:8080 and http://127.0.0.1:8080.
Configuration
First we need to locate and edit Apache's configuration file - httpd.conf. If you're going to do this via the easy route using Finder, you'll first need to reveal invisible files. Ironically, the quickest way to do this is to use a terminal window:
defaults write com.apple.finder AppleShowAllFiles Yes
Relaunch Finder - Apple Menu > Force Quit > Finder and you should then be able to see a folder at the root of your Mac's hard disk /private/etc/apache2 containing the main Apache configuration file - httpd.conf.
To be on the safe side, make a back-up of httpd.conf and then open the original httpd.conf with a text editor. First, we're going to make Apache only respond when you type http://localhost in your browser address bar. Scroll down a few lines until you see
Listen 80
replace this with
Listen localhost:80
We're making this change on the assumption that you're setting the configuration up for development purposes only. For a deployment server you would leave this line as it is.
Next, we're going to tell Apache to deliver your Plone site and your static resources via http://localhost. Head down to the section marked #main server configuration and add these three lines:
RewriteEngine On RewriteRule ^/staticresources/?(.*) - [L] RewriteRule ^/(.*)$ http://localhost:8080/VirtualHostBase/http/localhost:80/[your plone site name]/VirtualHostRoot/$1 [L,P]
- it doesn't matter much where you add this, except make sure you don't insert it inside another directive. I slipped mine in just before the #Default type section.
- [your plone site name] is the name of the plone site you're working on. If you're working with the site created by the default installation, then this will be Plone.
Save the file, you'll probably have to type your password.
Now add your staticresources folder. Using Finder, go to /Library/Webserver/Documents on your Mac hard disk and add a folder there with the name staticresources.
Note this is the Library at the root of your Mac hard disk, not the Library in your own user folder
Running the Server
Start Zope/Plone in the usual way. Then open a terminal window to check your configuration file:
sudo apachectl checkconfig
or
sudo apachectl -t
will check that the configuration file you've just altered is OK, you can then start the server:
sudo apachectl start
will start Apache.
Note sudo apachectl stop will stop the server. If you make a change to your httpd.conf file, you'll need to restart Apache (sudo apachectl restart) to reload the configuration.
Now go to http://localhost/ in your browser - if everything is working you should see your Plone site. Next go to http://localhost/staticresources/ - you should see a directory listing of your staticresources folder.
Engaging your static theme
The next job is to tell collective.xdv to deliver your Plone site wrapped in your static theme through the domain http://localhost (rather than localhost:8080). Access your site via http://127.0.0.1:8080 to get the plain vanilla version and go to Site Setup - Theme transform. In the Domains box, add:
locahost
Once you've made sure that your theme transform is switched on and saved your changes, refreshing http://localhost/ in your browser should now deliver your site wrapped in your static theme.
Finally test out your staticresources folder by dropping a css file into it. Remember this folder can be found in /Library/Webserver/Documents on your hard disk. Add a link to this CSS file in the head of your theme file, the href attribute should look something like this:
href="/staticresources/test.css"
Make sure that your compiled theme will pick this up by double-checking that, in your rules file, you aren't completely replacing the head tag with the head tag generated by Plone (you'll need a prepend or an append rule to combine the Plone head tag with your theme head tag).
Variations
The above is the quick and dirty approach - designed to get you up and running as quickly as possible with minimum changes to the Apache configuration provided with your Mac - but there are other things you can do.
Relocating your Static Resources
You might want to change the physical location of your static resources on your hard disk. In that case, look for the DocumentRoot directive (and its corresponding Directory directive) in httpd.conf and edit these entries to point to your chosen folder.
Multiple Sites
If you want to see more than one Plone site through Apache, then try replacing the VirtualHost rewrite rule in your httpd.conf with this:
RewriteRule ^(.*) http://localhost:8080/VirtualHostBase/http/localhost:80/VirtualHostRoot/$1 [L,P]
You'll then need to type http://localhost/[your Plone site name]/ to see your site, but there will be no need to change the links to your static resources in your theme file. One important thing to note: if you use collective.xdv while running Zope in debug mode, you can have as many rule and theme files as you do sites on localhost (the rules and theme are compiled with every request). This is very convenient for development purposes, if, for instance, you have two projects running at once. However, this doesn't translate into production mode. With debug turned off, you are limited to one set of rules and theme files per domain. This is because the rules and theme are compiled once, when the Theme transform is switched to 'On', and then cached.
Starting and Stopping Apache
It's possible to start Apache via your System Preferences panel, go to Sharing and then turn on Web Sharing. Your Mac will tell you that users of other computers can view web pages in the Sites folder on your computer, however, this won't be the case because we've set Apache to listen for localhost:80 only. Set your httpd.conf file back to Listen 80, if you want other people to access your pages.

