<?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>Leonard Teo &#187; Web Development</title>
	<atom:link href="http://www.leonardteo.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leonardteo.com</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 02:47:59 +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>2012 Resolution: Retire Internet Explorer 8</title>
		<link>http://www.leonardteo.com/2011/12/2012-resolution-retire-internet-explorer-8/</link>
		<comments>http://www.leonardteo.com/2011/12/2012-resolution-retire-internet-explorer-8/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 14:45:51 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Rambling]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=670</guid>
		<description><![CDATA[One of the biggest frustrations that I have as a professional web developer is Internet Explorer &#8211; more specifically IE8, which is currently refusing to die because it is &#8220;good enough but not quite&#8221;. Here we are, trying to move forward with new technology on HTML5 standards that work across most modern browsers, except things [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest frustrations that I have as a professional web developer is Internet Explorer &#8211; more specifically IE8, which is currently refusing to die because it is &#8220;good enough but not quite&#8221;. Here we are, trying to move forward with new technology on HTML5 standards that work across most modern browsers, except things don&#8217;t look or work quite right in IE8. Corporations still give out computers to employees with IE8 pre-installed. Enough is enough. Let&#8217;s make 2012 the year that we, as a body of web professionals, begin to retire IE8.</p>
<h2>How?</h2>
<p>From now on, every site that I deliver for clients will have, by default, an <a href="http://www.ie8nomore.com">IE8nomore</a> header (or variant), which will only show up when a user with IE8 or less browses to the site. If a client specifically wants me to support IE8, they will need to pay extra for it. It&#8217;s that simple. Clients need to be educated that IE8 is just bad software. If they have the chance to tell you that a site you created doesn&#8217;t work in IE8, you&#8217;re too late. You need to put the header in <em>by default</em> so that when they, or their colleagues browse to your site, they immediately see that their browser is outdated. It&#8217;s psychological. <em>They</em> need to upgrade. <em>You</em> don&#8217;t need to lower your standards.</p>
<p><a href="http://www.leonardteo.com/wp-content/uploads/2011/12/ie8nomore.jpg"><img class="aligncenter size-full wp-image-671 colorbox-670" title="ie8nomore" src="http://www.leonardteo.com/wp-content/uploads/2011/12/ie8nomore.jpg" alt="" width="604" height="82" /></a></p>
<p>If you&#8217;re a professional web developer, make it your resolution. Let&#8217;s rid the world of standard-less browsers. Let&#8217;s nail IE8 and please be done with it.</p>
<h2>Links</h2>
<p><a href="http://ie8nomore.com/">IE8nomore header</a><br />
<a href="http://www.ie6nomore.com/">IE6nomore header</a> (the original)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/12/2012-resolution-retire-internet-explorer-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails, Bootstrap and will_paginate</title>
		<link>http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/</link>
		<comments>http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 14:13:55 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=642</guid>
		<description><![CDATA[If you&#8217;re using Ruby on Rails, you&#8217;ll likely use the will_paginate plugin. If you use Twitter&#8217;s Bootstrap CSS framework as well, you&#8217;ll notice that the pagination is all messed up. This gist fixes it: # application_helper.rb # https://gist.github.com/1205828 # Based on https://gist.github.com/1182136 class BootstrapLinkRenderer &#60; ::WillPaginate::ViewHelpers::LinkRenderer protected &#160; def html_container&#40;html&#41; tag :div, tag&#40;:ul, html&#41;, container_attributes [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using Ruby on Rails, you&#8217;ll likely use the will_paginate plugin. If you use Twitter&#8217;s Bootstrap CSS framework as well, you&#8217;ll notice that the pagination is all messed up. This <a href="https://gist.github.com/1205828">gist</a> fixes it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># application_helper.rb</span>
  <span style="color:#008000; font-style:italic;"># https://gist.github.com/1205828</span>
  <span style="color:#008000; font-style:italic;"># Based on https://gist.github.com/1182136</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> BootstrapLinkRenderer <span style="color:#006600; font-weight:bold;">&lt;</span> ::<span style="color:#6666ff; font-weight:bold;">WillPaginate::ViewHelpers::LinkRenderer</span>
    protected
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> html_container<span style="color:#006600; font-weight:bold;">&#40;</span>html<span style="color:#006600; font-weight:bold;">&#41;</span>
      tag <span style="color:#ff3333; font-weight:bold;">:div</span>, tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ul</span>, html<span style="color:#006600; font-weight:bold;">&#41;</span>, container_attributes
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> page_number<span style="color:#006600; font-weight:bold;">&#40;</span>page<span style="color:#006600; font-weight:bold;">&#41;</span>
      tag <span style="color:#ff3333; font-weight:bold;">:li</span>, link<span style="color:#006600; font-weight:bold;">&#40;</span>page, page, <span style="color:#ff3333; font-weight:bold;">:rel</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> rel_value<span style="color:#006600; font-weight:bold;">&#40;</span>page<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'active'</span> <span style="color:#9966CC; font-weight:bold;">if</span> page == current_page<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> gap
      tag <span style="color:#ff3333; font-weight:bold;">:li</span>, link<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">super</span>, <span style="color:#996600;">'#'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'disabled'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> previous_or_next_page<span style="color:#006600; font-weight:bold;">&#40;</span>page, text, classname<span style="color:#006600; font-weight:bold;">&#41;</span>
      tag <span style="color:#ff3333; font-weight:bold;">:li</span>, link<span style="color:#006600; font-weight:bold;">&#40;</span>text, page <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'#'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>classname<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>..<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>, classname, <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'disabled'</span> <span style="color:#9966CC; font-weight:bold;">unless</span> page<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> page_navigation_links<span style="color:#006600; font-weight:bold;">&#40;</span>pages<span style="color:#006600; font-weight:bold;">&#41;</span>
    will_paginate<span style="color:#006600; font-weight:bold;">&#40;</span>pages, :<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'pagination'</span>, <span style="color:#ff3333; font-weight:bold;">:inner_window</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:outer_window</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span>, <span style="color:#ff3333; font-weight:bold;">:renderer</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> BootstrapLinkRenderer, <span style="color:#ff3333; font-weight:bold;">:previous_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'&amp;larr;'</span>.<span style="color:#9900CC;">html_safe</span>, <span style="color:#ff3333; font-weight:bold;">:next_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'&amp;rarr;'</span>.<span style="color:#9900CC;">html_safe</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying Ruby on Rails 3.1 on Ubuntu</title>
		<link>http://www.leonardteo.com/2011/12/deploying-ruby-on-rails-on-ubuntu/</link>
		<comments>http://www.leonardteo.com/2011/12/deploying-ruby-on-rails-on-ubuntu/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 07:18:48 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=618</guid>
		<description><![CDATA[This serves as a reminder for me on getting Ruby on Rails 3.1.3 running on Ubuntu (tested on 10.01 LTS). Install git using apt-get: sudo apt-get install git-svn Install build dependencies: sudo apt-get install gcc g++ build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev Install rvm (Ruby Version Manager) bash -s stable &#60; &#60;&#40;curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer &#41; [...]]]></description>
			<content:encoded><![CDATA[<p>This serves as a reminder for me on getting Ruby on Rails 3.1.3 running on Ubuntu (tested on 10.01 LTS). </p>
<p>Install git using apt-get:</p>

<div class="wp_syntax"><div 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</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git-svn</span></pre></div></div>

<p>Install build dependencies:</p>

<div class="wp_syntax"><div 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</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #c20cb9; font-weight: bold;">g++</span> build-essential libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libsqlite3-dev</pre></div></div>

<p>Install rvm (Ruby Version Manager)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-s</span> stable <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>curl <span style="color: #660033;">-s</span> https:<span style="color: #000000; font-weight: bold;">//</span>raw.github.com<span style="color: #000000; font-weight: bold;">/</span>wayneeseguin<span style="color: #000000; font-weight: bold;">/</span>rvm<span style="color: #000000; font-weight: bold;">/</span>master<span style="color: #000000; font-weight: bold;">/</span>binscripts<span style="color: #000000; font-weight: bold;">/</span>rvm-installer <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Put RVM into .bash_rc file so that you can run it easily:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'[[ -s &quot;$HOME/.rvm/scripts/rvm&quot; ]] &amp;&amp; . &quot;$HOME/.rvm/scripts/rvm&quot; # Load RVM function'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_rc</pre></div></div>

<p>Reload bash settings:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_rc</pre></div></div>

<p>That should install rvm. Now you can use it to install Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2</pre></div></div>

<p>Make sure to switch into the correct version of Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rvm use 1.9.2</pre></div></div>

<p>Install Rails:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</pre></div></div>

<p>This takes a while&#8230;.</p>
<p>Install Apache:</p>

<div class="wp_syntax"><div 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</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2</pre></div></div>

<p>Install Phusion Passenger:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">passenger-install-apache2-module</pre></div></div>

<p>Follow the instructions on screen.</p>
<p>Setup Apache virtual hosting the way you normally do. Make the DocumentRoot the rails public directory.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
        <span style="color: #00007f;">ServerName</span> ec2-<span style="color: #ff0000;">107</span>-<span style="color: #ff0000;">21</span>-<span style="color: #ff0000;">154</span>-<span style="color: #ff0000;">173</span>.compute-<span style="color: #ff0000;">1</span>.amazonaws.com
        RailsEnv production
        <span style="color: #00007f;">DocumentRoot</span> /home/ubuntu/depot/public
        &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /home/ubuntu/depot/public&gt;
                <span style="color: #00007f;">Options</span> <span style="color: #0000ff;">Indexes</span> <span style="color: #0000ff;">FollowSymLinks</span> MultiViews
                <span style="color: #00007f;">AllowOverride</span> <span style="color: #0000ff;">All</span>
                <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
                <span style="color: #00007f;">allow</span> from <span style="color: #0000ff;">all</span>
        &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&nbsp;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>When deploying an app make sure to run bundle install to make sure all the dependencies are installed. This includes mysql, etc.</p>
<p>Rails 3.1 needs a Javascript runtime. </p>
<p>Add this to your gemfile:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gem <span style="color:#996600;">'execjs'</span>
gem <span style="color:#996600;">'therubyracer'</span></pre></div></div>

<p>Run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bundle <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Make sure to setup your DB using:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rake db:setup <span style="color: #007800;">RAILS_ENV</span>=<span style="color: #ff0000;">&quot;production&quot;</span></pre></div></div>

<p>Restart apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> service apache2 restart</pre></div></div>

<p>Load your browser and visit the site. Hopefully it works, if it doesn&#8217;t, check logs/production.log and trace from there.</p>
<h2>Asset Pipeline Gotchas</h2>
<p>The new asset pipeline in Rails may cause your app to fail. </p>
<p>When you deploy an app, make sure that you precompile the assets using:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">bundle <span style="color: #7a0874; font-weight: bold;">exec</span> rake assets:precompile</pre></div></div>

<p>If you are including css files that are not in your application.css manifest, you need to manually include them in your config/environments/production.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">assets</span>.<span style="color:#9900CC;">precompile</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'960.css'</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>Note: After recompiling assets you will need to restart your rails app. Do this either by restarting apache or creating/modifying &#8220;tmp/restart.txt&#8221; in your rails app. Passenger will look at the timestamp for restart.txt and restart rails accordingly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/12/deploying-ruby-on-rails-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rcconf &#8211; Tool to edit Linux boot services</title>
		<link>http://www.leonardteo.com/2011/11/rcconf-tool-to-edit-linux-boot-services/</link>
		<comments>http://www.leonardteo.com/2011/11/rcconf-tool-to-edit-linux-boot-services/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 20:53:07 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=610</guid>
		<description><![CDATA[I know I&#8217;ll forget this because I only have to edit runlevel services once in a blue moon. Use a tool called rcconf. You may have to install it using apt-get.]]></description>
			<content:encoded><![CDATA[<p>I know I&#8217;ll forget this because I only have to edit runlevel services once in a blue moon. Use a tool called rcconf. You may have to install it using apt-get.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/11/rcconf-tool-to-edit-linux-boot-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBulletin single sign on</title>
		<link>http://www.leonardteo.com/2011/11/vbulletin-single-sign-on/</link>
		<comments>http://www.leonardteo.com/2011/11/vbulletin-single-sign-on/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 16:01:29 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=599</guid>
		<description><![CDATA[I figure I would write this because I searched around for a suitable solution and it&#8217;s quite frustrating to find. VBulletin (the company) runs a very tight community and generally don&#8217;t help people who want to hack or extend the software. In my case, I am integrating VBulletin into a client&#8217;s custom application and trying [...]]]></description>
			<content:encoded><![CDATA[<p>I figure I would write this because I searched around for a suitable solution and it&#8217;s quite frustrating to find. VBulletin (the company) runs a very tight community and generally don&#8217;t help people who want to hack or extend the software. In my case, I am integrating VBulletin into a client&#8217;s custom application and trying to get single sign on to work. Do a search and you&#8217;ll find VBulletin telling people who have asked the same question &#8220;we won&#8217;t help you. Go to vbulletin.org.&#8221; When you do get to vbulletin.org, you can&#8217;t see any code because you&#8217;re not a licensed user. Very frustrating.</p>
<p>So&#8230;here it is.</p>
<p>VBulletin stores two cookie vars that can be used for single sign on:</p>
<ul>
<li>bb_userid &#8211; look in the &#8216;user&#8217; table, it is the field &#8216;userid&#8217;</li>
<li>bb_password &#8211; md5(user.password . COOKIE_SALT)</li>
</ul>
<p>When a user visits the forum, it can login based on the above.</p>
<p>Once you authenticate that the user can login in your app, read the user row from the vbulletin database. Take the password (which is already hashed) and concatenate the COOKIE_SALT constant to it. You can find COOKIE_SALT defined in /includes/functions.php. You then md5 hash this string and set the cookie as bb_password.</p>
<p>When setting your cookie, remember to set the domain to one that vbulletin can read. If you&#8217;re using different subdomains (e.g.   www.leonardteo.com for the main app and forums.leonardteo.com for the forums) simply set the domain to &#8220;.leonardteo.com&#8221;. In VBulletin, you&#8217;ll want to go into the admincp and change the cookie domain to the same.</p>
<p>By setting these two cookies, you should be able to login with your app and it will automatically login to VBulletin as well.</p>
<p><strong>Logout</strong><br />
Make sure you set the logout routine as well. Your logout routine needs to clear three cookies:</p>
<ul>
<li>bb_userid</li>
<li>bb_password</li>
<li>bb_sessionhash</li>
</ul>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/11/vbulletin-single-sign-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My rant about storing crucial web app settings in a database</title>
		<link>http://www.leonardteo.com/2011/11/my-rant-about-storing-crucial-web-app-settings-in-a-database/</link>
		<comments>http://www.leonardteo.com/2011/11/my-rant-about-storing-crucial-web-app-settings-in-a-database/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 12:51:37 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Rambling]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=591</guid>
		<description><![CDATA[I&#8217;ve been coding PHP for a long time. Since 1999 actually. That means that for most of my adult life, I&#8217;ve been working with this programming language in the web-o-sphere in general. I&#8217;ve gotten to work on many applications and continue to do so. I&#8217;ve also gotten to use many off-the-shelf apps including WordPress, Expression [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been coding PHP for a long time. Since 1999 actually. That means that for most of my adult life, I&#8217;ve been working with this programming language in the web-o-sphere in general. I&#8217;ve gotten to work on many applications and continue to do so. I&#8217;ve also gotten to use many off-the-shelf apps including WordPress, Expression Engine and VBulletin. Today, I&#8217;d like to rant about two conventions that these all have in common, and why we need to be rid of them.</p>
<h2>1. Storing paths and URLs in the database</h2>
<p>This happens in WordPress, Expression Engine and VBulletin. Basically, the idea is that all settings must be stored in a database table because&#8230;well&#8230;it&#8217;s supposed to be easier. The user updates a setting in the admin control panel, and it stores those settings in a database. The problem with storing paths in a database like this is that it makes the app less portable. For example, say you want to move an installation of any of the above-said apps to a different domain, it&#8217;s not as simple as tarballing the entire application, running mysqldump and restoring on the other side. You&#8217;d think that changing the config file would get it to work but this is only half the battle. WordPress and Vbulletin, for example, stores the actual URL of the application in the database, so when it does any redirect (e.g. when you login to the admin control panel), it will redirect to your OLD site.</p>
<p>WordPress does something else that I consider evil. When you upload images, it stores the full web path in the meta data. This is also a problem when you move to another domain because all your images are now pointing to the old domain. I&#8217;ve had to write scripts that change all metadata values and wordpress settings when porting from one domain to another. It&#8217;s annoying.</p>
<p><strong>Why is this an issue though?</strong></p>
<p>Development. For most people, the above shouldn&#8217;t matter because you have a blog that you installed on a webserver; you update it and all&#8217;s well. You never run a local copy of the site for development. As a developer though, I have to usually get local and staging copies of the website running. This means that I&#8217;m constantly having to do all kinds of shenanigans to get these instances running on different servers.</p>
<p>I used to think that this was simply a bad design limited to a couple of web apps but it seems like a whole plethora of web apps suffer from this. While working for Gnomon, we bought into Expression Engine, thinking that this would be the silver bullet that kills WordPress. Nada. EE is just as BADLY designed! (not just for the reasons above, but many others)</p>
<h2>2. Serializing Critical Settings</h2>
<p>PHP has a neat function called serialize(). It takes data and turns it into a string. The data can be read back in easily. This is great for many things. For example, if you have user accounts and each user has their own settings, it&#8217;s probably useful to just serialize their settings data and save it as a single string in the database.</p>
<p>Crucial site settings though, should NEVER be serialized in a database. I would go as far to say that as a rule of thumb, if the setting is crucial enough to make or break an installation of an app, it should be in a config file. This relates to my first rant as well. Many settings can be put in the database, but some settings (like paths), should just be in flat config files that can be quickly changed when moving the app.</p>
<p>I was absolutely shocked when using Expression Engine that crucial app-breaking settings like upload paths were not only stored in the database but SERIALIZED. I ended up writing a script that can move an entire installation of EE from one server to another in a single command line, and it&#8217;s really long because it had to connect to the database, unserialize the data, make modifications, re-serialize the data, write back to database.</p>
<p>It shouldn&#8217;t be this hard.</p>
<h2>My recommendation</h2>
<p>My recommendation is to follow this rule of thumb: if the setting is crucial enough to make or break an installation of an app, it should be in a config file.</p>
<p>Absolute paths like upload paths, etc. should be stored in a config file.</p>
<p>If the application needs a site-wide URL, this should be in a config file.</p>
<p>Individual asset links in the database should link to the relative location (i.e. minus the hostname.) e.g. not http://leonardteo.com/image1.jpg, but /image1.jpg instead. Even better, just store &#8216;image1.jpg&#8217; and use a configuration setting to determine what the path to that image is.</p>
<p>The litmus test should be: Tarball an application, dump the database. Copy everything to a different computer/hostname. Restore everything. If you can&#8217;t get the site up and running again without accessing and changing values in the database, fail.</p>
<h2>A practical benefit &#8211; fast deployment</h2>
<p>On a closing note, one of the benefits of running critical site settings in config files, is that you can switch configurations based on the hostname.</p>
<p>E.g. in your config file:</p>
<pre>switch ($_SERVER['SERVER_NAME']){
    case 'cgacontest.local':
        define('SITE_MODE', "LOCAL");
        break;
    case 'cgacontest.test':
        define('SITE_MODE', "TEST");
        break;
    case '3dsmaxdesign.cgarchitect.com':
        define('SITE_MODE', "LIVE");
        break;
}</pre>
<p>With the above code, we can switch between site modes and run different configurations automatically based on the hostname. This means that when it comes to deployment, I simply push any changes to the server without having to change configuration.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/11/my-rant-about-storing-crucial-web-app-settings-in-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting files in Unix in 1 command</title>
		<link>http://www.leonardteo.com/2011/07/deleting-files-in-unix-in-1-command/</link>
		<comments>http://www.leonardteo.com/2011/07/deleting-files-in-unix-in-1-command/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 11:52:45 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=563</guid>
		<description><![CDATA[I find myself constantly doing this with files that some OS&#8217;s and programs spew all over a directory structure. E.g. .DS_Store, .svn, etc. find . -name &#34;filename&#34; -exec rm -rf &#123;&#125; \;]]></description>
			<content:encoded><![CDATA[<p>I find myself constantly doing this with files that some OS&#8217;s and programs spew all over a directory structure. E.g. .DS_Store, .svn, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;filename&quot;</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/07/deleting-files-in-unix-in-1-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking Server Side Screenshots of Websites</title>
		<link>http://www.leonardteo.com/2011/07/taking-server-side-screenshots-of-websites/</link>
		<comments>http://www.leonardteo.com/2011/07/taking-server-side-screenshots-of-websites/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 13:01:42 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=517</guid>
		<description><![CDATA[(updated the post so that it works on Ubuntu 11.10) I was recently doing some testing to see if it was possible to take server side screenshots of websites. After a bit of fudging around, managed to do it&#8230;. Now, I can&#8217;t take credit for figuring this out. Other people have done this before me [...]]]></description>
			<content:encoded><![CDATA[<p>(updated the post so that it works on Ubuntu 11.10)</p>
<p>I was recently doing some testing to see if it was possible to take server side screenshots of websites. After a bit of fudging around, managed to do it&#8230;. Now, I can&#8217;t take credit for figuring this out. Other people have done this before me and some have posted blog posts about this, but technology changes so fast that some of the blog posts that outlined how to do this no longer work. I got most of the way from a <a href="http://tech.gregorymazurek.com/2010/12/28/how-to-generate-server-side-website-screenshots/">blog post</a> by <a href="http://gregorymazurek.com/about/">Gregory Mazurek</a>.</p>
<p>Tools:</p>
<ul>
<li>Ubuntu Linux (I used Ubuntu 11.10) &#8211; 32 bit (so we can run Flash without any problems)</li>
<li>Xvfb</li>
<li>Firefox</li>
<li>Flash</li>
<li>ImageMagick</li>
</ul>
<p>Theoretically, it sounds very simple. Xvfb lets you run X windows but rather than rendering to a display (servers might not have a display), it renders to a virtual framebuffer. So&#8230;you run Firefox in Xvfb, then take a screenshot of it as it&#8217;s running. Simple right? lol&#8230;</p>
<p><strong>Step 1  - Install all the stuff you need</strong></p>
<p>sudo apt-get install xvfb<br />
sudo apt-get install firefox<br />
sudo apt-get install adobe-flashplugin    //You may need to enable the canonical partner repositories. Uncomment appropriate lines in /etc/apt/sources.list<br />
sudo apt-get install imagemagick</p>
<p><strong>Step 2 &#8211; Get the xvfb process running</strong></p>
<p>Note: Credit to <a href="http://tech.gregorymazurek.com/2010/12/28/how-to-generate-server-side-website-screenshots/">Gregory Mazurek</a> for this shell script&#8230;</p>
<p>Create a file in /etc/init.d called xvfb. Put this in:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># /etc/rc.d/init.d/xvfb</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># chkconfig: 345 98 90</span>
<span style="color: #666666; font-style: italic;"># description: starts virtual framebuffer process to</span>
<span style="color: #666666; font-style: italic;"># enable server</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Source function library.</span>
<span style="color: #666666; font-style: italic;">#.  /etc/init.d/functions</span>
<span style="color: #007800;">XVFB_OUTPUT</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Xvfb.out
<span style="color: #007800;">XVFB</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>Xvfb
<span style="color: #007800;">XVFB_OPTIONS</span>=<span style="color: #ff0000;">&quot;:5 -screen 0 1080x1440x24 -fbdir /var/run&quot;</span>
&nbsp;
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>  <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting : X Virtual Frame Buffer &quot;</span>
<span style="color: #007800;">$XVFB</span> <span style="color: #007800;">$XVFB_OPTIONS</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #007800;">$XVFB_OUTPUT</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #007800;">$RETVAL</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>   <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Shutting down : X Virtual Frame Buffer&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #c20cb9; font-weight: bold;">killall</span> Xvfb
<span style="color: #7a0874; font-weight: bold;">echo</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
start
<span style="color: #000000; font-weight: bold;">;;</span>
stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
stop
<span style="color: #000000; font-weight: bold;">;;</span>
status<span style="color: #7a0874; font-weight: bold;">&#41;</span>
status xvfb
<span style="color: #000000; font-weight: bold;">;;</span>
restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    stop
    start
    <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: xvfb {start|stop|status|restart}&quot;</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span></pre></div></div>

<p>Once you have this shell script in place, you can simply start and stop the xvfb server easily with:<br />
sudo /etc/init.d/xvfb start    (or sudo service xvfb start)<br />
sudo /etc/init.d/xvfb stop</p>
<p>Great!</p>
<p>Now to run Firefox&#8230;</p>
<p><strong>Step 3 &#8211; Firefox and Flash</strong></p>
<p>I&#8217;ll assume that you did the apt-get install to get both Firefox and flash-plugin. Once you have those, test the configuration like this&#8230;</p>
<p>1. Make sure that the xvfb server is running<br />
2. Run this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">5</span> <span style="color: #c20cb9; font-weight: bold;">nohup</span> firefox http:<span style="color: #000000; font-weight: bold;">//</span>www.youtube.com <span style="color: #000000; font-weight: bold;">&amp;</span>amp;</pre></div></div>

<p>DISPLAY=:5 // This tells xvfb to render to display 5 (virtual)<br />
nohup //silence the output<br />
firefox //loads firefox<br />
http://youtube.com //loads youtube which tells you whether you have Flash or not<br />
&amp; //Load this in the background</p>
<p>Firefox should be running in the background now. If it&#8217;s not, you may have to debug and find out why. Remove the nohup and the &amp; to see the output to shell if you need to debug.</p>
<p>Now comes the moment of truth. Taking a screenshot:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">5</span> import <span style="color: #660033;">-window</span> root screenshot.png</pre></div></div>

<p>This will dump the desktop to screenshot.png. Check it.</p>
<p>Kill firefox by typing &#8216;fg&#8217; then CTRL+C.</p>
<p><strong>Step 4 &#8211; Firefox configuration</strong></p>
<p>We have to override the default Firefox configuration settings. E.g. it has one that will try to resume a crash.</p>
<p>Firefox stores its preferences in the user root  ~/.mozilla. On each system and each user it&#8217;s different. Look in: ~/.mozilla/firefox/</p>
<p>In there, you should see a directory with funny numbers and letters followed by a .default. Mine is 6mqvagz4.default.  Chdir into there. Create a file called user.js.</p>
<p>The problem here is that we either have to edit files manually or have to get Firefox to generate the appropriate settings for us. If you are already using Ubuntu at home, this is much simpler because you can set up Firefox however you like, then take the entire preferences directory and copy its contents into the server&#8217;s. This is what I ended up doing. That route is by far the easiest and recommended.</p>
<p>Otherwise:</p>
<p>In prefs.js, edit these:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">pref<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;browser.startup.page&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pref<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;browser.sessionstore.resume_from_crash&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now&#8230;another annoyance is that the Firefox window may not be at the size you want it. So you need to edit the file &#8216;localstore.rdf&#8217;. What I ended up doing was running Firefox on my Mac at home, deleting the localstore.rdf file, having Firefox generate a new one. On quitting, it saves it out. This is my localstore.rdf file that I ended up using:</p>
<p>localstore.rdf:</p>
<pre>&lt;?xml version="1.0"?&gt;
&lt;RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
  &lt;RDF:Description RDF:about="about:config#lockCol"
                   ordinal="3" /&gt;
  &lt;RDF:Description RDF:about="about:config#prefCol"
                   ordinal="1"
                   sortDirection="ascending" /&gt;
  &lt;RDF:Description RDF:about="about:config#valueCol"
                   ordinal="7" /&gt;
  &lt;RDF:Description RDF:about="chrome://browser/content/browser.xul#sidebar-title"
                   value="" /&gt;
  &lt;RDF:Description RDF:about="about:config#typeCol"
                   ordinal="5" /&gt;
  &lt;RDF:Description RDF:about="chrome://browser/content/browser.xul"&gt;
    &lt;NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/&gt;
    &lt;NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/&gt;
    &lt;NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/&gt;
  &lt;/RDF:Description&gt;
  &lt;RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
                   screenY="0"
                   width="1080"
                   screenX="0"
                   height="1440"
                   sizemode="maximized" /&gt;
  &lt;RDF:Description RDF:about="about:config"&gt;
    &lt;NC:persist RDF:resource="about:config#prefCol"/&gt;
    &lt;NC:persist RDF:resource="about:config#lockCol"/&gt;
    &lt;NC:persist RDF:resource="about:config#typeCol"/&gt;
    &lt;NC:persist RDF:resource="about:config#valueCol"/&gt;
  &lt;/RDF:Description&gt;
&lt;/RDF:RDF&gt;</pre>
<p>Notice the width and height of the window. I set it to this portrait width/height so that I could grab square images.</p>
<p><strong>Step 5 &#8211; Further Automation</strong></p>
<p>From here, you can do further automation to make the process of taking a screenshot really simple. I created this script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#screengrab</span>
&nbsp;
<span style="color: #007800;">FIREFOX_OUTPUT</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firefox.out
<span style="color: #007800;">TIMESTAMP</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">DELAY</span>=<span style="color: #000000;">5</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Check for args</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You need to pass a URL in. E.g. urlscreengrab www.google.com&quot;</span>
                <span style="color: #7a0874; font-weight: bold;">exit</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Calculate how many instances of grab we have running</span>
<span style="color: #007800;">COUNT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'grab.sh'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">COUNT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>COUNT-<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #666666; font-style: italic;">#I don't know why but the above returns 2 when there are 0 processes running.</span>
<span style="color: #666666; font-style: italic;">#if grab.sh is already running, wait for it to finish</span>
<span style="color: #007800;">WAIT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>DELAY<span style="color: #000000; font-weight: bold;">*</span>COUNT<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$WAIT</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">WAIT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>WAIT+<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #666666; font-style: italic;">#Add 2 seconds to wait for other grab processes to finish</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Waiting <span style="color: #007800;">$WAIT</span> seconds for other grab processes to finish&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$WAIT</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Load up firefox</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Loading Firefox&quot;</span>
<span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">5</span> firefox <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #007800;">$FIREFOX_OUTPUT</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #007800;">FFPID</span>=<span style="color: #007800;">$!</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Standby...waiting <span style="color: #007800;">$DELAY</span> seconds for browser to load...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$DELAY</span>
<span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">5</span> import <span style="color: #660033;">-window</span> root <span style="color: #660033;">-crop</span> 1000x1000+<span style="color: #000000;">4</span>+<span style="color: #000000;">86</span> <span style="color: #007800;">$TIMESTAMP</span>.png
<span style="color: #666666; font-style: italic;">#DISPLAY=:5 import -window root $TIMESTAMP.png</span>
<span style="color: #666666; font-style: italic;">#killall firefox-bin</span>
<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #007800;">$FFPID</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TIMESTAMP</span>.png&quot;</span></pre></div></div>

<p>To use this script, type: ./urlscreengrab http://www.youtube.com</p>
<p>With the above configuration, it will automatically take the screenshot and crop it into a 1000&#215;1000 square png file. It also has process checking, so it will check for existing Firefox processes and wait until the other grab processes finish. It will also wait 5 seconds for a web page to finish loading before taking the shot. This is needed on many web pages because it takes time to load the page.</p>
<p><strong>Step 6 &#8211; Hook up to your web scripts</strong></p>
<p>From here, I just call the web script from PHP using the exec() command. Make sure that Apache is running using the same user as you set up your above scripts so that it can use the correct Mozilla profile. To check, create a php script with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'whoami'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This should give you the user of the owner of the apache/php process.</p>
<p>My web script for grabbing the image:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
Script for grabbing a website image
*/</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No URL provided&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//chdir into the correct dir</span>
<span style="color: #990000;">chdir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Grab the site</span>
<span style="color: #000088;">$exec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/home/ubuntu/grab.sh &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Executing: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$exec</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$lastline</span> <span style="color: #339933;">=</span> <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exec</span><span style="color: #339933;">,</span> <span style="color: #000088;">$out</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</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;">$out</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$line</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$line</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Finished with status: <span style="color: #006699; font-weight: bold;">$status</span> &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href=&quot;</span>\<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span>images<span style="color: #339933;">/</span><span style="color: #000088;">$lastline</span>\<span style="color: #339933;">&amp;</span>quot<span style="color: #339933;">;</span><span style="color: #0000ff;">&quot;&gt;Your image is here&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There you go&#8230;have fun. <img src='http://www.leonardteo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley colorbox-517' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/07/taking-server-side-screenshots-of-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick and dirty WordPress profiling</title>
		<link>http://www.leonardteo.com/2011/07/quick-and-dirty-wordpress-profiling/</link>
		<comments>http://www.leonardteo.com/2011/07/quick-and-dirty-wordpress-profiling/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 11:59:08 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=510</guid>
		<description><![CDATA[Recently while working on one of our client sites CG Channel, the front page was taking around 8-10 seconds to load. This was driving me crazy. Somehow, the page had gotten so bloated that it was taking what the web considers to be an eternity to show anything on screen. At first, I assumed it [...]]]></description>
			<content:encoded><![CDATA[<p>Recently while working on one of our client sites <a href="http://www.cgchannel.com">CG Channel</a>, the front page was taking around 8-10 seconds to load. This was driving me crazy. Somehow, the page had gotten so bloated that it was taking what the web considers to be an eternity to show anything on screen. At first, I assumed it was the RSS feeds that it was reading to update various content on the site, but soon found that information was cached. What now?</p>
<p>Profiling to the rescue. In PHP, you have some pretty good tools that enable you to do profiling on your application. In the case of WordPress which is mostly theme (view) driven, it&#8217;s almost easier because all the processing is called from the view itself. In the case of CG Channel homepage home.php, I put the following code in&#8230;</p>
<p>This goes at the top of the page:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$timer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timer</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Timing functions</span>
	<span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$global_time_start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It basically sets up a timer. The $timer variable is for you to turn the timer on or off. If you put lot&#8217;s of timers in, you can simply switch it off later rather than having to remove all the code.</p>
<p>The PHP <a href="http://php.net/manual/en/function.microtime.php">microtime</a>() function returns the current unix timestamp with microseconds. Just what we need.</p>
<p>$time_start holds the time for the current block.<br />
$global_time_start holds the time for the entire page.</p>
<p>To time a previously rendered section, you just do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timer</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span style=<span style="color: #000099; font-weight: bold;">\&quot;</span>color:red<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$time</span> seconds&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So&#8230;for example&#8230;.:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$timer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timer</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//Timing functions</span>
	<span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$global_time_start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timer</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span style=<span style="color: #000099; font-weight: bold;">\&quot;</span>color:red<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$time</span> seconds&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This would time the get_header() section of the site. When you refresh the page, it will show the time it&#8217;s taken to render the previous section.</p>
<p>At the bottom of the page, you can put:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timer</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$time_start</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span style=<span style="color: #000099; font-weight: bold;">\&quot;</span>color:red<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$time</span> seconds&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$time_start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #000088;">$global_time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$time_start</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$global_time_start</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;span style=<span style="color: #000099; font-weight: bold;">\&quot;</span>color:red<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Total page render time: <span style="color: #006699; font-weight: bold;">$global_time</span> seconds&lt;/span&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will give you a time for the previous block that was rendered, and the global time that it took for the whole page to run.</p>
<p>Doing this, I found the culprit. Using <a href="http://codex.wordpress.org/Class_Reference/WP_Query">WP_Query</a>() to fetch posts and using the <a href="http://codex.wordpress.org/The_Loop">wordpress loop</a> was very slow: about 4 seconds for fetching and displaying 12 news items. I found another function <a href="http://codex.wordpress.org/Template_Tags/get_posts">get_posts</a>() which returned all the information I needed to show the news items, so I switched to using that. Rather than using a WordPress loop, I used a simple foreach() loop. This brought each query down to under 1 second!</p>
<p>To further optimize, rather than using WordPress template tags to directly output data, I cached them into variables. For example, if you are going to call get_post_meta() on the same meta information multiple times in a loop, save the data into a variable and use the variable instead. This saves WordPress the trouble of doing unnecessary database calls.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Return array of posts</span>
<span style="color: #000088;">$posts</span> <span style="color: #339933;">=</span> get_posts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'numberposts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//If you want to see what's in the array...</span>
<span style="color: #666666; font-style: italic;">//var_dump($posts);</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Loop through each post</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Cache the variables</span>
	<span style="color: #000088;">$permalink</span> <span style="color: #339933;">=</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thumbnail_b</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;thumbnail_b&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$thumbnail_s</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;thumbnail_s&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$plug_title</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;plug_title&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Do whatever output you want here....</span>
&nbsp;
<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span></pre></div></div>

<p>I did some further optimization of the site with minification of javascript, getting rid of unnecessary code, etc. My efforts resulted in the site going from taking about 10 seconds to load, down to 1-1.5 seconds. That&#8217;s not bad. Could be faster, but at least the site feels snappy now!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/07/quick-and-dirty-wordpress-profiling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Nginx and PHP5 on Ubuntu</title>
		<link>http://www.leonardteo.com/2011/07/nginx/</link>
		<comments>http://www.leonardteo.com/2011/07/nginx/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 22:44:21 +0000</pubDate>
		<dc:creator>Leo</dc:creator>
				<category><![CDATA[Reminders to myself]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.leonardteo.com/?p=504</guid>
		<description><![CDATA[Very simple to set up Nginx, PHP5 and MySQL on Ubuntu. Hats off to the Ubuntu guys for making it so simple. sudo apt-get install nginx sudo apt-get install php5-cgi  (you might need to also need to install php5) Test that nginx works by opening your browser and going to http://localhost/ Edit /etc/nginx/sites-available/default Search for [...]]]></description>
			<content:encoded><![CDATA[<p>Very simple to set up Nginx, PHP5 and MySQL on Ubuntu. Hats off to the Ubuntu guys for making it so simple.</p>
<ol>
<li>sudo apt-get install nginx</li>
<li>sudo apt-get install php5-cgi  (you might need to also need to install php5)</li>
</ol>
<p>Test that nginx works by opening your browser and going to http://localhost/</p>
<p>Edit /etc/nginx/sites-available/default</p>
<p>Search for the bits that say &#8220;# pass the PHP scripts to FastCGI server&#8230;.&#8221; uncomment those configuration bits.</p>
<p>Create index.php in /usr/share/nginx/www/</p>
<p>In it, put:</p>
<pre> &lt;?php  phpinfo();</pre>
<p>In a web browser go to http://localhost/index.php     It should give you a &#8220;bad gateway error&#8221;. This is because php fastCGI isn&#8217;t running. Go back to your terminal and type &#8220;php5-cgi -b 127.0.0.1:9000 &amp;&#8221;  This should start php fastCGI in the background. Now visit http://localhost/index.php again and you should see the php info screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leonardteo.com/2011/07/nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

