Setting up local websites on Snow Leopard
A short tutorial on setting up local websites on Snow Leopard.
Not keen on the command line? Using something like MAMP may be a better option for you. I’m using vi to edit the files but feel free to use your text editor of choice (TextMate, emacs etc).
Step 1 - Creating your site ¶
On OSX websites are stored in /Users/yourname/Sites so it is a good idea to store your site in there. Let’s create a site in there. Note you’ll need to change yourname in the example to whatever your name is.
printf "My awesome site" > index.html
Great - we’ve created our site. Now let’s set up Apache.
Step 2 - Setting up Apache ¶
First we need to allow virtual hosts by uncommenting a line in the Apache config file
sudo vi +/'# Virtual hosts' /etc/apache2/httpd.conf
Save the file and exit
Step 3 - Adding the virtual host ¶
Now we can add the virtual host
sudo vi /etc/apache2/extra/httpd-vhosts.conf
Add the following to the end of the file. Remember to change ‘yourname’ to whatever your name is and also ‘mysite.com’ to whatever your site folder name is. ServerName is the name you will use to access the site from a browser so if you want something specific change it.
Options +FollowSymlinks +SymLinksIfOwnerMatch
Step 4 - Setting your hosts file ¶
As there is no DNS associated with your site we need to set this.
sudo vi /etc/hosts
Add the following. This relates to the ServerName you set in the Step 2
Step 4 - Start Apache ¶
Now we just need to start apache
sudo apachectl start
If you see
org.apache.httpd: Already loaded
Then it is already running so restart it using
sudo apachectl restart
Now open a browser and visit http://mysite.local/ (or whatever ServerName you set). All being well you should see a page displaying “My awesome site”
Step 5 - Enable PHP ¶
If you need PHP then this needs to be enabled. You can do this using
sudo vi +/php5_module /etc/apache2/httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so
Then save and exit. Finally we need to restart apache:
sudo apachectl restart
Now lets see if PHP is running ok:
printf "<?php phpinfo() ?>" > index.php
Now if you open a browser and visit http://mysite.local/index.php you should see the phpinfo() page. Apache is set to serve index.html before index.php so if you delete the index.html you will also be able to access the phpinfo() page at http://mysite.local.
All done! To add further sites just repeat steps 3, 4 and 5.
Can you help make this article better? You can edit it here and send me a pull request.
ExpressionEngine permissions shell script
Every ExpressionEngine install requires that a number of permissions are set on folders and files. Here's a shell script to do the hard work for you.
Using custom shell scripts on OSX or Linux
Custom shell scripts allow you to do pretty much anything. Here's a short tutorial on how to set up either OSX or Linux so you can use custom shell scripts on your system.
ExpressionEngine plugin - Friendly 404 pages
I've written a simple plugin for ExpressionEngine that suggests valid pages to users based on the final segement of a 404 page.