<?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>phoenixheart - portfolio &#38; more &#187; virtual host</title> <atom:link href="http://www.phoenixheart.net/tag/virtual-host/feed/" rel="self" type="application/rss+xml" /><link>http://www.phoenixheart.net</link> <description>phoenixheart - portfolio &#38; more</description> <lastBuildDate>Wed, 25 Aug 2010 03:02:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <script type="text/javascript">/*<![CDATA[*/if(typeof Meebo=="undefined"){Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};(function(q){var args=arguments;if(!document.body){return setTimeout(function(){args.callee.apply(this,args)},100);}var d=document,b=d.body,m=b.insertBefore(d.createElement('div'),b.firstChild);s=d.createElement('script');m.id='meebo';m.style.display='none';m.innerHTML='<iframe id="meebo-iframe"></iframe>';s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;b.insertBefore(s,b.firstChild);})({network:'phoenixheartnet_bo16we'});}/*]]>*/</script> <item><title>How to configure nginx to run Kohana on Ubuntu</title><link>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/</link> <comments>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/#comments</comments> <pubDate>Mon, 01 Mar 2010 07:20:23 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Featured]]></category> <category><![CDATA[Server stuffs]]></category> <category><![CDATA[configure]]></category> <category><![CDATA[kohana]]></category> <category><![CDATA[nginx]]></category> <category><![CDATA[virtual host]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=440</guid> <description><![CDATA[As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve started to move away from Apache in favor of nginx (pronounced &#8220;engine-X&#8221;). It&#8217;s not that I really need its strength, it&#8217;s just that I wanted to learn something new to break my box. It&#8217;s fairly simple to set up [...]]]></description> <content:encoded><![CDATA[<p>As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve started to move away from Apache in favor of <a
title="nginx's homepage" href="http://nginx.org/">nginx</a> (pronounced &#8220;engine-X&#8221;). It&#8217;s not that I really need <a
title="nginx compared to Apache" href="http://www.joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/">its strength</a>, it&#8217;s just that I wanted to learn something new to break my box.</p><p>It&#8217;s fairly simple to set up and get nginx running with FastCGI and MySQL on Ubuntu &#8211; a very well-written tutorial can be read <a
href="http://www.howtoforge.com/installing-nginx-with-php5-and-mysql-support-on-ubuntu-8.10">on HowtoForge</a>, which should take you less than 15 minutes for everything. In this article therefore I will only write about how to configure nginx to actually run a <a
href="http://www.kohanaphp.com/">Kohana</a>-powered site, with virtual host and rewriting and such. If you&#8217;re not familiar with Kohana, take a look at <a
href="http://www.phoenixheart.net/2009/01/kohana-php-framework/">my article here</a>.</p><h3>The prerequisites</h3><ul><li>I have my Kohana-power site located under <code>/home/phoenixheart/www/my-kohana/</code> directory with proper permission set (owner being www-data, that is).</li><li>nginx has been set up properly and listening on port 80, with the configuration directory being <code>/etc/nginx/</code></li><li>I want my site to be locally accessible via my-kohana.dev. Any requests to www.my-kohana.dev should be permanently redirected to my-kohana.dev &#8211; which is also called &#8220;force non-www&#8221;.</li><li>I want to have neat URL rewriting without &#8220;index.php&#8221;, for example <code>index.php?controller=product&amp;function=get&amp;id=1</code> should be rewritten into <code>/product/get/1</code></li><li>I also want that all existing files and directories under the root directory are accessible, except Kohana&#8217;s system directories <code>system</code>, <code>application</code>, and <code>modules</code>. Any attempt to access system files and directories(beginning with dots, like .htaccess or .settings) should be disallowed also.</li></ul><p>All clear. So let&#8217;s do it!<br
/> <span
id="more-440"></span></p><h3>Set up the virtual host</h3><p>The way nginx handles virtual hosts is totally different from Apache, as we can expect. Instead of using .conf files to declare and configure the hosts, nginx, when started, additionally scans through the configuration folder (<code>/etc/nginx</code> in our case) to find (if any) configuration files under 2 directories: sites-available and sites-enabled. So under /etc/nginx/sites-available, create a file called my-kohana.dev with the following content:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">server <span style="color: #009900;">&#123;</span>
    listen   <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
    server_name my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">;</span>
&nbsp;
    access_log <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">/</span>access<span style="color: #339933;">.</span><span style="color: #990000;">log</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># remember to create this file
</span>    <span style="color: #990000;">error_log</span> <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">/</span>error<span style="color: #339933;">.</span><span style="color: #990000;">log</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;"># and this file
</span>
    location <span style="color: #339933;">/</span> <span style="color: #009900;">&#123;</span>
	root   <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">;</span>
	index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location ~ \<span style="color: #339933;">.</span>php$ <span style="color: #009900;">&#123;</span>
	fastcgi_pass   127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1<span style="color: #339933;">:</span><span style="color: #cc66cc;">9000</span><span style="color: #339933;">;</span>
	fastcgi_index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
	fastcgi_param  SCRIPT_FILENAME  <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #000088;">$fastcgi_script_name</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">include</span>        fastcgi_params<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Of course, this is just the basis configuration for the site to get up and running. To continue, we must create a host entry. Open /etc/hosts and add this line:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1	my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev www<span style="color: #339933;">.</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev</pre></td></tr></table></div><p>If this was Apache, we would be good enough to restart the webserver to see the result. But like I said, nginx is different. For nginx to properly recognize and serve our site, we must <em>enable</em> the site by creating a symlink of the configuration file under <code>sites-enabled</code>. We do that as follow:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">ln <span style="color: #339933;">-</span>s <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>sites<span style="color: #339933;">-</span>available<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>sites<span style="color: #339933;">-</span>enabled<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev</pre></div></div><p>Now, let&#8217;s restart nginx. Open Terminal and type:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">sudo <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>init<span style="color: #339933;">.</span>d<span style="color: #339933;">/</span>nginx restart</pre></div></div><p>The result should be as followed:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">Restarting nginx<span style="color: #339933;">:</span> the configuration <span style="color: #990000;">file</span> <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>nginx<span style="color: #339933;">.</span>conf syntax is ok
configuration <span style="color: #990000;">file</span> <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>nginx<span style="color: #339933;">.</span>conf test is successful
nginx<span style="color: #339933;">.</span></pre></div></div><p>If you receive any &#8220;failure&#8221; response, chance is some typos in the configuration.</p><p>Now, http://my-kohana.dev should be accessible via the browser (Note that, if Kohana complains about the logs folder inaccessible, try properly setting its owner to www-data). Next step is tweaking the configuration a bit to serve our needs.</p><h3>Tweak it up</h3><h4>Force non-www</h4><p>To force non-www, open sites-available/my-kohana.dev and add these lines at the top:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">server <span style="color: #009900;">&#123;</span>
    listen <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
    server_name www<span style="color: #339933;">.</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">;</span>
    rewrite  ^<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$  http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//my-kohana.dev/$1  permanent;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>This kind of configuration is very similar to that of Apache, so I would assume there&#8217;s no need to explain. After a nginx restart, all request to http://www.my-kohana.dev should be silently redirected to http://my-kohana.dev.</p><h4>Neat URL rewriting</h4><p>Again, in sites-available/my-kohana.dev, modify the first <code>location</code> block to the following</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">location <span style="color: #339933;">/</span> <span style="color: #009900;">&#123;</span>
    root   <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">;</span>
    index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># this is where the rewriting gets done.
</span>    <span style="color: #666666; font-style: italic;"># refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
</span>    rewrite ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>index<span style="color: #339933;">.</span>php?kohana_uri<span style="color: #339933;">=</span>$<span style="color: #cc66cc;">1</span> last<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>But wait! We don&#8217;t want EVERY requests to be re-written. For example, a request to my-kohana.dev/css/style.css should be kept as-is. Same goes with javascripts and images. In short, if the request is for an existing file or folder, we keep it as-is; else, we route it to index.php using rewriting. To achieve that, modify the configuration above to this:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">location <span style="color: #339933;">/</span> <span style="color: #009900;">&#123;</span>
    root   <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">;</span>
    index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>f <span style="color: #000088;">$request_filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># translated into &quot;if the request is an existing file, break (do nothing)&quot;
</span>        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>d <span style="color: #000088;">$request_filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># translated into &quot;if the request is an existing directory, break (do nothing)&quot;
</span>        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># the request is not an existing file or directory
</span>    <span style="color: #666666; font-style: italic;"># this is where the rewriting gets done.
</span>    <span style="color: #666666; font-style: italic;"># refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
</span>    rewrite ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>index<span style="color: #339933;">.</span>php?kohana_uri<span style="color: #339933;">=</span>$<span style="color: #cc66cc;">1</span> last<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><h4>Set files and folder accessibilities</h4><p>Now, we prohibit access to the sensitive stuffs, including kohana system folders, dot files and directories etc. It&#8217;s fairly simple with nginx. All we need to do is adding two more location blocks, specific for this purpose:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">location ~ <span style="color: #339933;">/</span>\<span style="color: #339933;">.</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">404</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># or, if you prefer
</span>    <span style="color: #666666; font-style: italic;">#return 403;
</span>    <span style="color: #666666; font-style: italic;"># or even
</span>    <span style="color: #666666; font-style: italic;">#deny all;
</span><span style="color: #009900;">&#125;</span>
location ~<span style="color: #339933;">*</span> ^<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>modules<span style="color: #339933;">|</span>application<span style="color: #339933;">|</span>system<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">404</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;"># or, if you prefer
</span>    <span style="color: #666666; font-style: italic;">#return 403;
</span>    <span style="color: #666666; font-style: italic;"># or even
</span>    <span style="color: #666666; font-style: italic;">#deny all;
</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>The final configuration file should look like this:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">server <span style="color: #009900;">&#123;</span>
    listen <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
    server_name www<span style="color: #339933;">.</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">;</span>
    rewrite  ^<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">.*</span><span style="color: #009900;">&#41;</span>$  http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//my-kohana.dev/$1  permanent;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
server <span style="color: #009900;">&#123;</span>
    listen   <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
    server_name my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">;</span>
&nbsp;
    access_log <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">.</span>access<span style="color: #339933;">.</span><span style="color: #990000;">log</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">error_log</span> <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">.</span>error<span style="color: #339933;">.</span><span style="color: #990000;">log</span><span style="color: #339933;">;</span>
&nbsp;
    location ~ <span style="color: #339933;">/</span>\<span style="color: #339933;">.</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">404</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location <span style="color: #339933;">/</span> <span style="color: #009900;">&#123;</span>
        root   <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">;</span>
        index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>f <span style="color: #000088;">$request_filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;"># translated into &quot;if the request is an existing file, break (do nothing)&quot;
</span>            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>d <span style="color: #000088;">$request_filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;"># translated into &quot;if the request is an existing directory, break (do nothing)&quot;
</span>            <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># the request is not an existing file or directory
</span>        <span style="color: #666666; font-style: italic;"># this is where the rewriting gets done.
</span>        <span style="color: #666666; font-style: italic;"># refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
</span>        rewrite ^<span style="color: #009900;">&#40;</span><span style="color: #339933;">.+</span><span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">/</span>index<span style="color: #339933;">.</span>php?kohana_uri<span style="color: #339933;">=</span>$<span style="color: #cc66cc;">1</span> last<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location ~ \<span style="color: #339933;">.</span>php$ <span style="color: #009900;">&#123;</span>
        fastcgi_pass   127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1<span style="color: #339933;">:</span><span style="color: #cc66cc;">9000</span><span style="color: #339933;">;</span>
        fastcgi_index  index<span style="color: #339933;">.</span>php<span style="color: #339933;">;</span>
        fastcgi_param  SCRIPT_FILENAME  <span style="color: #339933;">/</span>home<span style="color: #339933;">/</span>phoenixheart<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #000088;">$fastcgi_script_name</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">include</span>        fastcgi_params<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    location ~<span style="color: #339933;">*</span> ^<span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>modules<span style="color: #339933;">|</span>application<span style="color: #339933;">|</span>system<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">403</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>After another nginx restart, our Kohana instance should run without any hassles.</p><p>Typos? Mistakes? Errors? Let&#8217;s hear it in your comment.</p> <img
style='display:none' id="post-440-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/',title:'How to configure nginx to run Kohana on Ubuntu',tweet:'As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve st',description:'As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve st'})"><script type='text/javascript'>document.getElementById("post-440-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Setup a development version of WordPress</title><link>http://www.phoenixheart.net/2009/01/setup-a-development-version-of-wordpress/</link> <comments>http://www.phoenixheart.net/2009/01/setup-a-development-version-of-wordpress/#comments</comments> <pubDate>Mon, 05 Jan 2009 07:38:19 +0000</pubDate> <dc:creator>phoenix.heart</dc:creator> <category><![CDATA[Blahblahblah]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[apache]]></category> <category><![CDATA[virtual host]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[xampp]]></category><guid
isPermaLink="false">http://www.phoenixheart.net/?p=190</guid> <description><![CDATA[Being a WordPress user, there&#8217;re certainly times when you want to try something new with your blog &#8211; a new plugin, some hacks and tweaks, some theme fine-tunes etc. It may not be a big deal if your blog is new and has a limited userbase, but if you&#8217;re maintaining a big blog, then every [...]]]></description> <content:encoded><![CDATA[<p><span
class="drop-cap">B</span>eing a WordPress user, there&#8217;re certainly times when you want to try something new with your blog &#8211; a new plugin, some hacks and tweaks, some theme fine-tunes etc. It may not be a big deal if your blog is new and has a limited userbase, but if you&#8217;re maintaining a big blog, then every little modification puts you in risk. Like, if something goes wrong with the plugin you&#8217;re developing, the whole running site maybe broken, and you may lose hundreds of visitors and RSS subscribers before you know it. Well, it&#8217;s my own story too&#8230; once I left my <a
href="http://www.thica.net">Thica.net</a> abandoned two days long, without even knowing that with my <em>smart</em> hacks, all the internal links were totally broken. The worst thing is, that mechanic Google didn&#8217;t forgive me about this, which resulted in a disappearance of Thica.net from the first 2 result pages &#8211; ugh.</p><p>So after that stupid &#8220;accident&#8221;, I decided to keep myself out of those risks. I installed a local development version of Thica.net on my own PC. It was a true breeze &#8211; very easy and fast. If you&#8217;re like me &#8211; always living on the news trying new cool stuffs &#8211; then here is a step-by-step guide, with no or very little coding involved. Even better, all software to be used are free/open source.<span
id="more-190"></span></p><h4>Step 1: Downloading XAMPP</h4><p>I always prefer quick and easy ways. So to setup a server that hosts my development copy, instead of seperatedly download and install and configure those complex Apache, MySQL, PHP, I obtained a copy of <a
href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> which is a package with all Apache, MySQL, and PHP bundled (in case you&#8217;re wondering, X stands for &#8220;all major operating systems&#8221;, A for Apache, M for MySQL, 1st P for PHP, 2nd one for Perl).</p><h4>Step 2: Installing XAMPP</h4><p>The installation was dead simple. Just run the downloaded executable file, click Next, Next, Next, then done. By default, the XAMPP files are saved at C:\xampp, but I chose to place them under E:\xampp\xampp, just by habit.</p><p>Just before the installation is finished, XAMPP will start Apache, PHP, and MySQL as services. If for any reason it doesn&#8217;t, you will head to its installation folder, start XAMPP control panel by double clicking xampp-control.exe, and manually manage those services there.</p><p><img
class="shot" src="/wp-content/uploads/2009/1/xampp-cp.gif" alt="XAMPP Control Panel" /></p><p>Now the server is basically ready to rock. Piece of cake, isn&#8217;t it? Now on to the next steps.</p><h4>Step 3: Copying the files</h4><p>Now, for the content, first I created a directory called &#8220;thica.net&#8221; in my XAMPP&#8217;s htdocs folder. To fill it up, I fired up my all-time favorite FTP client FileZilla and started downloading everything from my server.</p><p><a
href="/wp-content/uploads/2009/01/filezilla.gif"><img
class="shot" src="/wp-content/uploads/2009/01/filezilla.gif" alt="Downloading contents using FileZilla" width="450" /></a></p><p>Of course you may use some plugins out there or the useful backup feature of cPanel to get the server content into one archive and extract it on local. Whatever it is, just make sure the contents of you remote site and local folder are identical.</p><p><a
href="/wp-content/uploads/2009/01/local-remote.gif"><img
class="shot" src="/wp-content/uploads/2009/01/local-remote.gif" alt="Comparing Local (left) and Remote (right) folder contents" width="450" /></a></p><h4>Step 4: Creating the local database</h4><p>Now we&#8217;ll have to run the SQL dump file just downloaded toward the local MySQL to create the local database. Any MySQL front end utility can do this, but I used the most popular phpMyAdmin which should be built-in already at http://localhost/phpmyadmin/ right after XAMPP was installed (remember it?). Well, just click &#8220;Databases&#8221; and locate &#8220;Create databases&#8221; section.</p><p><a
href="/wp-content/uploads/2009/01/phpmyadmin-createdb.gif"><img
class="shot" src="/wp-content/uploads/2009/01/phpmyadmin-createdb.gif" alt="Create local database" width="450" /></a></p><p>Note that I set the database collation as &#8220;utf8_unicode_ci&#8221; which is the best in most cases.</p><h4>Step 5: Backing up the remote database</h4><p>I used a extremely useful plugin called <a
href="http://wordpress.org/extend/plugins/wp-dbmanager/">WP-DBManager</a> to backup the whole server WordPress database into one SQL dump. After installing and activate the plugin, just head to Database -&gt; Backup DB and you&#8217;ll be served with something similar to this screenshot:</p><p><a
href="/wp-content/uploads/2009/01/db-backup.gif"><img
class="shot" src="/wp-content/uploads/2009/01/db-backup.gif" alt="Backup database" width="450" /></a></p><p>One the database was backup, I downloaded the dump file to my local machine and process to the next step.</p><h4>Step 6: Populating the local data</h4><p>Now, with the SQL dump in my hand, we&#8217;d need to populate it so that the data is the same as that of the remote server. For this, I accessed http://localhost/phpmyadmin/ again, selected the database &#8220;thica&#8221; created in step 4 and clicked &#8220;Import&#8221;. In the new screen, I browsed to the SQL dump file (of course you will need to extract it if it&#8217;s gzipped), and clicked &#8220;Go&#8221; button. In a matter of seconds (actually it depends on your database size) phpMyAdmin will transfer the data and I&#8217;ll have an exact copy on my local machine.</p><p><a
href="/wp-content/uploads/2009/01/phpmyadmin-import.gif"><img
class="shot" src="/wp-content/uploads/2009/01/phpmyadmin-import.gif" alt="Importing data database" width="450" /></a></p><h4>Step 7: Some configurations</h4><p>Now for the development version to be able to connect to and query the local MySQL database, we&#8217;ll have to configurate a bit. Open the file wp-config.php in your local wordpress folder (we&#8217;re talking about my site, then it&#8217;s E:\xampp\xampp\htdocs\thica.net) with any plain text editor and locate some lines similar to these:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remote-mysql-username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Your MySQL username</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remote-mysql-password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ...and password</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// ...and the server MySQL is running on</span></pre></td></tr></table></div><p>Change these variables into the local values which can be set in http://localhost/security/xamppsecurity.php. In my case, it is:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'root'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// Your MySQL username</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ...and password</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// ...and the server MySQL is running on</span></pre></td></tr></table></div><p>Then I saved the file.</p><h4>Step 8: Creating a virtual host</h4><p>Next I decided to create a virtual host instead of using the dumb and inconvenient http://localhost/thica.net url. It&#8217;s never been that easy with XAMPP <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>First I opened the file httpd-vhosts.conf in E:\xampp\xampp\apache\conf\extra folder with Notepad++ and added these lines at the very bottom:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;">NameVirtualHost thica.dev:80
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VirtualHost</span> thica.dev:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
ServerName www.thica.dev
ServerAlias thica.dev
DocumentRoot &quot;E:\xampp\xampp\htdocs\thica.net&quot;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><p>This will instruct Apache to create a virtual host that we can access at the url www.thica.dev, with the content served from E:\xampp\xampp\htdocs\thica.net folder.</p><p>Next I opened the &#8220;host&#8221; file (no extension!) in C:\WINDOWS\system32\drivers\etc and added this line:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;">127.0.0.1	thica.dev www.thica.dev</pre></td></tr></table></div><p>Then at the XAMPP Control Panel, I restarted Apache by stopping and starting it. The virtual host is ready <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><h4>Step 9: Final touches</h4><p>With the files already in place and the database ready to server, I accessed www.thica.dev in my browser. But how strange&#8230; instead of the local development site, I was redirected to http://www.thica.net. It turned out that WordPress had some settings that takes effect in this here:</p><p><a
href="/wp-content/uploads/2009/01/option-siteurl.gif"><img
class="shot" src="/wp-content/uploads/2009/01/option-siteurl.gif" alt="SiteURL Option" width="450" /></a></p><p>and here</p><p><a
href="/wp-content/uploads/2009/01/option-home.gif"><img
class="shot" src="/wp-content/uploads/2009/01/option-home.gif" alt="Home Option" width="450" /></a></p><p>So, using phpMyAdmin, I changed both values into http://www.thica.dev. Now pointing my browser to www.thica.dev works!</p><p>But wait&#8230; I&#8217;m a perfectionist, and I want more. There is a FireFox addon called <a
href="https://addons.mozilla.org/firefox/addon/2409">Server Switcher</a> which helps us switch between the Live and Development versions with just one click. Yes, it may sound small, but it certainly comes in handy. So if you want it perfect, install this little plugin.</p><h4>Step 10: Enjoy</h4><p>Now everything should be in working order. Is there anything else, or am I missing anything here? Please leave your comment <img
src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> <img
style='display:none' id="post-190-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/01/setup-a-development-version-of-wordpress/',title:'Setup a development version of WordPress',tweet:'Being a WordPress user, there&#8217;re certainly times when you want to try something new with your ',description:'Being a WordPress user, there&#8217;re certainly times when you want to try something new with your '})"><script type='text/javascript'>document.getElementById("post-190-blankimage").onload();</script>]]></content:encoded> <wfw:commentRss>http://www.phoenixheart.net/2009/01/setup-a-development-version-of-wordpress/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 5/11 queries in 0.016 seconds using disk

Served from: www.phoenixheart.net @ 2010-09-09 08:19:51 -->