Nuclear Rooster

9May/100

Web-enable your OS X Documents folder

What?

Give apache access to your Documents folder, so you can view your documents in a browser.

Why?

Working with web technologies, you can't (or shouldn't) avoid HTML, PHP and JavaScript. Apple provides the default webserver serving files from /Library/WebServer/Documents, and your user vhost under ~/Sites, but I don't find either very convenient. I keep all of the projects under ~/Documents, and I want to be able to view those files in a browser as well.

Some of this could be done through a browser over file://, but I find it easier to set it up this way. Additionally, when developing Flash/Flex apps, the security sandbox model can necessitate using HTTP.

How?

First, create a virtual host file with the configuration details at /private/etc/apache2/extra/documents_vhost.conf. Replace USERNAME with your username. I chose port 1234, because it is easy to remember, but you can replace that with a port of your choosing.

<VirtualHost 127.0.0.1:1234>
    DocumentRoot "/Users/USERNAME/Documents"
    ServerName 127.0.0.1
	<Directory "/Users/USERNAME/Documents">
	    Options Indexes FollowSymLinks MultiViews
	    AllowOverride All
	    Order allow,deny
	    Allow from all
	</Directory>
</VirtualHost>

Edit the main apache configuration file, /private/etc/apache2/httpd.conf. Add the following to the bottom.

# Tell apache to listen to requests on this port
Listen 1234
# Include the vhost details
Include /private/etc/apache2/extra/documents_vhost.conf

Lastly, you have to change the permissions of your Documents folder so that it has read and execute permissions, required by Apache to read from it.

chmod 711 ~/Documents

Restart apache

sudo /usr/sbin/apachectl graceful

and visit your Documents folder in your browser at http://127.0.0.1:1234/.

Tagged as: , No Comments