You are now on my Technical Blog. My other sites: Personal Blog - Genealogy Blog - Genealogy Site

DLMax Max Westen's ramblings on OSX and PHP

Blog Tags: apple

Easiest local development environment on OSX

Nov 19, 2012

Create a folder in your ~/Sites folder and immediately access it with your browser by using, without changing your apache config or adding sitenames to your DNS or /etc/hosts file. That’s what you can do after following the instructions in this post!


Most of the time I’ve been using specific vhost files per webdevelopment project in a vhost folder of which all vhost files will be included. All development sites are added to the /etc/hosts file, so I could access them by a friendly-name lie

An article by Blain Smith on his local development setup made me rethink my own setup: "Can’t I just configure it to add the domainnames to the local DNS resolution too, so I only have to create a folder and immediately be able to access the site?"

Apache configuration

Current setup

I’m using the included Apache included in OSX Mountain Lion (10.8) and modified it, so it’s using 1 conf file per vhost in the /etc/apache2/vhosts folder. These get included at the end of the file /etc/apache2/httpd.config with the line:

Include /private/etc/apache2/vhosts/*.conf

in the vhosts folder I’ve created a file 1_default.conf that contains the following:

NameVirtualHost *

<VirtualHost *>
    ServerAdmin mwesten@localhost
    DocumentRoot "/Users/mwesten/Sites"
    ServerName max.local
    ServerAlias localhost

An example of the other files, in this case dlmax.conf then contains:

<VirtualHost *>
    ServerAdmin mwesten@localhost
    DocumentRoot "/Users/mwesten/Sites/dlmax"
    Options -Indexes +FollowSymLinks

Changes to this setup:

In /etc/apache2/httpd.config change the line that calls all *.conf files in the vhosts folder, to only call the virtual.conf

Include /private/etc/apache2/vhosts/virtual.conf

now create the etc/apache2/vhosts/virtual.conf to use some wildcards:

NameVirtualHost *
UseCanonicalName Off

<VirtualHost *>
  VirtualDocumentRoot "/Users/mwesten/Sites/%0"

  <Directory "/Users/mwesten/Sites">
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      Allow from all
 # If you are experiencing problems with the PHP DOCUMENT_ROOT setting, create a
 # PHP file containing the following lines:
 #   <?php
 # and uncomment the following line, pointing to the just created PHP file:
 #   php_admin_value auto_prepend_file /Users/mwesten/Sites/setdocroot.php


DOCUMENT_ROOT problems with PHP

If you are experiencing problems with your DOCUMENT_ROOT server variable, uncomment the php_admin_value line in the virtual.conf file. Add the file setdocroot.php to the path specified above and put the following in, to fix the DOCUMENT_ROOT problem described in this apache bugreport


Get the local DNS names working

Because the /etc/hosts file doesn’t parse wildcards, we cannot add something like: *.dev.

The only option is to install a local DNS server like bind or a DNS proxy like DNSMasq.

I’m using DNSMasq, because it’s the easiest to configure and less prone to configuration errors.

Install and configure DNSMasq

I’m using Homebrew as my package manager, so if you don’t use one, or use another one, you should install brew(to keep it easy) or try to follow the next steps based on your package manager.

brew install dnsmasq

Then create a textfile /usr/local/etc/dnsmasq.conf and add the following line, to redirect all *.dev sites to the local ip


Now make dnsmasq start on system-startup and start it now:

sudo cp /usr/local/Cellar/dnsmasq/2.63/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

Configure OSX to use your local system as first DNS server

Enter your network preferences and note the DNS servers named there. In my case I’m using my router, so Now add your loopback IP ( first and then your previous addres.

Now if you try to ping some address ending in .dev it should give a reply like this:

$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=0.056 ms
64 bytes from icmp_seq=1 ttl=64 time=0.079 ms
64 bytes from icmp_seq=2 ttl=64 time=0.101 ms
64 bytes from icmp_seq=3 ttl=64 time=0.075 ms
64 bytes from icmp_seq=4 ttl=64 time=0.094 ms

--- ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.056/0.081/0.101/0.016 ms

Pinging to should also work, so we know external name resolutions works well too.

Adding a new local site

Adding a site is now as easy as creating a new folder in the ~/Sites folder with the name of the local sitename, so for you would create the folder.

Setting ACL on webfolders when using GIT or SVN

Aug 27, 2012

When using a VCS(Version Control System) like SVN or GIT to deploy files to your webserver you are generally faced with some troubles with permissions.

If the website/webapplication needs permissions to write files in folders, you cannot easy chown these folders like:

sudo chown -R www-data:www-data content

When setting rights this way, the webapplication works like a charm, but updating with GIT or SVN give problems, because the user executing the update isn’t www-data.

A solution to this problem is to use ACL.

To install ACL on ubuntu

Then add the rwx right to the current running user and www-data on the folders content and config/user

sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx content config/user
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx content config/user

The move to Statamic

Jul 10, 2012


Since running my own sites, I’ve been using several techniques to keep the site running.

In 1996 when I started having my own site just HTML with javascript, in 1997 I started toying around with some vanilla PHP sites and in 2001 I put up some sites with phpNuke. In 2003 I started using Drupal and in 2005 I settled with Wordpress.

Using Wordpress for a blog/simple site felt better than using something like Drupal. Wordpress was good at not getting (too much) in the way when writing content and setting up your site.

On the other hand: Every time I had to change something on the site(this happened mostly during one of the frequent security-updates) it felt like things could and should be easier…


I’ve been looking at a lot of different CMS’es, but most of them had the same problems and needed frequent database backups to prevent losing my blogging history. Then some No-DB CMS-es got my attention.

Jekyll and Octopress

I started looking at Jekyll and then stumbled upon Octopress. I converted my Wordpress posts to markdown with the ExitWP script and pulled them into Octopress. I styled the site, created and modified several plugins and all was ready to put live… But I didn’t.

It had a lot of stuff I liked:

  • Compass generation of stylesheets
  • Use of files-only system:
    • Easy versioning with Git
    • Easy deployment
    • Easy updating of the system software

Some other things held me back in eventually using it and pushing the system live:

  • It needed a ruby system(or had to use something as github pages) to generate the files (I do like Ruby, but I don’t like the extra step to generate the html files (Yes, I know you can automate this, but it needs to be a SIMPLE system that doesn’t get in the way))
  • I need access to a system that can access my server to update and add posts, because there is no interface to add or modify stuff. (This one is both positive(security) and negative (ease of use) and the negative won in this case.)

Laravel Kudos

I started thinking on what I’d like to see in a system to use it:

  • It had to run on my Linode VPS with Apache and PHP, without me adding some obscure unmanagable extra server
  • It had to be filebased and Markdown files are a must, so I can edit them with Mou, like I do with all notes/texts I write.

While looking at Lavarel, I came across the Kudos project by Ian Landsman. I really liked the way it worked and was still considering to rewrite the Octopress site to Kudos.


Base system

While still thinking about picking this up sometime, I saw the release of Statamic in my timeline on the 20th of june. When looking at their site, I thought: "This could very well be what I was looking for!".

Within 10 minutes I bought a personal license( Hey, what’s $19,- for quality software!) for this blog and started tweaking the system to work how I want it to work.

Creating pages and pages with listings of items/posts is easy and the system works with you instead of against you. That’s quite a nice experience after using more complex systems (like Wordpress and Drupal) for websites comparable with the complexity of this blog!

Theming and styling the system is even more fun !

Start building off of the "Wild-London" theme that’s included, of just start with a framework like Zurb Foundation 3 or InuitCSS add your layouts, style your content with some templates and mix-in some partials and voila!

The building of the system is great, but the included admin interface that can be enabled eases creating and modifying your content in a way that you don’t get frustrated in writing or updating a post on your site.

Oh and the guys(Mubashar Iqbal & Jack McDade) creating the system have loads of things that will be added and are very swift in supporting their customers.

AddOns / Plugins

Because the system is just released, I ported and modified some of my plugins that I used for Octopress and added them to github for everyone to use.

FancyBox2 Image Lightbox

I like to be able to see bigger images in a lightbox on other sites and that’s exactly what I use on mine too. I’m using the nice FancyBox2; read the licensing when considering commercial use.

You can find the Fancybox addon for Statamic here.

Random Flickr badge images

I tend to place a lot of pictures on Flickr and like a way to display 9 random images in the sidebar. That’s exactly what this addon does. Just client-side with JS, so no cache is needed.

You can find the Random Flickr Badge addon for Statamic here.

Highlight.js Code Highlighting

Because most of the posts are technical and contain somesort of code or commands, I feel obliged to my readers to display the code in the best way: Color Coded. Highlight.js does a great job with that client-side, so I’ve added that in an addon.

You can find the Highlight.js Code Highlighting addon for Statamic here.

Tweets: displays latest tweets

I like to show the last tweets on my pages too. I rewrote some of the octopress stuff earlier and liked that better than the included twitter addon from Statamic, so I ported mine to Statamic.

You can find the Tweets addon for Statamic here.

Dynamic Sitemap generator

You can use a semi-dynamic way to generate the sitemap, like Eric Barnes explains in his post on "Statamic Sitemap".

I like it a bit more dynamic though; It needs to fetch all non-hidden pages and add a changefreq and priority to it that is a bit more flexible:

  • changefreq based on the last modification date; the longer untouched, the longer the changefreq
  • The priority based on folder/pagetype or even use a standard that can be overridden in the page YAML.

Because of my health, it’s a work in progress right now. I’ll add an extra post once it’s ready.

When it’s ready, You can find the Dynamic Sitemap addon for Statamic here.

Setting up MockSMTP on OSX 10.7(Lion) for local PHP development

Jun 01, 2012

** NOTE ** : This post was sitting in my drafts for way too long (over 7 months now), so I’ll just post it in the hopes someone likes it. There could be rough edges here and there, but hey, that’s what the contact page is for… ;)

Because I tend to do some PHP development on my MacBookPro runnin OSX 10.7(Lion) and want to be able to test the email-functionality, without the system actually sending email to people, I was on the lookout for an easy way to accomplish this in such a way, that I would be able to collect all mail and display both text and HTML versions of it. I found MockSMTP, and it works like a charm. In this post we’ll set it up and configure the system to route all mail to MockSMTP, even when it’s not running.

Install MockSMTP (via the AppStore or download it from their website)

Open the terminal and enter the following command to reroute all traffic on port 25 to port 1025 on the local system.

sudo ipfw add 1025 forward,1025 ip from any to any 25 in

Edit the Postfix file from the postfix configuration folder:

sudo /etc/postfix/nano

Add the following at the end of the file:

relayhost = localhost:1025

Make sure the line reading "mydomain_fallback = localhost" is witten as: "mydomain_fallback=localhost" so without the spaces, to prevent any runtime warnings.

In OSX Lion a new version of postfix is installed, so we need an extra file to deliver mail:

sudo touch /etc/postfix/submit.cred
sudo nano /etc/postfix/submit.cred

Add the following lines:

submitcred version 1

(Note: the username and password can be used literally here, they don’t need to match your account credentials!)

Check the maillog in a new terminal tab/window. This monitors new lines written to the logfile. This way you can troubleshoot and see if messages are sent correctly. (Ctrl+C to stop)

tail -f /var/log/mail.log

Start Postfix and make sure it will restart on system boot: enter in the terminal:

sudo launchctl load -w /System/Library/LaunchDaemons/org.postfix.master.plist

Afterwards to stop or start the service use:

sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist
sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist

Start the MockSMTP application and make sure it is listening on port 1025 (see the status in the bottom of the screen). MockSMTP Status

Now try to send a testmail:

echo "This is the body of a text test-mail" | mail -s "Email test"

And all went well, we now have a testmail in our MockSMTP app. MockSMTP mailmessage

Because we used the IP Port Forward, mail sent by any application that tries to use the local SMTP server (localhost:25) or sendmail/postfix will be rerouted to MockSMTP. If the MockSMTP app is not running, mail will be spooled and will be delivered when you run the app again.

Have fun developing…

Developing in PHP with NetBeans 6.8

Nov 25, 2009

The problem:

I love Textmate as an editor period.

There are some things though that I started missing while developing:

  • Code completion
  • Inline documentation
  • instant error checking
  • debugging from my editor
  • must have strong syntax highlighting support for dark themes like my favourite Sunburst

So I started looking around for an IDE(or Editor) that would work for me and that I could adhere to.

The contestants:


I’ve heard a lot on VIM and really like the application. When you add a couple of plugins like Project, PHP-Doc, DelimitMate, SnipMate and Sunburst you can accomplish most of these tasks. An added feature is that you can configure VIM to work the same on your remote systems too, so it virtually doesn’t matter if you’re on Mac, Windows or Linux or working trough an SSH connection; your editor functions and looks the same. Most features from my list can be accomplished in VIM, but I can’t get used to the shortcuts. There are a lot of them and all of them are new compared to windows/mac users. If you’re in a full-time development job I think it’s very difficult to learn the new way of working and still deliver on time. So for me VIM isn’t something that can be used out of the box.

Eclipse PDT:

Eclipse with PDT 2.1 is another IDE I hear a lot of good comments on. All of the things I want to see in an alternative editor/IDE is there, except for the strong Syntax highlighting and easy themeing. Colours can be changed, but have to be changed on a lot of different locations, making it hard to do consistently. The PDT plugin has some nice features, but the syntax highlighting could be much better. Eclipse with PDT isn’t my thing because of the lack of syntax highlighting features, the difficult themeing (especially to darker themes) and the high memory consumption.


Aptana Studio 2.0 is a good IDE (I’ve used it before) with a very nice PHP plugin, but changed to use the PDT eclipse plugin. There is a way to use the older PHP plugin, but because development on that plugin has ceased, I don’t recommend it. The PDT plugin with Aptana has lacks the same points as discussed above under "Eclipse PDT".

Zend Studio:

Zend Studio 7.1 basically is Eclipse with the PDT plugin and some added features; specifically focussed on "Zend Framework", "Zend Server" and "Zend Debugger". Zend Studio isn’t a fit for me, because the problems I have with the Eclipse PDT plugin are the features taken from this plugin. If these points would improve it would be a good choice for me. The price could be a turnoff though if a free IDE is available that can do most you need.

Komodo IDE:

Komodo IDE 5.2 is a stable IDE and has a smaller memory footprint then the eclipse based tools. It has support for a multitude of languages, VCS(=Version Control Systems). The support for PHP and debugging are good and this is one of the few IDEs that are quite easy to style in a dark background. There are only 2 downsides for me; the price and the syntax highlighting could be even better. The price isn’t that high for a business, but I found an alternative that fits me better.


Netbeans 6.8 (currently in beta) is like Komodo a stable IDE with smaller memory footprint. It fits my wish-list and I can adapt quite easily to the shortcuts and natural for me. It’s a full featured IDE with all the bells and whistles. Room for improvement would be: More VCS plugins (Git), support for the Zend Debugger, scriptable (regexp) like syntax highlighting support, to be able to add custom highlighting.

NetBeans Tips:

Font rendering in NetBeans on OSX:

I love the anti-aliasing done by TextMate to my coding fonts. If you want to achieve the same effect in NetBeans, you need to add 2 parameters to the application startup-file.

  1. Open the finder and go to the file.
  2. Press the right mouse-button (or ctrl+click) and select the option "Show Package Contents".
  3. In the new opened finder window, go to the following location: "Contents/Resources/NetBeans/etc/"
  4. Edit the file: "netbeans.conf"
  5. add the following to the end of the line starting with: "netbeans_default_options=" -J-Dsun.java2d.noddraw=true
  6. save the file and start NetBeans.

The font will be like you used to see in TextMate.

Preventing Java crashes on OSX 10.6:

Update: I’ve updated to the final 6.8 release now and it runs fine on Java 6, so this workaround is probably not needed….

If you are working on OSX Snow Leopard (10.6) and NetBeans crashes randomly, it’s worth a try to downgrade your Java from 6 to 5. This probably greatly improves stability for NetBeans and other Java applications running on OSX. To downgrade, I followed the steps outlined on the oneswarm wiki and put them up here too.

Get the java 5 that was included in 10.5 "leopard" and unpack

cd /tmp/
curl -o java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz

Move it to your System java folder (password needed)

sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard

Tell OS X that java 5 actually is java 5

cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo ln -s 1.5.0-leopard 1.5.0
sudo rm 1.5
sudo ln -s 1.5.0 1.5

Open Java Preferences

open "/Applications/Utilities/Java"

Change the properties to use Java 5 32-bit by default:

Start NetBeans and you’re done !