<?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>david winter</title>
	<atom:link href="http://davidwinter.me.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidwinter.me.uk</link>
	<description>you were expecting someone else?</description>
	<lastBuildDate>Sun, 22 Aug 2010 20:51:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Capistrano to deploy Mercurial changes</title>
		<link>http://davidwinter.me.uk/articles/2010/08/22/using-capistrano-to-deploy-mercurial-changes/</link>
		<comments>http://davidwinter.me.uk/articles/2010/08/22/using-capistrano-to-deploy-mercurial-changes/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 20:51:19 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=229</guid>
		<description><![CDATA[We have a few production servers at work, and we have a central bitbucket repository to store our core code. Once we make a change on our testing server (!), we used to have to commit, push changes to bitbucket, and then ssh into each server, then pull changes, and update each repository. A pain [...]]]></description>
			<content:encoded><![CDATA[<p>We have a few production servers at work, and we have a central <a href="http://bitbucket.org">bitbucket</a> repository to store our core code. Once we make a change on our testing server (!), we used to have to commit, push changes to bitbucket, and then ssh into each server, then pull changes, and update each repository. A pain in the backside! Enter <a href="http://www.capify.org">Capistrano</a>. A ruby ssh automation tool. In a few simple steps you can create a recipe file that will let you do this all with one command.</p>

<p><span id="more-229"></span></p>

<p>On the machine where you&#8217;d like to kick this all off&#8212;where you&#8217;ll be pushing the changes from&#8212;install Capistrano (requires <a href="http://www.ruby-lang.org/en/">Ruby</a> and <a href="http://rubygems.org/">RubyGems</a> to be installed):</p>

<pre><code>sudo gem install capistrano
</code></pre>

<p>Capistrano is opinionated software; meaning it makes a <a href="http://www.capify.org/index.php/Getting_Started">few assumptions</a> about your server setup which you&#8217;ll need to comply with. Mainly that either you have <a href="http://davidwinter.me.uk/articles/2010/08/22/ssh-and-public-key-authentication/">public key authentication</a> setup to connect to these remote servers, or, you use the same password across all of them.</p>

<p>Now, create a <code>capfile</code>, perhaps in your home directory, and here is an example that you can modify for your own setup:</p>

<pre><code>role :production_servers, "srv1.internet.com", "srv2.internet.com"

task :push_deploy, :roles =&gt; :production_servers do
    system "cd /local/path/to/repos &amp;&amp; hg push"
    run "cd /remote/path/to/repos &amp;&amp; hg pull &amp;&amp; hg update"
end
</code></pre>

<p>With that now saved, you can issue this task with the following command:</p>

<pre><code>cap push_deploy
</code></pre>

<p>This will first of all run a local command to push the changes to bitbucket. After that is complete, it&#8217;ll connect to each of the production servers listed, pull changes and then update the repository. And that&#8217;s it. You don&#8217;t need to do anything else. Piece of <a href="http://fatcakehole.tumblr.com/">cake</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/08/22/using-capistrano-to-deploy-mercurial-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up SSH host shortnames</title>
		<link>http://davidwinter.me.uk/articles/2010/08/22/setting-up-ssh-host-shortnames/</link>
		<comments>http://davidwinter.me.uk/articles/2010/08/22/setting-up-ssh-host-shortnames/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 20:33:08 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=224</guid>
		<description><![CDATA[Here&#8217;s an example setup to create SSH host shortnames. On you local computer, add the following to ~/.ssh/config: Host server1 HostName server1.internet.com User david Host server2 HostName server2.internet.com User david Host * User davidwinter Now with this file saved, you can ssh into server2.internet.com with just the following command: ssh server2 This will save you [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example setup to create SSH host shortnames. On you local computer, add the following to <code>~/.ssh/config</code>:</p>

<pre><code>Host server1
HostName server1.internet.com
User david

Host server2
HostName server2.internet.com
User david

Host *
User davidwinter
</code></pre>

<p>Now with this file saved, you can ssh into <code>server2.internet.com</code> with just the following command:</p>

<pre><code>ssh server2
</code></pre>

<p>This will save you having to type out:</p>

<pre><code>ssh david@server2.internet.com
</code></pre>

<p>And if you have <a href="http://davidwinter.me.uk/articles/2010/08/22/ssh-and-public-key-authentication/">public key authentication</a> setup, it makes the process even smoother. Adding the wildcard host record at the bottom allows you to specify a default username to use for other servers to the ones you&#8217;ve not specified above.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/08/22/setting-up-ssh-host-shortnames/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH and public key authentication</title>
		<link>http://davidwinter.me.uk/articles/2010/08/22/ssh-and-public-key-authentication/</link>
		<comments>http://davidwinter.me.uk/articles/2010/08/22/ssh-and-public-key-authentication/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 20:16:38 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=214</guid>
		<description><![CDATA[Fed up with having to type your password in each time you log into a server over SSH? Me too. Down with passwords, and in with public key authentication! First thing to do, is to check that you have a SSH key setup already on your local computer: cd ~/.ssh ls If you see some [...]]]></description>
			<content:encoded><![CDATA[<p>Fed up with having to type your password in each time you log into a server over SSH? Me too. Down with passwords, and in with public key authentication!</p>

<p><span id="more-214"></span></p>

<p>First thing to do, is to check that you have a SSH key setup already on your local computer:</p>

<pre><code>cd ~/.ssh
ls
</code></pre>

<p>If you see some files in there starting with <code>id_</code>, like <code>id_rsa.pub</code> or <code>id_tsa.pub</code>, you&#8217;re all set. If not, you&#8217;ll need to generate these files:</p>

<pre><code>ssh-keygen -t rsa
</code></pre>

<p>At the prompts you see, you can just hit enter to accept the defaults.</p>

<p>With your public key now in place, we need to transfer that to the server we want to log into.</p>

<pre><code>scp ~/.ssh/id_rsa.pub username@remote.server.com:
</code></pre>

<p>Don&#8217;t forget the colon at the end. This has now transfered the public key over. Now you need to log into the remote server (with your password &#8211; last time, I promise):</p>

<pre><code>ssh username@remote.server.com
</code></pre>

<p>Now, check if there is a <code>.ssh</code> directory on the remote server in your home directory:</p>

<pre><code>cd ~/.ssh/
</code></pre>

<p>If there isn&#8217;t:</p>

<pre><code>mkdir ~/.ssh
</code></pre>

<p>Now move the public key to a file named <code>authorized_keys</code>:</p>

<pre><code>mv ~/id_rsa.pub ~/.ssh/authorized_keys
</code></pre>

<p>Now we need to set the correct permissions to ensure no one can tamper with these files:</p>

<pre><code>chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
</code></pre>

<p>And you&#8217;re done. Now you can logout, and log back in again &#8211; and all going well (if your SSH server has been setup correctly &#8211; by default it usually is), you won&#8217;t be prompted for a password.</p>

<p>If it doesn&#8217;t work, one problem I encountered was where the actual home directory permissions weren&#8217;t set to <code>700</code>. So try:</p>

<pre><code>chmod 700 /home/username
</code></pre>

<p>All done.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/08/22/ssh-and-public-key-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Avoid giving 777 permissions</title>
		<link>http://davidwinter.me.uk/articles/2010/06/28/avoid-giving-777-permissions/</link>
		<comments>http://davidwinter.me.uk/articles/2010/06/28/avoid-giving-777-permissions/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 20:37:42 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=211</guid>
		<description><![CDATA[Just a quick post for me to remember the following workflow of commands: sudo find . -type d -exec chmod 755 {} \; sudo find . -type f -exec chmod 644 {} \; sudo chgrp -R www-data . sudo chmod -R g+w .]]></description>
			<content:encoded><![CDATA[<p>Just a quick post for me to remember the following workflow of commands:</p>

<pre><code>sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chgrp -R www-data .
sudo chmod -R g+w .
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/06/28/avoid-giving-777-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using o2 PAYG mobile broadband</title>
		<link>http://davidwinter.me.uk/articles/2010/06/19/using-o2-payg-mobile-broadband/</link>
		<comments>http://davidwinter.me.uk/articles/2010/06/19/using-o2-payg-mobile-broadband/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 21:34:42 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[o2]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=195</guid>
		<description><![CDATA[Our internet connection via our landline has been dead since Tuesday afternoon, so I&#8217;ve needed an alternative connection in the meantime to give me my twitter fix! I&#8217;d kept an eye on the o2 pay-as-you-go mobile broadband for a while, because it offered the cheapest, noncommittal setup. A one off £20 for the USB dongle, [...]]]></description>
			<content:encoded><![CDATA[<p>Our internet connection via our landline has been dead since Tuesday afternoon, so I&#8217;ve needed an alternative connection in the meantime to give me my twitter fix! </p>

<p>I&#8217;d kept an eye on the o2 pay-as-you-go mobile broadband for a while, because it offered the cheapest, noncommittal setup. A one off £20 for the USB dongle, and then as little as £2 for 500MB for a 24 hour period. </p>

<p>So I plug in the dongle and we get a nice little installer to set everything up; installing drivers and the o2 Mobile Connect application. The annoying thing is that if you install going this route, you can only connect if you have this app open. You can&#8217;t just use system preferences. Also, turns out this &#8216;handy&#8217; installer program then blocks you from getting to the installation files again, and the dongle will refuse to do anything unless Mobile Connect is open (you&#8217;ll get a red light on the dongle when it&#8217;s being evil).</p>

<p>So, what can you do?</p>

<p><span id="more-195"></span></p>

<ol>
<li>Drag <code>Mobile Connect.app</code> to the trash from your Applications directory. </li>
<li>Then head into System > Library > Extensions and delete <code>ZTEUSBCDCACMData.kext</code> and <code>ZTEUSBMassStorageFilter.kext</code></li>
<li>Go into Network in System Preferences and remove the devices starting with ZTEUSB.</li>
<li>Then restart your Mac.</li>
</ol>

<p>Now, let&#8217;s install things a different route giving everyone more flexibility.</p>

<ol>
<li>Plug in the dongle and when the CD Icon appears on the desktop, open it up, but rather than double clicking on the installer, right click on it and select &#8216;Show Package Contents&#8217;. </li>
<li>Now head to Contents then Resources. Now double click on the <code>drv.pkg</code> file and install this only. </li>
<li>Once complete, restart your Mac again. </li>
</ol>

<p>And now to configure the connection:</p>

<ol>
<li>Open System Preferences, and go to the Network pane. </li>
<li>You should have three new items in there. Click on ZTEUSBModem. </li>
<li>Set the telephone number to <code>*99#</code></li>
<li>Username to <code>o2bb</code></li>
<li>Password to <code>password</code> </li>
<li>Click on Advanced. Select Vendor; Generic, Model; GPRS (GSM/3G) and set the APN to <code>m-bb.o2.co.uk</code> </li>
<li>Click on OK and then Apply. </li>
<li>Now you can click &#8216;Connect&#8217; and all should work fine. </li>
</ol>

<p>That is of course, besides the crappy image compression and caching o2 force onto you! Need to find a solution for that next.</p>

<p><strong>Update</strong>: Here&#8217;s a solution for getting around the image compression, and Javascript injection; use a SSH SOCKS proxy. Works a treat.</p>

<ol>
<li>Open up <code>Terminal.app</code></li>
<li>Run <code>ssh -ND 9999 username@yourserver.com</code></li>
<li>Enter your password if/when prompted (you may have key authentication setup)</li>
<li>That&#8217;s the SOCKS proxy setup. Now go to System Preferences and open the network connection.</li>
<li>Click on ZTEUSBModem.</li>
<li>Then Advanced, Proxies</li>
<li>Check the SOCKS Proxy and enter in <code>localhost</code> and <code>9999</code></li>
<li>Click OK and then Apply.</li>
</ol>

<p>All done. You should now get perfect images and no longer have Javascript inserted into all webpages. Both of which weren&#8217;t clearly mentioned when purchasing my dongle.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/06/19/using-o2-payg-mobile-broadband/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Redirecting Apache traffic to a maintenance page</title>
		<link>http://davidwinter.me.uk/articles/2010/05/03/redirecting-apache-traffic-to-a-maintenance-page/</link>
		<comments>http://davidwinter.me.uk/articles/2010/05/03/redirecting-apache-traffic-to-a-maintenance-page/#comments</comments>
		<pubDate>Mon, 03 May 2010 18:54:21 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=173</guid>
		<description><![CDATA[Here&#8217;s a simple solution to redirect users to a maintenance page in Apache. This rewrite rule can stay in your config (&#60;VirtualHost&#62; or .htaccess) all the time; all that you need to enable it is to create the file maintenance.html. The first rewrite condition checks to see if the file exists, and only if it [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple solution to redirect users to a maintenance page in Apache. This rewrite rule can stay in your config (<code>&lt;VirtualHost&gt;</code> or <code>.htaccess</code>) all the time; all that you need to enable it is to create the file <code>maintenance.html</code>.</p>

<p>The first rewrite condition checks to see if the file exists, and only if it does, will it redirect all traffic to it. The second rewrite condition is there to prevent an infinite loop, by  only redirecting traffic to files other than <code>maintenance.html</code>.</p>

<pre><code>RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{REQUEST_FILENAME} !/maintenance.html
RewriteRule ^.*$    /maintenance.html [L]
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/05/03/redirecting-apache-traffic-to-a-maintenance-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Mercurial on CentOS 4</title>
		<link>http://davidwinter.me.uk/articles/2010/04/18/install-mercurial-on-centos-4/</link>
		<comments>http://davidwinter.me.uk/articles/2010/04/18/install-mercurial-on-centos-4/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 18:42:22 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=171</guid>
		<description><![CDATA[We&#8217;ve finally moved to Mercurial at work (well, we didn&#8217;t exactly move from anywhere, but that&#8217;s another story&#8230;). Our production server is running CentOS 4, which comes installed with Python 2.3.4. Mercurial requires 2.4. No Python updates available in the yum repository. What to do? First up, install the latest version of Python to a [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve finally moved to Mercurial at work (well, we didn&#8217;t exactly move from anywhere, but that&#8217;s another story&#8230;). Our production server is running CentOS 4, which comes installed with Python 2.3.4. Mercurial requires 2.4. No Python updates available in the yum repository. What to do?</p>

<p><span id="more-171"></span></p>

<p>First up, install the latest version of Python to a location that won&#8217;t interfere with the system:</p>

<pre><code>wget http://www.python.org/ftp/python/2.6.5/Python-2.6.5.tgz
tar xvfz Python-2.6.5.tgz
cd Python-2.6.5/
./configure --prefix=/opt
make
sudo make install
</code></pre>

<p>Now we just want to test the new Python install:</p>

<pre><code>/opt/bin/python -V
</code></pre>

<p>This should come back with <code>Python 2.6.5</code>.</p>

<p>Now we install Mercurial, but tell it to use this new install of Python, rather than the default:</p>

<pre><code>cd ..
wget http://mercurial.selenic.com/release/mercurial-1.5.1.tar.gz
tar xvfz mercurial-1.5.1.tar.gz
cd mercurial-1.5.1/
sudo make install PYTHON=/opt/bin/python PREFIX=/opt
</code></pre>

<p>Now to test Mercurial has installed successfully:</p>

<pre><code>/opt/bin/hg --version
</code></pre>

<p>This should print out somewhere the version 1.5.1. Now Mercurial is setup, add it to <code>/usr/local/bin</code> so that it&#8217;s available in the path:</p>

<pre><code>sudo ln -s /opt/bin/hg /usr/local/bin/hg
</code></pre>

<p>That wasn&#8217;t too painful was it?</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/04/18/install-mercurial-on-centos-4/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Installing MySQL for PHP with MacPorts</title>
		<link>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/</link>
		<comments>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 13:38:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=162</guid>
		<description><![CDATA[In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a WordPress theme and plugin on my local machine. Here are the few steps I used: sudo port install mysql5-server sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist sudo -u _mysql mysql_install_db5 sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ [...]]]></description>
			<content:encoded><![CDATA[<p>In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a WordPress theme and plugin on my local machine. Here are the few steps I used:</p>

<p><span id="more-162"></span></p>

<pre><code>sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u _mysql mysql_install_db5
sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/run/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/log/mysql5/
</code></pre>

<p>I then add the following aliases to make it easy to start, stop and restart MySQL:</p>

<pre><code>mate ~/.bashrc

alias mysql-start="sudo /opt/local/share/mysql5/mysql/mysql.server start"
alias mysql-restart="sudo /opt/local/share/mysql5/mysql/mysql.server restart"
alias mysql-stop="sudo /opt/local/share/mysql5/mysql/mysql.server stop"

source ~/.profile
</code></pre>

<p>You can then use the following to start MySQL:</p>

<pre><code>mysql-start
</code></pre>

<p><em>Note: I had errors when I first tried starting MySQL. This was because I&#8217;d installed a version of MySQL previously from the official site and it was conflicting. Removing the old version of MySQL did the trick &#8211; instructions <a href="http://tomkeur.net/39/how-to-remove-mysql-completely-mac-os-x-leopard.html">here</a>.</em></p>

<p>When you start the server, it&#8217;s best to set the <code>root</code> user password:</p>

<pre><code>mysqladmin5 -u root password mysupersecretpassword
</code></pre>

<p>Then to setup PHP to work with MySQL:</p>

<pre><code>sudo port install php5-mysql
</code></pre>

<p>Then update the php.ini file:</p>

<pre><code>sudo nano /opt/local/etc/php5/php.ini
</code></pre>

<p>And ensure this line is in there:</p>

<pre><code>mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
</code></pre>

<p>Restart Apache, and then you&#8217;re all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache, PHP and MongoDB on Mac OS X 10.6 Snow Leopard</title>
		<link>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/</link>
		<comments>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 13:12:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=152</guid>
		<description><![CDATA[MongoDB (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database. There&#8217;s a lot of buzz brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the Xcode [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database.</p>

<p>There&#8217;s a lot of <a href="http://delicious.com/search?p=mongodb&amp;chk=&amp;context=popular|&amp;fr=del_icio_us&amp;lc=">buzz</a> brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the <a href="[http://developer.apple.com/tools/xcode/">Xcode</a> developer tools (found on the Snow Leopard install DVD) and <a href="[http://www.macports.org/">MacPorts</a> for this to all work.</p>

<p><span id="more-152"></span></p>

<p>First, let&#8217;s install Apache:</p>

<pre><code>sudo port install apache2
</code></pre>

<p>Nice and simple. Now we can move onto PHP:</p>

<pre><code>sudo port install php5 +apache2 +pear
</code></pre>

<p>To enable PHP for Apache:</p>

<pre><code>cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
</code></pre>

<p>I like to make some alias commands for starting, restarting and stopping Apache:</p>

<pre><code>mate ~/.bashrc

alias apache-start="sudo /opt/local/apache2/bin/apachectl start"
alias apache-restart="sudo /opt/local/apache2/bin/apachectl restart"
alias apache-stop="sudo /opt/local/apache2/bin/apachectl stop"

source ~/.bashrc
</code></pre>

<p>Now we can make a few changes to the Apache config so that we can use our Sites directory:</p>

<pre><code>sudo mate /opt/local/apache2/conf/httpd.conf
</code></pre>

<p>I&#8217;m using Textmate here (<code>mate</code>), but you can use any editor you wish, like <code>nano</code>.</p>

<p>Change the <code>DocumentRoot</code>:</p>

<pre><code>DocumentRoot "/Users/davidwinter/Sites"
</code></pre>

<p>Then update the <code>&lt;Directory&gt;</code> path to the updated <code>DocumentRoot</code> path.  </p>

<pre><code>&lt;Directory "/Users/davidwinter/Sites"&gt;
</code></pre>

<p>We also want to enable <code>index.php</code> as a directory index file:</p>

<pre><code>&lt;IfModule dir_module&gt;
    DirectoryIndex index.html index.php
&lt;/IfModule&gt;
</code></pre>

<p>And then add the PHP mime type:</p>

<pre><code>&lt;IfModule mime_module&gt;
    ...
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
&lt;/IfModule&gt;
</code></pre>

<p>Now we need to setup the <code>php.ini</code> file:</p>

<pre><code>sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini

sudo mate /opt/local/etc/php5/php.ini
</code></pre>

<p>My <a href="[http://php.net/manual/en/timezones.php">timezone</a> is for London:</p>

<pre><code>date.timezone = Europe/London
</code></pre>

<p>Now we can get onto installing MongoDB (this will install the latest stable version as of time of writing &#8211; 1.2.1): </p>

<pre><code>sudo port install mongodb
</code></pre>

<p>And then the PHP MongoDB extension:</p>

<pre><code>sudo pecl install mongo
</code></pre>

<p>You&#8217;ll need to add the extension to the bottom of your <code>php.ini</code> file:</p>

<pre><code>sudo mate /opt/local/etc/php5/php.ini

extension=mongo.so
</code></pre>

<p>Now startup Apache using the <code>alias</code> created earlier:</p>

<pre><code>apache-start
</code></pre>

<p>If you create a file in your Sites directory, called <code>test.php</code>, and add the following to it:</p>

<pre><code>&lt;?php phpinfo(); ?&gt;
</code></pre>

<p>Then visit the page in your browser; <a href="http://localhost/test.php">http://localhost/test.php</a></p>

<p>You can then scroll down the page and you should see a section titled &#8216;mongo&#8217;. This means the extension is working!</p>

<p>Now we need to startup MongoDB:</p>

<pre><code>mkdir -p ~/data/db
mongod --dbpath ~/data/db/
</code></pre>

<p>Almost there, now a simple MongoDB test in PHP:</p>

<pre><code>&lt;?php
// Connect:
$connection = new Mongo();
// Select database:
$db = $connection-&gt;my_db;
// Select collection:
$films = $db-&gt;films;

$frwl = array(
    'title' =&gt; 'From Russia With Love',
    'year' =&gt; 1963,
    'actor' =&gt; 'Sean Connery'
);
// Save array to collection:
$films-&gt;insert($frwl);

$gf = array(
    'title' =&gt; 'Goldfinger',
    'year' =&gt; 1964,
    'actor' =&gt; 'Sean Connery',
    'girl' =&gt; 'Pussy Galore'
);

$films-&gt;insert($gf);

// Count documents in collection:
if ($films-&gt;count()): ?&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Title&lt;/th&gt;
        &lt;th&gt;Year&lt;/th&gt;
        &lt;th&gt;Actor&lt;/th&gt;
        &lt;th&gt;Girl&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php foreach ($films-&gt;find() as $film): ?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $film['title']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['year']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['actor']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['girl']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php endforeach; ?&gt;
&lt;/table&gt;
&lt;?php endif;
?&gt;
</code></pre>

<p>Very exciting stuff. More to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Remove startup scripts on Ubuntu</title>
		<link>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/</link>
		<comments>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 19:55:40 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/</guid>
		<description><![CDATA[sudo update-rc.d -f script_name remove]]></description>
			<content:encoded><![CDATA[<pre><code>sudo update-rc.d -f script_name remove
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/10/20/remove-startup-scripts-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
