<?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>Dave James Miller&#039;s Blog</title>
	<atom:link href="http://blog.davejamesmiller.com/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.davejamesmiller.com</link>
	<description></description>
	<lastBuildDate>Mon, 14 May 2012 17:41:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to set up PHP FastCGI with suEXEC on Debian</title>
		<link>http://blog.davejamesmiller.com/2011/12/how-to-set-up-php-fastcgi-with-suexec-on-debian</link>
		<comments>http://blog.davejamesmiller.com/2011/12/how-to-set-up-php-fastcgi-with-suexec-on-debian#comments</comments>
		<pubDate>Sun, 18 Dec 2011 13:57:53 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2865</guid>
		<description><![CDATA[Most of the time I&#8217;m happy with mod_php. It&#8217;s certainly the most efficient way to run PHP. But there is one major downside &#8211; all scripts are run as the Apache user (www-data). We can get around this by using the FastCGI version of PHP with suEXEC, so it runs as another user. I wouldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time I&#8217;m happy with mod_php. It&#8217;s certainly the most efficient way to run PHP. But there is one major downside &#8211; all scripts are run as the Apache user (<em>www-data</em>). We can get around this by using the FastCGI version of PHP with suEXEC, so it runs as another user.</p>
<p>I wouldn&#8217;t recommend this for all sites &#8211; mod_php is much more efficient &#8211; but in my case there was one site in particular that was very low traffic but where security was very important.</p>
<h2>Directory structure</h2>
<p>This is the directory structure I&#8217;m using, so you can visualise it:</p>
<pre>/etc/
    apache2/
        sites-enabled/
            test.conf         &lt;-- Apache site configuration
/home/
    sites/
        test/
            cgi-bin
                php.fcgi    &lt;-- FastCGI wrapper script
            conf/
                php.ini       &lt;-- PHP configuration
            htdocs/
                phpinfo.php   &lt;-- Test script</pre>
<h2>How to install</h2>
<h3>Install &amp; enable FastCGI and suEXEC</h3>
<pre class="brush: bash; title: ; notranslate">sudo apt-get install php5-cgi libapache2-mod-fastcgi apache2-suexec-custom
sudo a2enmod actions fastcgi suexec
sudo /etc/init.d/apache2 restart</pre>
<h3>Configure suEXEC</h3>
<pre class="brush: bash; title: ; notranslate">sudo vim /etc/apache2/suexec/www-data</pre>
<p>Replace the first line with the parent directory of all websites:</p>
<pre class="brush: plain; title: ; notranslate">/home/sites</pre>
<p>Comment out or delete the second line if you aren&#8217;t using <em>UserDir</em>.</p>
<h3>Create a FastCGI wrapper script</h3>
<p>Note that permissions are important here &#8211; suEXEC will refuse to run if the file is group-writable.</p>
<pre class="brush: bash; title: ; notranslate">
mkdir /home/sites/test/cgi-bin/
chmod 755 /home/sites/test/cgi-bin/
vim /home/sites/test/cgi-bin/php.fcgi
</pre>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh
export PHP_FCGI_CHILDREN=4
export PHP_FCGI_MAX_REQUESTS=200
export PHPRC=&quot;/home/sites/test/conf/php.ini&quot;
exec /usr/bin/php5-cgi
</pre>
<pre class="brush: bash; title: ; notranslate">
chmod 755 /home/sites/test/cgi-bin/php.fcgi
sudo chown -R dave:dave /home/sites/test/cgi-bin/</pre>
<h3>Set the site to use FastCGI</h3>
<pre class="brush: bash; title: ; notranslate">vim /etc/apache2/sites-enabled/test.conf</pre>
<pre class="brush: plain; title: ; notranslate">

    ...

    # Use FastCGI version of PHP
    php_admin_flag engine off
    ScriptAlias /cgi-bin /home/sites/test/cgi-bin
    Action application/x-httpd-php /cgi-bin/php.fcgi
    SuexecUserGroup dave dave
</pre>
<h3>Restart Apache</h3>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/apache2 restart</pre>
<h3>Protect the web files from other users</h3>
<p>Now you can set it so only the suEXEC user can read the PHP files.</p>
<p>Note: The directories and non-PHP files must still be readable by Apache.</p>
<pre class="brush: bash; title: ; notranslate">sudo chown -R dave:dave /home/sites/test/htdocs/
find /home/sites/test/htdocs/ -name '*.php' -exec sudo chmod o-rwx '{}' \;
find /home/sites/test/htdocs/ -name '*.inc' -exec sudo chmod o-rwx '{}' \;
</pre>
<h2>Notes</h2>
<p>1. Make sure the <code>php.fcgi</code> script is saved in Unix line-ending format not Windows &#8211; otherwise, again, FastCGI will hang for 30 seconds then time out. Test the script by running it at the command line.</p>
<p>2. If you make any changes to the wrapper script (<code>php.fcgi</code>), you must kill the existing instances before you will see the changes. (I did this by restarting Apache, but I suspect there is a more graceful way!)</p>
<p>3. You do not have to make the PHP scripts executable, or add the <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29">shebang</a> to the top &#8211; it is the wrapper script that is executed, not the PHP scripts.</p>
<p>4. If it doesn&#8217;t load correctly check the suEXEC log:</p>
<pre class="brush: bash; title: ; notranslate">sudo tail /var/log/apache2/suexec.log</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/12/how-to-set-up-php-fastcgi-with-suexec-on-debian/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Rails 3.1 + Ruby 1.9 on a cPanel 11.30 server</title>
		<link>http://blog.davejamesmiller.com/2011/12/installing-rails-3-1-ruby-1-9-on-a-cpanel-11-30-server</link>
		<comments>http://blog.davejamesmiller.com/2011/12/installing-rails-3-1-ruby-1-9-on-a-cpanel-11-30-server#comments</comments>
		<pubDate>Sun, 04 Dec 2011 12:50:13 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2850</guid>
		<description><![CDATA[cPanel 11.30 doesn&#8217;t support Ruby 1.9 or Ruby on Rails 3.0/3.1, only Ruby 1.8 and Rails 2.3. They are working on supporting Rails 3 in cPanel 11.34, but that could be 12 months away still, so for now we have to install them manually. To do this you&#8217;ll need root access to the server &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>cPanel 11.30 doesn&#8217;t support Ruby 1.9 or Ruby on Rails 3.0/3.1, only Ruby 1.8 and Rails 2.3. They are working on supporting Rails 3 in cPanel 11.34, but that could be <a href="http://forums.cpanel.net/f145/mod_rails-passenger-instead-mongrel-rails-3-support-case-44197-a-152577-p3.html#post990281">12 months away</a> still, so for now we have to install them manually.</p>
<p>To do this you&#8217;ll need <strong>root</strong> access to the server &#8211; reseller or normal user access will not do. You also need to be comfortable using the command line and editing configuration files.</p>
<h2>Warnings</h2>
<ul>
<li>You won&#8217;t be able to use the Ruby on Rails section in cPanel &#8211; everything will have to be done using the command line instead.</li>
<li>If you mess up the Apache configuration you could break your web server &#8211; so make sure you know what you&#8217;re doing!</li>
<li>This is what worked for me &#8211; there may be better solutions I&#8217;m not aware of.</li>
</ul>
<h2>What we&#8217;re going to install</h2>
<p><a href="http://beginrescueend.com/">Ruby Version Manager</a> makes it easy to install multiple versions of Ruby into your home directory. We&#8217;ll use that to install Ruby 1.9 separately from the cPanel-provided version 1.8.</p>
<p><a href="http://www.modrails.com/">Phusion Passenger</a> (a.k.a. mod_rails) is an Apache module that lets you run multiple Rails apps under a single Apache instance &#8211; no need for backend servers like Mongrel any more.</p>
<h2>Install RVM, Ruby &amp; Phusion Passenger</h2>
<h3>1. Create a new user</h3>
<p>First you need to decide which user to install it under. It&#8217;s probably best not to do it as root (I don&#8217;t even know if it would let you), so I created a new user especially for this. That way I know I won&#8217;t accidentally break it.</p>
<p>To do that, go to WebHost Manager (WHM) &gt; Account Functions &gt; Create a New Account. I used the username <em>ruby</em> and the domain name <em>ruby.myservername.com</em> (using my actual server name of course).</p>
<h3>2. Install RVM</h3>
<p>Now log in as that user via SSH and install RVM:</p>
<pre class="brush: bash; title: ; notranslate">bash &lt; &lt;(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)</pre>
<p>If it tells you to install some dependancies, log in as root and do that. In my case it told me to run this:</p>
<pre class="brush: bash; title: ; notranslate">yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel</pre>
<p>Now (back as the <em>ruby</em> user) load RVM:</p>
<pre class="brush: bash; title: ; notranslate">source &quot;$HOME/.rvm/scripts/rvm&quot;</pre>
<p>You should also configure Bash to load RVM automatically at login:</p>
<pre class="brush: bash; title: ; notranslate">echo '[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; source &quot;$HOME/.rvm/scripts/rvm&quot;' &gt;&gt; ~/.bashrc</pre>
<h3>3. Install Ruby</h3>
<p>Now it&#8217;s time to install Ruby. I installed version 1.9.2 because I couldn&#8217;t get <em>ruby-debug </em>to work with the latest version, 1.9.3.</p>
<pre class="brush: bash; title: ; notranslate">rvm install 1.9.2
rvm --default 1.9.2</pre>
<h3>4. Install Bundler</h3>
<p>You&#8217;ll also need Bundler installed, so let&#8217;s install it now:</p>
<pre class="brush: bash; title: ; notranslate">gem install bundler</pre>
<p>This is the only Rails gem you need to install under this user account &#8211; the rest can be installed locally for each app.</p>
<h3>5. Install Phusion Passenger</h3>
<pre class="brush: bash; title: ; notranslate">gem install passenger
passenger-install-apache2-module</pre>
<p>Passenger will give you some code to add to your Apache config &#8211; make a note of it.</p>
<p>Now log in as root again and add that code to <tt>/usr/local/apache/conf/includes/pre_main_global.conf</tt>. e.g. My code was:</p>
<pre class="brush: plain; title: ; notranslate">LoadModule passenger_module /home/ruby/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /home/ruby/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11
PassengerRuby /home/ruby/.rvm/wrappers/ruby-1.9.2-p290/ruby</pre>
<p>Now tell cPanel to rebuild the main Apache config file:</p>
<pre class="brush: bash; title: ; notranslate">cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak-modrails
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart</pre>
<h3>6. Make sure all the RVM files are world-readable</h3>
<p>As the <em>ruby</em> user again:</p>
<pre class="brush: bash; title: ; notranslate">chmod ugo+x ~
chmod ugo+rX -R ~/.rvm</pre>
<p>That&#8217;s it &#8211; you&#8217;re ready to run Rails! The next section shows how to set up each app.</p>
<h2>Using Ruby on Rails</h2>
<h3>Installing RVM, Ruby and Ruby on Rails</h3>
<p>You will need to install RVM, Ruby and Ruby on Rails for each user that will be creating Rails apps. The commands are the same as we used above:</p>
<pre class="brush: bash; title: ; notranslate">
bash &lt; &lt;(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
source &quot;$HOME/.rvm/scripts/rvm&quot;
echo '[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; source &quot;$HOME/.rvm/scripts/rvm&quot;' &gt;&gt; ~/.bashrc
rvm install 1.9.2
rvm --default 1.9.2
gem install rails
</pre>
<h3>Creating a new Rails app</h3>
<p>Nothing special here:</p>
<pre class="brush: bash; title: ; notranslate">rails new hello_world</pre>
<p>For the following examples I&#8217;ll assume your app is installed in <tt>~/hello_world</tt>.</p>
<h3>Installing Gems to the vendor/ directory</h3>
<p>If you run <tt>bundle</tt>, that will install the Gems to your RVM directory, which won&#8217;t be picked up by Passenger. There&#8217;s <a href="http://beginrescueend.com/integration/passenger/">instructions on the RVM website</a> how to make that work, but I wasn&#8217;t able to make it work.</p>
<p>A much simpler solution is to install the Gems to the <tt>vendor/</tt> directory, where they are picked up automatically:</p>
<pre class="brush: bash; title: ; notranslate">bundle install --deployment</pre>
<p>Or if you are using the site for development not production:</p>
<pre class="brush: bash; title: ; notranslate">bundle install --path vendor/bundle</pre>
<p>Bundler will remember the path after that, so you can just run <tt>bundle install</tt> (or even just <tt>bundle</tt>) as normal.</p>
<h3>Installing Rails to a subdirectory</h3>
<p>e.g. <strong>http://example.com/hello/</strong></p>
<p>The simplest way to make the new Rails app accessible is to make a symlink from a subdirectory to the Rails public/ directory:</p>
<pre class="brush: bash; title: ; notranslate">ln -s ~/hello_world/public ~/public_html/hello</pre>
<p>Passenger will automatically detect the symlink and load Rails for you.</p>
<h3>Installing Rails to a subdomain / add-on domain</h3>
<p>e.g. <strong>http://hello.example.com/</strong></p>
<p>The second way is to create a subdomain or add-on domain for the app. You can do this in cPanel &#8211; just set the document root to <tt>hello_world/public</tt>. Again, Passenger will do the rest.</p>
<h3>Installing Rails to the site root</h3>
<p>e.g. <strong>http://example.com/</strong></p>
<p>The Phusion Passenger documentation tells you to set the Apache DocumentRoot to the Rails <tt>public/</tt> directory&#8230; But cPanel doesn&#8217;t let you do that!</p>
<p>Instead we have to remove the existing <tt>~/public_html/</tt> folder and symlink it to the Rails <tt>public/</tt> directory instead:</p>
<pre class="brush: bash; title: ; notranslate">mv public_html public_html-backup
ln -s hello_world/public public_html</pre>
<p>But then Passenger fails to find the Rails root, so we have to set it manually in the <tt>hello_world/public/.htaccess</tt> file:</p>
<pre class="brush: plain; title: ; notranslate">PassengerAppRoot /home/myusername/hello_world</pre>
<h2>Other tips</h2>
<h3>Using the <em>production</em> environment automatically</h3>
<p>You will probably want to use the <em>production</em> environment instead of the <em>development</em> one. To make that the default for all commands, simply set the RAILS_ENV environment variable:</p>
<pre class="brush: bash; title: ; notranslate">export RAILS_ENV=production</pre>
<p>To set it automatically when you log in:</p>
<pre class="brush: bash; title: ; notranslate">echo &quot;export RAILS_ENV=production&quot; &gt;&gt; ~/.bashrc</pre>
<h3>Precompiling the assets</h3>
<p>Since this is a production site you will need to precompile the assets:</p>
<pre class="brush: bash; title: ; notranslate">rake assets:precompile</pre>
<h3>Restarting the app</h3>
<p>The final thing I had to do after making all those changes is restart the app:</p>
<pre class="brush: plain; title: ; notranslate">touch tmp/restart.txt</pre>
<p>This tells Passenger to restart the app next time you visit it, and saves you having to restart Apache every time.</p>
<h2>Sources</h2>
<ul>
<li><a href="http://beginrescueend.com/rvm/install/">RVM documentation</a></li>
<li><a href="http://www.cpanel.net/blog/cpanel-whm-admins/2011/07/installing-mod-rails-and-rails-309-on-a-cpanel-machine.html">cPanel Admin Blog</a></li>
<li><a href="http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerAppRoot">Phusion Passenger users guide</a></li>
<li>And many others I&#8217;ve forgotten about!</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/12/installing-rails-3-1-ruby-1-9-on-a-cpanel-11-30-server/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Automatically mounting a Samba share at boot on Debian</title>
		<link>http://blog.davejamesmiller.com/2011/11/automatically-mounting-a-samba-share-at-boot-on-debian</link>
		<comments>http://blog.davejamesmiller.com/2011/11/automatically-mounting-a-samba-share-at-boot-on-debian#comments</comments>
		<pubDate>Mon, 14 Nov 2011 20:37:45 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2845</guid>
		<description><![CDATA[First you&#8217;ll need somewhere safe to put the username &#38; password. We&#8217;ll store them in /etc/sambapasswords, and make that only readable by root. Now create a file for the server itself: Enter the credentials in this format: (Note: The maximum password length is 16 characters. I spent ages trying to debug it when I was [...]]]></description>
			<content:encoded><![CDATA[<p>First you&#8217;ll need somewhere safe to put the username &amp; password. We&#8217;ll store them in <tt>/etc/sambapasswords</tt>, and make that only readable by <tt>root</tt>.</p>
<pre class="brush: bash; title: ; notranslate">sudo mkdir /etc/sambapasswords
sudo chmod 700 /etc/sambapasswords</pre>
<p>Now create a file for the server itself:</p>
<pre class="brush: bash; title: ; notranslate">sudo vim /etc/sambapasswords/myserver</pre>
<p>Enter the credentials in this format:</p>
<pre class="brush: plain; title: ; notranslate">username=windowsusername
password=mypassword</pre>
<p>(Note: The maximum password length is 16 characters. I spent ages trying to debug it when I was using a randomly generated 20 character password!)</p>
<p>And make sure the file itself is secure, just in case:</p>
<pre class="brush: bash; title: ; notranslate">sudo chmod 600 /etc/sambapasswords/myserver</pre>
<p>Create the directory where it should be mounted:</p>
<pre class="brush: bash; title: ; notranslate">sudo mkdir /mnt/myserverfiles</pre>
<p>Now edit <tt>/etc/fstab</tt>:</p>
<pre class="brush: bash; title: ; notranslate">sudo vim /etc/fstab</pre>
<p>And add the following line:</p>
<pre class="brush: plain; title: ; notranslate">//myserver/path/to/files /mnt/myserverfiles smbfs credentials=/etc/sambapasswords/myserver 0 0</pre>
<p>Finally tell it to mount the newly added share now (so you don&#8217;t have to reboot to test it / start using it):</p>
<pre class="brush: bash; title: ; notranslate">sudo mount -a</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/11/automatically-mounting-a-samba-share-at-boot-on-debian/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating a self-signed SSL certificate for Apache</title>
		<link>http://blog.davejamesmiller.com/2011/11/generating-a-self-signed-ssl-certificate-for-apache</link>
		<comments>http://blog.davejamesmiller.com/2011/11/generating-a-self-signed-ssl-certificate-for-apache#comments</comments>
		<pubDate>Sat, 12 Nov 2011 21:34:42 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2838</guid>
		<description><![CDATA[1. Generate a private key (If you&#8217;re concerned about security you should also look at the -des3 and -rand options &#8211; see here &#8211; otherwise I&#8217;ve found this works fine for testing.) 2. Generate a certificate signing request Answer the questions when prompted &#8211; e.g. Country Name: UK State or Province Name: England Locality Name: blank Organization [...]]]></description>
			<content:encoded><![CDATA[<h2>1. Generate a private key</h2>
<pre class="brush: bash; title: ; notranslate">openssl genrsa -out server.key 1024</pre>
<p>(If you&#8217;re concerned about security you should also look at the <tt>-des3</tt> and <tt>-rand</tt> options &#8211; see <a href="http://slacksite.com/apache/certificate.php">here</a> &#8211; otherwise I&#8217;ve found this works fine for testing.)</p>
<h2>2. Generate a certificate signing request</h2>
<pre class="brush: bash; title: ; notranslate">openssl req -new -key server.key -out server.csr</pre>
<p>Answer the questions when prompted &#8211; e.g.</p>
<ul>
<li><strong>Country Name:</strong> UK</li>
<li><strong>State or Province Name:</strong> England</li>
<li><strong>Locality Name: </strong><em>blank</em></li>
<li><strong>Organization Name:</strong> DaveJamesMiller.com</li>
<li><strong>Organizational Unit Name: </strong><em>blank</em></li>
<li><strong>Common Name: </strong>secure.davejamesmiller.com <em>(Enter the domain name)</em></li>
<li><strong>Email Address: </strong>me@example.com</li>
</ul>
<p>The only one that really matters for a self-signed certificate is the Common Name field, which should be set to the domain name.</p>
<h2>3. Self-sign the certificate</h2>
<pre class="brush: bash; title: ; notranslate">openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt</pre>
<p>This will be valid for 365 days, but you could increase that if you want to.</p>
<h2>4. Configure Apache</h2>
<p>This will depend on how your distro is set up, but it will look something like this:</p>
<pre class="brush: plain; title: ; notranslate">&lt;VirtualHost *:443&gt;
ServerName secure.davejamesmiller.com
DocumentRoot /var/www/secure/
SSLEngine on
SSLCertificateFile /path/to/server.crt
SSLCertificateKeyFile /path/to/server.key
&lt;/VirtualHost&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/11/generating-a-self-signed-ssl-certificate-for-apache/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Write tweets in your own words instead of retweeting</title>
		<link>http://blog.davejamesmiller.com/2011/11/write-tweets-in-your-own-words-instead-of-retweeting</link>
		<comments>http://blog.davejamesmiller.com/2011/11/write-tweets-in-your-own-words-instead-of-retweeting#comments</comments>
		<pubDate>Sun, 06 Nov 2011 18:57:01 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2812</guid>
		<description><![CDATA[Sometimes retweeting is good &#8211; you can quickly share something you&#8217;re interested in with your followers. If you want to say exactly the same thing as the original author, retweeting makes it very easy. But sometimes wouldn&#8217;t it be better to rewrite the tweet in your own words &#8211; to tell your followers why you [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes retweeting is good &#8211; you can quickly share something you&#8217;re interested in with your followers.</p>
<p>If you want to say exactly the same thing as the original author, retweeting makes it very easy.</p>
<p>But sometimes wouldn&#8217;t it be better to rewrite the tweet in your own words &#8211; to tell your followers <em>why</em> you think something is worth reading, or to add your own opinion?</p>
<p>For example, I recently <a href="https://twitter.com/#!/holman/status/132565101764018176">retweeted</a>:</p>
<blockquote><p><strong>@<a href="https://twitter.com/#!/holman">holman</a>:</strong> Updated my &#8220;How GitHub Uses GitHub to Build GitHub&#8221; slides for <a title="#rubymidwest" href="https://twitter.com/#%21/search?q=%23rubymidwest" rel="nofollow"><s>#</s>rubymidwest</a>. <a title="http://zachholman.com/talk/how-github-uses-github-to-build-github/" href="http://t.co/dsR3HDjS" rel="nofollow" target="_blank" data-display-url="zachholman.com/talk/how-githu…" data-ultimate-url="http://zachholman.com/talk/how-github-uses-github-to-build-github/" data-expanded-url="http://zachholman.com/talk/how-github-uses-github-to-build-github">http://zachholman.com/talk/how-github-uses-github-to-build-github</a> Videos will be coming soon.</p></blockquote>
<p>Which gives you an idea of what it&#8217;s about, and Zach&#8217;s reason for posting it, but doesn&#8217;t tell you why <em>I</em> thought it was worth sharing.</p>
<p>What I should have said instead is:</p>
<blockquote><p>How GitHub uses GitHub to collaborate asynchronously and avoid meetings &amp; meta-work <a href="http://zachholman.com/talk/how-github-uses-github-to-build-github">http://zachholman.com/talk/how-github-uses-github-to-build-github</a> by @<a href="https://twitter.com/#!/holman">holman</a></p></blockquote>
<p>Note that I still credit the original author &#8211; in this case with &#8220;by @holman&#8221; since he wrote the post too, but if he didn&#8217;t I&#8217;d write &#8220;via @holman&#8221; instead.</p>
<p>In the future I&#8217;m going to make more of an effort to do that.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/11/write-tweets-in-your-own-words-instead-of-retweeting/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting PHP to Microsoft SQL Server on Debian/Ubuntu</title>
		<link>http://blog.davejamesmiller.com/2011/04/connecting-php-to-sql-server-on-debian-ubuntu</link>
		<comments>http://blog.davejamesmiller.com/2011/04/connecting-php-to-sql-server-on-debian-ubuntu#comments</comments>
		<pubDate>Fri, 22 Apr 2011 23:16:27 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2788</guid>
		<description><![CDATA[Here is how to get PHP 5.2 on Linux (specifically Debian/Ubuntu) talking to a Microsoft SQL Server database: Install FreeTDS and the PHP MS SQL extension Note: That is correct, the MS SQL extension is in the &#8220;php5-sybase&#8221; package. Restart Apache Test FreeTDS If it connects, it&#8217;s working. Note: If you try to SELECT an [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how to get PHP 5.2 on Linux (specifically Debian/Ubuntu) talking to a Microsoft SQL Server database:</p>
<h3>Install FreeTDS and the PHP MS SQL extension</h3>
<pre class="brush: bash; title: ; notranslate">sudo apt-get install freetds-common freetds-bin unixodbc php5-sybase</pre>
<p><em>Note: That is correct, the MS SQL extension is in the &#8220;php5-sybase&#8221; package.</em></p>
<h3>Restart Apache</h3>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/apache2 restart</pre>
<h3>Test FreeTDS</h3>
<pre class="brush: bash; title: ; notranslate">tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename</pre>
<p>If it connects, it&#8217;s working.</p>
<p><em>Note: If you try to SELECT an NTEXT or NVARCHAR column you may get an error saying &#8220;Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier&#8221;. That is expected and will be fixed in the next step.</em></p>
<h3>Configure FreeTDS</h3>
<pre class="brush: bash; title: ; notranslate">sudo vim /etc/freetds/freetds.conf</pre>
<p>Add this at the end of the file:</p>
<pre class="brush: plain; title: ; notranslate">[yourserver]
host = your.server.name
port = 1433
tds version = 8.0</pre>
<h3>Test FreeTDS using server name</h3>
<pre class="brush: bash; title: ; notranslate">tsql -S yourserver -U yourusername -P yourpassword -D yourdatabasename</pre>
<p><em>If you try to select something, you shouldn&#8217;t get the Unicode error now &#8211; because you specified &#8220;tds version = 8.0&#8243;.</em></p>
<h3>Test in PHP</h3>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$link = mssql_connect('yourserver', 'yourusername', 'yourpassword');

if (!$link) {
   die('Unable to connect!');
}

if (!mssql_select_db('yourdatabasename', $link)) {
   die('Unable to select database!');
}

$result = mssql_query('SELECT * FROM yourtable');

while ($row = mssql_fetch_array($result)) {
   var_dump($row);
}

mssql_free_result($result);
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/04/connecting-php-to-sql-server-on-debian-ubuntu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install PHP 5.2 FastCGI on Debian 6.0 Squeeze</title>
		<link>http://blog.davejamesmiller.com/2011/03/how-to-install-php-5-2-fastcgi-on-debian-6-0-squeeze</link>
		<comments>http://blog.davejamesmiller.com/2011/03/how-to-install-php-5-2-fastcgi-on-debian-6-0-squeeze#comments</comments>
		<pubDate>Sun, 13 Mar 2011 23:00:44 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.davejamesmiller.com/?p=2771</guid>
		<description><![CDATA[Debian Squeeze comes with PHP 5.3. This is good, because PHP 5.2 is no longer maintained, but causes problems for old applications that can&#8217;t support it (e.g. ViArt 3, because it uses Zend Encoder). Rather than permanently downgrade PHP for the whole server, I opted to install PHP 5.2 alongside it using FastCGI. It took [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.debian.org/">Debian</a> Squeeze comes with PHP 5.3. This is good, because PHP 5.2 is no longer maintained, but causes problems for old applications that can&#8217;t support it (e.g. <a href="http://www.viart.com/">ViArt</a> 3, because it uses Zend Encoder).</p>
<p>Rather than permanently downgrade PHP for the whole server, I opted to install PHP 5.2 alongside it using FastCGI. It took some trial-and-error to get it to compile with all the features I need, but here is how I did it:</p>
<h2>Directory structure</h2>
<p>This is the directory structure (at the end), so you can visualise it:</p>
<pre>/etc/
    apache2/
        sites-enabled/
            test.conf         &lt;-- Apache site configuration
/opt/
    php52/
        bin/
            php-cgi           &lt;-- PHP CGI binary
            ...
        ...
/home/
    sites/
        test/
            cgi-bin
                php52.fcgi    &lt;-- FastCGI wrapper script
            conf/
                php.ini       &lt;-- PHP configuration
            htdocs/
                phpinfo.php   &lt;-- Test script</pre>
<h2>How to install</h2>
<h3>Install &amp; enable FastCGI</h3>
<pre class="brush: bash; title: ; notranslate">sudo apt-get install libapache2-mod-fastcgi
sudo a2enmod actions fastcgi
sudo /etc/init.d/apache2 restart</pre>
<h3>Download PHP</h3>
<pre class="brush: bash; title: ; notranslate"> mkdir ~/php5-build
cd ~/php5-build
wget http://uk3.php.net/get/php-5.2.17.tar.bz2/from/this/mirror -O php-5.2.17.tar.bz2
tar jxf php-5.2.17.tar.bz2
cd php-5.2.17/</pre>
<h3>Download dependancies</h3>
<pre class="brush: bash; title: ; notranslate">sudo apt-get build-dep php5
sudo apt-get install libfcgi-dev libmhash-dev</pre>
<h3>Compile PHP</h3>
<pre class="brush: bash; title: ; notranslate">./configure \
    --prefix=/opt/php52 \
    --enable-force-cgi-redirect \
    --enable-fastcgi \
    --with-regex=php \
    --enable-calendar \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-sysvmsg \
    --enable-bcmath \
    --with-bz2 \
    --enable-ctype \
    --with-iconv \
    --enable-exif \
    --enable-ftp \
    --with-gettext \
    --enable-mbstring \
    --with-pcre-regex \
    --enable-shmop \
    --enable-sockets \
    --enable-wddx \
    --with-libxml-dir=/usr \
    --with-zlib \
    --with-openssl=/usr \
    --enable-soap \
    --enable-zip \
    --with-mhash=yes \
    --with-gd \
    --with-mysql \
    --with-mysqli \
    --with-pdo-mysql \
    --with-pear \
    --with-jpeg-dir=/usr/lib \
    --enable-gd-native-ttf \
    --with-ttf \
    --with-freetype-dir=/usr
make
sudo make install
sudo chmod o+rX -R /opt/php52/</pre>
<h3>Create a FastCGI wrapper script</h3>
<pre class="brush: bash; title: ; notranslate">mkdir /home/sites/test/cgi-bin/
chmod o+rX /home/sites/test/cgi-bin/
vim /home/sites/test/cgi-bin/php52.fcgi</pre>
<p>&nbsp;</p>
<pre class="brush: bash; title: ; notranslate">#!/bin/sh
export PHP_FCGI_CHILDREN=4
export PHP_FCGI_MAX_REQUESTS=200
export PHPRC=&quot;/home/sites/test/conf/php.ini&quot;
exec /opt/php52/bin/php-cgi</pre>
<p>&nbsp;</p>
<pre class="brush: bash; title: ; notranslate">chmod a+rx /home/sites/test/cgi-bin/php52.fcgi</pre>
<h3>Set the site to use FastCGI</h3>
<pre class="brush: bash; title: ; notranslate">vim /etc/apache2/sites-enabled/test.conf</pre>
<p>&nbsp;</p>
<pre class="brush: plain; title: ; notranslate">&lt;VirtualHost *&gt;

    ...

    # Use FastCGI version of PHP
    php_admin_flag engine off
    ScriptAlias /cgi-bin /home/sites/test/cgi-bin
    Action application/x-httpd-php /cgi-bin/php52.fcgi

&lt;/VirtualHost&gt;</pre>
<h3>Restart Apache</h3>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/apache2 restart</pre>
<h2>Notes</h2>
<p>It took me many hours to get this right. Here are some of the things I learned:</p>
<p>1. If you don&#8217;t have <code>libfcgi-dev</code> installed when you compile PHP, it will compile fine, but FastCGI will time out when you try to use it.</p>
<p>2. Make sure the <code>php52.fcgi</code> script is saved in Unix line-ending format not Windows &#8211; otherwise, again, FastCGI will hang for 30 seconds then time out. Test the script by running it at the command line.</p>
<p>3. If you miss out the <code>--with-jpeg-dir=/usr/lib</code> switch the first time, you must run <code>make clean</code> before PHP will compile a second time with JPEG support.</p>
<p>4. If you make any changes to the wrapper script (<code>php52.fcgi</code>), you must kill the existing instances before you will see the changes. (I did this by restarting Apache, but I suspect there is a more graceful way!)</p>
<p>5. You do not have to make the PHP scripts executable, or add the <a href="http://en.wikipedia.org/wiki/Shebang_%28Unix%29">shebang</a> to the top &#8211; it is the wrapper script that is executed, not the PHP scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/03/how-to-install-php-5-2-fastcgi-on-debian-6-0-squeeze/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Recommended web development software</title>
		<link>http://blog.davejamesmiller.com/2011/02/recommended-web-development-software</link>
		<comments>http://blog.davejamesmiller.com/2011/02/recommended-web-development-software#comments</comments>
		<pubDate>Sun, 06 Feb 2011 00:39:30 +0000</pubDate>
		<dc:creator>Dave James Miller</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://webdev.davejamesmiller.com/?p=10</guid>
		<description><![CDATA[These are the software I use and recommend for web development: Beyond Compare &#8211; Synchronise local and remote files Color Cop &#8211; Colour picker gVim (with various customisations) &#8211; Powerful text editor JRuler &#8211; Measure on-screen distances PuTTY &#8211; SSH client WinSCP &#8211; FTP/SFTP/SCP client Firefox plugins Clear Cache Button &#8211; Quickly clear the cache [...]]]></description>
			<content:encoded><![CDATA[<p>These are the software I use and recommend for web development:</p>
<ul>
<li><a href="http://www.scootersoftware.com/">Beyond Compare</a> &#8211; Synchronise local and remote files</li>
<li><a href="http://colorcop.net/">Color Cop</a> &#8211; Colour picker</li>
<li><a href="http://www.vim.org/">gVim</a> (with <a href="http://hg.davejamesmiller.com/linux-config/file/tip">various customisations</a>) &#8211; Powerful text editor</li>
<li><a href="http://www.spadixbd.com/freetools/jruler.htm">JRuler</a> &#8211; Measure on-screen distances</li>
<li><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> &#8211; SSH client</li>
<li><a href="http://winscp.net/">WinSCP</a> &#8211; FTP/SFTP/SCP client</li>
</ul>
<h2>Firefox plugins</h2>
<ul>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/clear-cache-button/">Clear Cache Button</a> &#8211; Quickly clear the cache</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/clear-dns-cache/">Clear DNS Cache</a> &#8211; Quickly clear the DNS cache</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/firebug/">Firebug</a> &#8211; Very powerful tool for development and debugging</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/firecookie/">Firecookie</a> &#8211; View site cookies in Firebug</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/firephp/">FirePHP</a> &#8211; Display server-side messages from PHP in Firebug</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/html-validator/">HTML Validator</a> &#8211; Validate (X)HTML</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/open-with/">Open With</a> &#8211; Quickly open a page in other web browsers</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/server-switcher/">Server Switcher</a> &#8211; Quickly switch between development &amp; production server</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/wappalyzer/">Wappalyzer</a> &#8211; See what software powers every website</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/web-developer/">Web Developer</a> &#8211; More tools for web development</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/worldip-flag-and-datacenter-pi/">WorldIP</a> &#8211; See the IP/hostname of every website</li>
<li><a href="https://addons.mozilla.org/en-US/firefox/addon/yslow/">YSlow</a> &#8211; Test the speed of your websites</li>
</ul>
<h2>Browsers for testing</h2>
<ul>
<li><a href="http://www.mozilla.com/firefox/">Firefox</a></li>
<li><a href="http://www.google.com/chrome">Google Chrome</a></li>
<li><a href="http://www.my-debugbar.com/wiki/IETester/HomePage">IETester</a></li>
<li><a href="http://www.microsoft.com/windows/internet-explorer/">Internet Explorer</a></li>
<li><a href="http://www.opera.com/">Opera</a></li>
<li><a href="http://www.apple.com/safari/">Safari</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.davejamesmiller.com/2011/02/recommended-web-development-software/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

