<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dean Clatworthy</title>
	<atom:link href="http://deanclatworthy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://deanclatworthy.com</link>
	<description>I build websites for a living. PHP/MySQL, Javascript, CSS, HTML5</description>
	<lastBuildDate>Tue, 18 Jun 2013 13:43:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Facebook: The new giant of advertising?</title>
		<link>http://deanclatworthy.com/2013/06/facebook-the-new-giant-of-advertising/</link>
		<comments>http://deanclatworthy.com/2013/06/facebook-the-new-giant-of-advertising/#comments</comments>
		<pubDate>Tue, 18 Jun 2013 13:38:46 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=356</guid>
		<description><![CDATA[Last week Facebook rolled out a new update that lets people tag what they&#8217;re doing in their post or say how they are feeling. Users can say they are watching a movie or reading a book &#8211; amongst other things. What makes this different from before is that your status update is providing more structured data [...]]]></description>
				<content:encoded><![CDATA[<p>Last week Facebook <a href="http://newsroom.fb.com/News/600/Adding-What-You-re-Doing-to-Status-Updates">rolled out a new update</a> that lets people tag what they&#8217;re doing in their post or say how they are feeling. Users can say they are watching a movie or reading a book &#8211; amongst other things. What makes this different from before is that your status update is providing more structured data to Facebook about your activity.<span id="more-356"></span></p>
<p>For example, when you went to the movie theatre, before you might have just typed a status update such as: &#8220;At the movies seeing the new Batman&#8221;. Unfortunately for Facebook there are 1000s of different ways to say you&#8217;re at the movies, across 1000s of different languages used on their platform. The problem of trying to analyse what a user is doing from text is a difficult one to solve. But Facebook now made it easier.</p>
<p>More worryingly, however, is that facebook now lets you tag how you are feeling. The only way to do this previously was using sentiment analysis where the text you type is analysed for keywords to detect the sentiment in what you are saying, or in other words how you are feeling. This is an extremely difficult problem to solve, far more than looking for keywords that try and figure out what you are doing. Now whenever you attach your &#8220;feeling&#8221; to a facebook post, facebook knows in that moment much more about you.</p>
<p>Facebook now has one of the biggest advertising platforms around, <a href="http://techcrunch.com/2013/05/01/facebook-mobile-ad-revenue/">bringing in revenue of $1.25 billion in Q1, 2013</a>. You&#8217;ve long been able to target demographics in Facebook as they know so much about you. If you had a new hair spray piloting in the United States, you could target 18-21 year old Females, living in the US. Facebook even allows you to specifically target users based on their interests, so in this example the advertiser might target girls interested in beauty, or hair styling.</p>
<p>The new changes to Facebook will most likely allow Facebook to allow advertisers to target advertising not only based on who you are, what you are interested in but how you are feeling at the time. Last week, Microsoft announced to gamers that their console would cost $100 more at launch than Sony&#8217;s. Gaming is a hot topic on social networks, so Sony could specifically target advertising at key moments where users on social media are &#8220;feeling angry&#8221; and have an interest in Microsoft&#8217;s console. Another example could be targeting people who are &#8220;feeling tired&#8221; with energy drinks.</p>
<p>The current market leader in online advertising, Google, has their own social network they could use to leverage this data and target advertisements more effectively, but there aren&#8217;t as many people using it and they don&#8217;t have as much aggregated meta-data on their users. Furthermore their advertising efforts are centered around browsing history and search history, rather than who the user is.</p>
<p>Facebook has positioned itself to become the market leader in online advertising. Through its variety of methods they can target users far more accurately at a specific moment in time than any other advertiser currently can, and with the amount of users they have information on, and the amount of information they posses about them, revenues will continue to rise as advertisers realise the potential opportunities of the platform.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/06/facebook-the-new-giant-of-advertising/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web fonts not loading in Firefox</title>
		<link>http://deanclatworthy.com/2013/06/web-fonts-not-loading-in-firefox/</link>
		<comments>http://deanclatworthy.com/2013/06/web-fonts-not-loading-in-firefox/#comments</comments>
		<pubDate>Tue, 11 Jun 2013 10:28:29 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=352</guid>
		<description><![CDATA[I encountered a peculiar issue today regarding web fonts on firefox. On all browsers except Firefox the web fonts were loading correctly. I found multiple references suggesting that Firefox was picky with using quotes when referencing where the font file is hosted. However my findings were more interesting: Firefox does not support embedding webfont files [...]]]></description>
				<content:encoded><![CDATA[<p>I encountered a peculiar issue today regarding web fonts on firefox. On all browsers except Firefox the web fonts were loading correctly. I found multiple references suggesting that Firefox was picky with using quotes when referencing where the font file is hosted. However my findings were more interesting:</p>
<p><strong>Firefox does not support embedding webfont files from a different domain</strong></p>
<p>The good news is the fix is simple. Simply send the following header:</p>
<pre>
Access-Control-Allow-Origin *
</pre>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/06/web-fonts-not-loading-in-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ensuring facebook canvas applications work in IE8 / IE9 / IE10</title>
		<link>http://deanclatworthy.com/2013/05/ensuring-facebook-canvas-applications-work-in-ie9/</link>
		<comments>http://deanclatworthy.com/2013/05/ensuring-facebook-canvas-applications-work-in-ie9/#comments</comments>
		<pubDate>Fri, 17 May 2013 07:46:29 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.deanclatworthy.com/?p=223</guid>
		<description><![CDATA[Last week I deployed a new Facebook application into a production environment. Everything seemed to be working perfectly, but then I received a report that the application wasn&#8217;t working correctly in IE8+. I narrowed down the problem, and then realised that sessions weren&#8217;t working. It turns out IE8+ has a security policy that prevents iframes [...]]]></description>
				<content:encoded><![CDATA[<p>Last week I deployed a new Facebook application into a production environment. Everything seemed to be working perfectly, but then I received a report that the application wasn&#8217;t working correctly in IE8+. I narrowed down the problem, and then realised that sessions weren&#8217;t working. It turns out IE8+ has a security policy that prevents iframes from setting cookies if the parent domain is different. Therefore because my PHP session cooking wouldn&#8217;t set, the sessions obviously didn&#8217;t work between pages.</p>
<p>The good news is the fix is simple. Add this header to your page:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p3p: CP=&quot;NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you want to read more about this check this page:</p>
<p>http://en.wikipedia.org/wiki/P3P</p>
<p>Bonus: if using silex add this middleware:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$app</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>Request <span style="color: #000088;">$request</span><span style="color: #339933;">,</span> Response <span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headers</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p3p'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'CP=&quot;NOI ADM DEV PSAi COM NAV OUR OTR STP IND DEM&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/05/ensuring-facebook-canvas-applications-work-in-ie9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install different locales on a fresh debian installation</title>
		<link>http://deanclatworthy.com/2013/05/how-to-install-different-locales-on-a-fresh-debian-installation/</link>
		<comments>http://deanclatworthy.com/2013/05/how-to-install-different-locales-on-a-fresh-debian-installation/#comments</comments>
		<pubDate>Fri, 10 May 2013 09:54:05 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=347</guid>
		<description><![CDATA[Simples: sudo dpkg-reconfigure locale This will load a GUI where you should select the new locales to install, then follow the onscreen instructions.]]></description>
				<content:encoded><![CDATA[<p>Simples:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dpkg-reconfigure locale</pre></td></tr></table></div>

<p>This will load a GUI where you should select the new locales to install, then follow the onscreen instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/05/how-to-install-different-locales-on-a-fresh-debian-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silex Tip #1: How to quickly invalidate a form field in your controller</title>
		<link>http://deanclatworthy.com/2013/05/silex-tip-1-how-to-quickly-invalidate-a-form-field-in-your-controller/</link>
		<comments>http://deanclatworthy.com/2013/05/silex-tip-1-how-to-quickly-invalidate-a-form-field-in-your-controller/#comments</comments>
		<pubDate>Fri, 10 May 2013 09:34:06 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=343</guid>
		<description><![CDATA[You should be using custom constraints to validate your form fields, however there are some use-cases where you need to quickly invalidate in a controller. To do this it&#8217;s quite easy: $form-&#38;gt;get&#40;'username'&#41;-&#38;gt;addError&#40;new \Symfony\Component\Form\FormError&#40;&#34;This email is already in use&#34;&#41;&#41;;]]></description>
				<content:encoded><![CDATA[<p>You should be using <a href="http://symfony.com/doc/master/cookbook/validation/custom_constraint.html">custom constraints</a> to validate your form fields, however there are some use-cases where you need to quickly invalidate in a controller. To do this it&#8217;s quite easy:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$form</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>addError<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> \Symfony\Component\Form\FormError<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;This email is already in use&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/05/silex-tip-1-how-to-quickly-invalidate-a-form-field-in-your-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crawling UTF-8 pages using the Symfony2 DomCrawler component</title>
		<link>http://deanclatworthy.com/2013/04/crawling-utf-8-pages-using-the-symfony2-domcrawler-component/</link>
		<comments>http://deanclatworthy.com/2013/04/crawling-utf-8-pages-using-the-symfony2-domcrawler-component/#comments</comments>
		<pubDate>Sun, 21 Apr 2013 16:11:49 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=338</guid>
		<description><![CDATA[Just a small gotcha for anyone using Symfony2&#8242;s DomCrawler component. The standard behaviour of the class (from the current docs) is: $crawler = new Crawler&#40;$html&#41;; &#160; foreach &#40;$crawler as $domElement&#41; &#123; print $domElement-&#62;nodeName; &#125; However, this will assume the document is ISO-8859-1. If you want to crawl a UTF-8 page correctly do it like so: [...]]]></description>
				<content:encoded><![CDATA[<p>Just a small gotcha for anyone using Symfony2&#8242;s DomCrawler component. The standard behaviour of the class (from the current docs) is:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$crawler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Crawler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$crawler</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$domElement</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #000088;">$domElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>However, this will assume the document is ISO-8859-1. If you want to crawl a UTF-8 page correctly do it like so:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$crawler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Crawler<span style="color: #339933;">;</span>
<span style="color: #000088;">$crawler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHTMLContent</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.columbia.edu/~fdc/utf8/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$crawler</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$domElement</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">print</span> <span style="color: #000088;">$domElement</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The second parameter to addHTMLContent is &#8216;UTF-8&#8242; by default, but I&#8217;ve added it to illustrate that you could use other character sets too.</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/04/crawling-utf-8-pages-using-the-symfony2-domcrawler-component/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Intel X25-M SSD&#8217;s don&#8217;t work with Mac OSX 10.8.3</title>
		<link>http://deanclatworthy.com/2013/04/intel-x25-m-ssds-dont-work-with-mac-osx-10-8-3/</link>
		<comments>http://deanclatworthy.com/2013/04/intel-x25-m-ssds-dont-work-with-mac-osx-10-8-3/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 07:14:38 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=334</guid>
		<description><![CDATA[I&#8217;m writing this informative post to try and help anyone who had the same problem as me. I upgraded to OSX 10.8.3, and after it restarted the machine the Apple logo and spinner was on screen for about a minute followed by a stop/forbidden/no entry symbol that looks like this: &#160; I couldn&#8217;t boot into [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m writing this informative post to try and help anyone who had the same problem as me. I upgraded to OSX 10.8.3, and after it restarted the machine the Apple logo and spinner was on screen for about a minute followed by a stop/forbidden/no entry symbol that looks like this:<span id="more-334"></span></p>
<p><a href="http://deanclatworthy.com/wp-content/uploads/2013/04/osx-noentry.jpg"><img class="alignnone size-full wp-image-335" alt="osx-noentry" src="http://deanclatworthy.com/wp-content/uploads/2013/04/osx-noentry.jpg" width="599" height="449" /></a></p>
<p>&nbsp;</p>
<p>I couldn&#8217;t boot into safe mode (by holding shift on boot). I could enter the internet recovery mode, but a drive repair and permissions fix did nothing. I tried using the internet recovery mode to reinstall OSX (without losing data) and that didn&#8217;t work.</p>
<p>Next I reinstalled OSX from a bootable USB recovery drive. This installed 10.8.2 again which worked perfectly. I immediately upgraded to 10.8.3 and the no entry sign was back. This told me there was some issue with my hardware and 10.8.3. A quick google around found that Intel X25-M drives don&#8217;t work on 10.8.3 unless you upgrade to the most recent firmware. The good news is this is super easy.</p>
<p>Download the <a href="http://www.intel.com/go/ssdtoolbox">Intel SSD toolbox</a> on a windows machine. Shut down the machine and insert the drive from your mac. Boot up again and run the toolbox and update the firmware. It takes less than 20 seconds and then put the drive back in your mac and it should boot into 10.8.3 without issue.</p>
<p>Don&#8217;t do what I did and wipe your data, as there is no need!</p>
<p>Hopefully this article will be of help to a few people out there! Let me know in the comments if it was.</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/04/intel-x25-m-ssds-dont-work-with-mac-osx-10-8-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating from apache to nginx (wordpress edition)</title>
		<link>http://deanclatworthy.com/2013/02/migrating-from-apache-to-nginx-wordpress-edition/</link>
		<comments>http://deanclatworthy.com/2013/02/migrating-from-apache-to-nginx-wordpress-edition/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 13:03:14 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=326</guid>
		<description><![CDATA[Today I migrated my whole site from apache to nginx. The main reason for this being that nginx seems to handle load and use less memory on smaller boxes. It&#8217;s also an opportunity for me to try something new. I&#8217;ll cut straight to the chase. There&#8217;s some great information already available. At the time of [...]]]></description>
				<content:encoded><![CDATA[<p>Today I migrated my whole site from apache to nginx. The main reason for this being that nginx seems to handle load and use less memory on smaller boxes. It&#8217;s also an opportunity for me to try something new.</p>
<p>I&#8217;ll cut straight to the chase. There&#8217;s some <a href="http://codex.wordpress.org/Nginx">great information</a> <a href="http://wiki.nginx.org/WordPress">already available</a>. At the time of this writing though, both sets of instructions didn&#8217;t work for me. I&#8217;ll come to why later.<br />
<span id="more-326"></span></p>
<p>The first thing you want to do is install nginx and php5-fpm. Before you do this <a href="http://www.dotdeb.org/instructions/">add dotdeb to your sources list</a>. Don&#8217;t forget to update your packages.</p>
<p>Now we can install nginx and php5-fpm:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> nginx php5-fpm</pre></td></tr></table></div>

<p>In nginx, there&#8217;s no such thing as virtual hosts. We call them server blocks, but they work similarly. Let&#8217;s create one. Create a file at<br />
/etc/nginx/sites-available/` called `yourdomain.com` with these contents:</p>
<pre>server {
                listen 80;
                server_name yourdomain.com;

                access_log /var/log/nginx/yourdomain.com.access_log;
                error_log /var/log/nginx/yourdomain.com.error_log;

                root /var/www/yourdomain.com/public_html;
                index index.php index.htm index.html;

                include /etc/nginx/global/wordpress.conf;
                include /etc/nginx/global/restrictions.conf;
       }</pre>
<p>This creates a server block, which listens on port 80, with webroot at /var/www/yourdomain.com/public_html. It then includes two configuration files which we&#8217;ll come to now.</p>
<p>Now create a file at /etc/nginx/global/wordpress.conf with contents:</p>
<pre># WordPress single blog rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
        try_files $uri $uri/ /index.php?$args;
}

# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
       access_log off; log_not_found off; expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-wp-super-cache.conf;
#include global/wordpress-w3-total-cache.conf;

# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
        # Zero-day exploit defense.
        # http://forum.nginx.org/read.php?2,88845,page=3
        # Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine.  And then cross your fingers that you won't get hacked.
        try_files $uri =404;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#       fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
}</pre>
<p>This file is very important and one value particularly is of interest to us. The fastcgi_pass variable is critical if you want PHP to work. When PHP-FPM is running, it listens on a socket. Dependent on your distribution and package this value might be different. Every tutorial I tried suggested pointing this value to 127.0.0.1:9000 but this was not the case with my system. If you open /etc/php5/fpm/pool.d/www.conf there is a configuration value called &#8220;listen&#8221;. This is what you should set the fastcgi_pass variable to.</p>
<p>Finally, create a file at /etc/nginx/global/restrictions.conf to handle some security:</p>
<pre>
# Global restrictions configuration file.
# Designed to be included in any server {} block.</p>
location = /favicon.ico {
        log_not_found off;
        access_log off;
}

location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
        deny all;
}

# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
}
</pre>
<p>Now all of our configuration is in place, we need to shut down apache, and start nginx and php5-fpm:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 stop
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>php5-fpm restart
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>nginx start</pre></td></tr></table></div>

<p>Your site should now be running nginx. Confirm this by visiting it and of course checking to see if the process is running:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> nginx</pre></td></tr></table></div>

<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/02/migrating-from-apache-to-nginx-wordpress-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browse safely, and avoid drive-by attacks in Google Chrome</title>
		<link>http://deanclatworthy.com/2013/02/browse-safely-and-avoid-drive-by-attacks-in-google-chrome/</link>
		<comments>http://deanclatworthy.com/2013/02/browse-safely-and-avoid-drive-by-attacks-in-google-chrome/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 11:15:48 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://deanclatworthy.com/?p=319</guid>
		<description><![CDATA[With the increased number of drive-by attacks happening lately, I decided to investigate how these attacks work and what can be done to prevent them. The way in which drive-by attacks work is simple. A hacker breaks into a website and edits the source code of the page to deliver malware to the user. Usually [...]]]></description>
				<content:encoded><![CDATA[<p>With the <a href="http://www.theregister.co.uk/2013/02/22/nbc_hack/">increased</a> <a href="http://threatpost.com/en_us/blogs/mysqlcom-site-hacked-was-serving-malware-092611">number</a> of <a href="http://nakedsecurity.sophos.com/2012/12/03/dockster-mac-malware-dalai-lama/">drive-by</a> <a href="http://www.messagingnews.com/eyeonmessaging/stephanie-jordan/several-large-frequently-visited-sites-still-serving-malware">attacks</a> happening lately, I decided to investigate how these attacks work and what can be done to prevent them.<span id="more-319"></span></p>
<p>The way in which drive-by attacks work is simple. A hacker breaks into a website and edits the source code of the page to deliver <a href="http://en.wikipedia.org/wiki/Malware">malware</a> to the user. Usually this is works by the hacker creating their own web page and then loading that through an iframe on the site they broke into. This results in a subtle, but very effect method of attacking user&#8217;s machines as the iframe is normally hidden so the user doesn&#8217;t even see it.</p>
<p>The reason this is called a drive-by attack is because you are extremely unlikely to have noticed it happened. The most effective hackers will use a <a href="http://en.wikipedia.org/wiki/Zero-day_attack">0-day attack</a> which often means that the malware is not present in anti-virus databases, so the only method of detection from an anti-virus is to rely on heuristic methods which detect unusual activity on your system. Experience has shown that this is extremely difficult to do and often these drive-by attacks go unseen.</p>
<p>The exploits used in most of these attacks target browser plug-ins as they are installed on almost every browser of every system. Popular plugins such as Flash and Java are installed on most new machines by default, and if they aren&#8217;t updated by the user then they become a common attack vector for hackers.</p>
<p>So that leads me to my question: what can we do about it?</p>
<p>More recent builds of Google Chrome come with a fantastic feature which enables you to disable plugins by default, and only allow them to play if you explicitly click them. Let&#8217;s look into how to turn that on. In the top right corner of your browser click the menu icon and go to settings (If you&#8217;re on Windows you can click Ctrl+, or Mac Command+,).</p>
<p><a href="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.11.02-PM.png"><img class="alignnone size-full wp-image-320" alt="Screen Shot 2013-02-26 at 1.11.02 PM" src="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.11.02-PM.png" width="275" height="436" /></a></p>
<p>&nbsp;</p>
<p>Next, at the bottom of the page click &#8220;Show advanced settings&#8221;.</p>
<p>Under the &#8220;Privacy&#8221; section click the &#8220;Content Settings&#8221; button and scroll down to the &#8220;Plugins&#8221; section. We want to change this setting to &#8220;Click to Play&#8221;:</p>
<p><a href="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.13.09-PM.png"><img class="alignnone size-full wp-image-321" alt="Screen Shot 2013-02-26 at 1.13.09 PM" src="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.13.09-PM.png" width="266" height="195" /></a></p>
<p>&nbsp;</p>
<p>Finally, click the &#8220;Manage exceptions&#8230;&#8221; button so that we can whitelist some sites that are most likely safe to run plugins on. I have added youtube like so:</p>
<p><a href="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.14.25-PM.png"><img class="alignnone size-full wp-image-322" alt="Screen Shot 2013-02-26 at 1.14.25 PM" src="http://deanclatworthy.com/wp-content/uploads/2013/02/Screen-Shot-2013-02-26-at-1.14.25-PM.png" width="539" height="347" /></a></p>
<p>Remember, when you add a site to this whitelist all plugins will run on it, so only add to this list if a site relies on a plugin to operate or it becomes really inconvenient having to click every time.</p>
<p>And that&#8217;s it! Enjoy browsing the web more safely and please give feedback in the comments or <a href="https://twitter.com/deanclatworthy">follow me on twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/02/browse-safely-and-avoid-drive-by-attacks-in-google-chrome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to avoid relying on github: mirror your repository</title>
		<link>http://deanclatworthy.com/2013/01/how-to-avoid-relying-on-github-mirror-your-repository/</link>
		<comments>http://deanclatworthy.com/2013/01/how-to-avoid-relying-on-github-mirror-your-repository/#comments</comments>
		<pubDate>Mon, 14 Jan 2013 08:13:25 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.deanclatworthy.com/?p=300</guid>
		<description><![CDATA[One of the things that recent github outages have highlighted is that although git is designed to be decentralized version control system, many people are not treating it that way. Rather than having multiple remotes, people push to the same place and generally rely too much on github. I&#8217;ve seen people build their whole infrastructure [...]]]></description>
				<content:encoded><![CDATA[<p>One of the things that <a href="https://github.com/blog/1364-downtime-last-saturday">recent github outages</a> have highlighted is that although git is designed to be decentralized version control system, many people are not treating it that way. Rather than having multiple remotes, people push to the same place and generally rely too much on github. I&#8217;ve seen people build their whole infrastructure around github, including deploy scripts for their sites and install scripts for new developers. Furthermore, dependency managers such as <a href="http://getcomposer.org/">Composer</a> &amp; <a href="http://cocoapods.org/">Cocoapods</a> (not intending to single anyone out) rely on github to pull in dependencies. If github goes down, you can&#8217;t fix your dependencies or pull in new ones. In an ideal world these dependency managers should have built in support for mirrors, but I&#8217;m not aware of any such feature at the time of writing.</p>
<p><span id="more-300"></span></p>
<p><strong>What I&#8217;m going to illustrate is how easy it is to set up your git remotes so you push to two places</strong>. If github goes down, it doesn&#8217;t matter, assuming everyone on your team follows this guide the code will also be on bitbucket, or wherever else you choose. But this tutorial will mirror to github &amp; bitbucket. Let&#8217;s begin.</p>
<ol>
<li><span style="line-height: 14px;" data-mce-mark="1"><span style="line-height: 14px;" data-mce-mark="1">Firstly, I&#8217;m going to assume you have a remote set up already for github named &#8220;origin&#8221;. Rename it to &#8220;github:<br />
</span></span></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git remote</span> rename origin github</pre></td></tr></table></div>

</li>
<li>Create a new repository on bitbucket and name it the same as the one on github.</li>
<li>Add it as a remote using the instructions provided. But make sure you call it &#8220;bitbucket&#8221; and not &#8220;origin&#8221;. Something like so:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git remote</span> add bitbucket ssh:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">/</span>somerepo.git
<span style="color: #c20cb9; font-weight: bold;">git push</span> <span style="color: #660033;">-u</span> bitbucket <span style="color: #660033;">--all</span></pre></td></tr></table></div>

</li>
<li>Next type:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git config</span> <span style="color: #660033;">-e</span></pre></td></tr></table></div>

<p>This will open up a text editor and allow you to edit your git configuration.</li>
<li>We need to add the urls for every remote so far (github and bitbucket) into a new remote called &#8220;origin&#8221;. It should look something like this:

<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>remote <span style="color: #ff0000;">&quot;origin&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    url = <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com:username<span style="color: #000000; font-weight: bold;">/</span>somerepo.git
    url = ssh:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">/</span>somerepo.git</pre></td></tr></table></div>

</li>
<li>Next time you run <code>git push origin </code> it will push to both</li>
</ol>
<p>And that&#8217;s it. It&#8217;s as simple as that.</p>
<p>Recent of versions of git allow you to add multiple places per remote like this using git commands, but I prefer to see exactly what is going on in the configuration.</p>
<p><strong>Update #1: </strong>reddit user MatmaRex <a href="http://www.reddit.com/r/programming/comments/16jk97/how_to_avoid_relying_on_github_mirror_your/c7wnycx">makes a very valid point</a> to be careful renaming remotes if you have any remote branches. I&#8217;ve updated the instructions to reflect this.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://deanclatworthy.com/2013/01/how-to-avoid-relying-on-github-mirror-your-repository/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
