Comcast, Alternative DNS and CDNs

Recently I started noticing problems with our Comcast service that although speed tests were very speedy, as were certain downloads – primarily torrents of Linux distributions, other content downloads were pathetically slow.  These would include items such as iTunes downloads, streaming content and the like.  It wasn’t until I switched my router from using Google DNS (8.8.8.8, 8.8.4.4) back to using Comcast DNS and seeing a drastic speed increase did I realize why this slowdown was occurring.  The issue here is with Content Delivery Networks (CDNs) and alternative DNS services.

CDNs are great services that replicate data across a number of data centers to offer faster access to the content by allowing you to reach a center closer to your physical location.  This allows for lower latency as your connection has to go through fewer hops so you can get a better experience.  The problem comes with using alternative DNS services such as Google DNS.  These services tend to mess with the geo-location features of the CDNs and as such, they may route you to a center that is further away which would create a slower experience for the users.

This is the problem that we were seeing.  As mentioned, once I changed us back to using Comcast’s default DNS servers, everything from iTunes downloads and general page loading times increased dramatically.  Despite my disdain for Comcast DNS, I guess I’ll be leaving that alone for a while.

AMP Stack on Mountain Lion

Last night I started getting back into coding but have since switched how I develop.  All my code is now (finally) in a local Git repository which is fantastic, but the next step was to get a local server running so I could actually see the results of my work.

In the past, I’ve used Dropbox to sync the code between my workstations and to a Linux virtual machine which ran a web server.  The problem with this setup is that when it failed, it failed miserably.  The issue here was with Dropbox.  The Linux client is quite crappy and is prone to failure very easily – at least the command line version.  The version which integrates into Nautilus seemed a lot more stable.

So, I decided to go back to my old buddy, Mac OS X and use the server capabilities built-in.  I’d check-in code and test using a local server.  However, in Mountain Lion, Apple removed “Web Sharing” from the Sharing pane of Preferences.  After a bit of searching though, it was obvious that although the GUI was removed, the services weren’t.  Follow the directions below to enable an Apache + MySQL + PHP Stack on Mountain Lion that allows .htaccess file directives and has a few tweaks to php.ini.

1.  Configure Apache

sudo vi /etc/apache2/httpd.conf

Find the php5_module and uncomment the line.

#LoadModule perl_module libexec/apache2/mod_perl.so
LoadModule php5_module libexec/apache2/libphp5.so
#LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so

Next, I changed the default virtual domain to point to my local document root and set the User/Group as myself.  I also enabled directives to allow .htaccess to work.

#User _www
#Group _www
User keith
Group staff
#DocumentRoot "/Library/WebServer/Documents"
DocumentRoot "/Users/keith/code"
#<Directory "/Library/WebServer/Documents">
<Directory "/Users/keith/code">
   Options Indexes FollowSymLinks MultiViews
   #AllowOverride None
   AllowOverride All
   Order allow,deny
   Allow from all
</Directory>

2.  Configure PHP

Next up, we need to configure PHP to have a proper date timezone set.  This reduces errors/warnings which could show up. We will also enable short_open_tags. Not necessary for most setups, but can be useful.

sudo cp /etc/php.ini.default /etc/php.ini
sudo vi /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone
date.timezone = "America/New_York"
;short_open_tag = Off
short_open_tag = On

3.  Install & Configure MySQL

The MySQL libraries are actually built-in to the PHP that ships with Mountain Lion.  If you do not need any of the command line tools and will only connect to a remote server, you can skip to the next step.

4.  Set Apache to run on boot

Run the following command to have Apache start at boot

sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false

Congratulations! You’ve now configured Apache2, MySQL and PHP to play nicely together on OS X Mountain Lion in a more standardized way than the default Apple configs would normally allow.
Leave a comment if you have any questions or suggestions!