How to configure nginx to run Kohana on Ubuntu

As a web developer I’ve been using Apache for a long long time. Recently though, I’ve started to move away from Apache in favor of nginx (pronounced “engine-X”). It’s not that I really need its strength, it’s just that I wanted to learn something new to break my box.

It’s fairly simple to set up and get nginx running with FastCGI and MySQL on Ubuntu – a very well-written tutorial can be read on HowtoForge, 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 Kohana-powered site, with virtual host and rewriting and such. If you’re not familiar with Kohana, take a look at my article here.

The prerequisites

  • I have my Kohana-power site located under /home/phoenixheart/www/my-kohana/ directory with proper permission set (owner being www-data, that is).
  • nginx has been set up properly and listening on port 80, with the configuration directory being /etc/nginx/
  • 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 – which is also called “force non-www”.
  • I want to have neat URL rewriting without “index.php”, for example index.php?controller=product&function=get&id=1 should be rewritten into /product/get/1
  • I also want that all existing files and directories under the root directory are accessible, except Kohana’s system directories system, application, and modules. Any attempt to access system files and directories(beginning with dots, like .htaccess or .settings) should be disallowed also.

All clear. So let’s do it!
Read more »

Social Sketches – a free icon set released for Six Revisions

Social Sketches – a free icon set released for Six Revisions

Today I’m so pleased to announce the release of Social Sketches, my hand-drawn icon set exclusively done for Six Revisions. Initially it was made for Referrer Detector on my just-started sketch project The Daily Faces, but then I decided to make it available for public use, hence the featuring on Six Revisions yesterday.

Here is the preview of the set:

For more information and download, please head to Six Revisions’ post.

P.S. I have a plan to add some more icons into the set, so stay tuned ;)

New domain hack idea

Today, I happened to visit The Daily Monster. It’s a very cool site, I highly recommend you guys to visit it.

This post is not about Stefan and his monsters however, but about some domain hack ideas that I’ve just come up with today. In case you’re not familiar with the term, Wikipedia has a clear definition for domain hack:

A domain hack (sometimes known as a domain name hack) is an unconventional domain name that combines domain levels, especially the top-level domain (TLD), to spell out the full “name” or title of the domain. Well-known examples include blo.gs, del.icio.us, and cr.yp.to.

So upon visiting The Daily Monster, I was quite surprise to see it didn’t have its own domain name. I was expecting something like thedailymoster.com or dailymonster.com or dailymonsters.com or so, but it turned out that the url was a Typepad subdomain, not a standalone. I totally believe that content is King, but a good domain name in this case would be the crown. I was telling myself “Maybe the domains had been purchased by other guys” and I was right – none of them are available.

Then, I thought based on this “one design a day” concept I’d do a similar site on my own. “Daily face”, how is that? A drawing of a face each day. I used to sketch a lot, sometimes with pencil, sometimes with the computer mouse, like this one:

One of my sketches Read more »

WordPress: Thank that first time commentator!

WordPress: Thank that first time commentator!

Thumbnail credit: Premshree Pillai

To a website, comments are important – this you must agree. But not all visitors leave comments – in fact, very, very few. Most of them care about the content only, and tend to leave (bounce) the site right after getting the information they need (so sad a life, huh?)

Many tips have been introduced and used to encourage visitors to contribute to your site via comments. To my knowledge, and to name a few:

  • Use dofollow links in comments. By default, WordPress and other blogging systems mark links in comments with rel="nofollow" attribute. This attribute tells search engines to not follow the links, which means the commenter’s site will not be able to share any Google juice with you. While effective in fighting spammers, this technique may a bit disappoint the real visitors. Plugins like Dofollow address this problem and remove “nofollow” attribute from comment links.
  • Further promote the commenter’s blog (if any). CommentLuv is a plugin that “will visit the site of the comment author while they type their comment and retrieve a selection of their last blog posts, tweets or digg submissions which they can choose one from to include at the bottom of their comment when they click submit”.
  • Choose a (random) comment to give small prizes such as free ebooks, preminum themes etc.
  • Explicitly ask the readers to give comments at the end of the article – “Please share your thoughts”, “What do you think?”, “What say you?” etc. etc.

Today I would like to mention another method to encourage commenting. Though this won’t likely attract more commenters, it may encourage existing ones to leave more comments and become more effective contributors.

The method is called “Thank first time commenters” and it works like this: Read more »

How I sped up my Thica.net

How I sped up my Thica.net

Thumbnail credit: Amnemona

If you didn’t notice, I have another site called Thica.net – Vietnam poetry network, a WordPress (what else) powered blog dedicated to poems in Vietnamese. The site is receiving about 60K of views per month, which is 12x to that of the moment when it was started back on March 2008, and I’m rather happy about it.

About one month ago, Thica.net started to become very slow and tent to produce strange problems. More than often it threw 503 Internal Server Error just when I attempt to add a new post, or 404 Page Not Found for a page that I knew it was there, such as admin panel, plugin section etc. After some deep look inside, I decided that my site was too bloated and then it was time to optimize things to start it up. To admit, the result is nowhere near perfection, but it satisfies my need. So I think I’ll share with you here.

1. Eliminate unused plugins

Plugins
Original image by smackfu

Being a developer, I’m a big fan of plugins and addons. My Firefox has about 30 addons, ranging from Adblock Plus to UltraSurf (I’m living in a communist country FYI) and YSlow. Similarly, Thica.net had like 50 plugins, active and inactive alike. So you know, plugins power up WordPress in many ways, but on the downside slow it down because of all the added functions, hooks, data and so on. Some plugins are even terribly written (like one random post plugin which gets ALL posts from the database and uses PHP loop to get 5 random posts – WTH) and may cause serious problems: slowness, security holes, or even crashes your site. Read more »

Code Snippet 3 – Create post slugs

Code Snippet 3 – Create post slugs

If you’re used to WordPress, you must have noticed that usually a blog doesn’t use the default permalink structure (like http://site.com/?p=43, where 43 is the post ID store in the database). Instead, almost all blog owners tend to use the built-in option form to set the permalinks to something similar to http://site.com/a-great-post and leave the rest to Apache’s mod_rewrite to handle. In this case, a-great-post is called a post slug, or to be short, a slug. According to WordPress Codex:

A slug is a few words that describe a post or a page. Slugs are usually a URL friendly version of the post title (which has been automatically generated by WordPress), but a slug can be anything you like. Slugs are meant to be used with permalinks as they help describe what the content at the URL is.

In case you are wondering, slugs play a really, really important part in SEO. This is due to the fact that search engines like Google analyze an URL, and if it is relevant to the page’s content, the page’s rank point may be increased. Just like to us human, ?p=43 doesn’t tell anything, but how-to-create-post-slugs surely does.

So how is a slug generated? Read more »

Here we go – CDN Rewrites

Right after Free CDN was released, I got a request to enhance the plugin to support commercial Content Delivery Networks – you know, those big guys like Akamai, Limelight, EdgeCast, Velocix etc. The implementation is not too complicated: specify an origin host, and rewrite it into a destination host. That origin is of course usually http://www.a-busy-site.com, and the destination is something a Content Delivery Network would provide you with: http://static.a-busy-site.com, or http://images.a-busy-site.com, or http://a-static-host.com etc. This way, all static contents will be served from that CDN host.

So, instead of developing the enhancement as a new feature for Free CDN, I decided to create a new plugin called CDN Rewrites. Read more »

First version of Free CDN WP plugin released!

First version of Free CDN WP plugin released!

Office life has its advantages and disadvantages. On one hand, it keeps me so exhausted and leaves me so little free time for other hobbies – I’m talking about my books, my December Flower guitar self-training, my photographic stuffs etc. On the other hand, it does improve my knowledge and skills with all those working requirements.

I’m rather lucky to be working as an R&D guy in my current company, thus got a (legal) chance to (legally) spare a lot of time for (sometimes illegal) new and cool stuffs. Among them is CDN, a solution to distribute (mostly static) contents across a network and let end-user access their copies from the cloud instead of the central server itself, thus reduces bottle neck problems during peak hours. To enterprise websites like those of Microsoft, Yahoo, Amazon, eBay etc., this is vital, as the number of concurrent visitors and downloads very frequently exceeds millions. Some of them build their own CDN, when the others rather hire third party services to handle the load to save time and money. Most well known among these 3rd services are properly Akamai and Limelight, though there is a vast of them, naturally. For instance, Windows 7 downloads (~2GB each!) were served through Akamai network, when the live internet broadcast of Barrack Obama’s inaugural speech was done with help from Limelight. Read more »

Write your own URL shortener

With Twitter and its 140 characters limit leading all the trends, URL shortening services are in extremely high demand. We have seen TinyURL in the past, now Bit.ly, Is.gd, Tr.im and dozens of others are joining the party to share the cake. Honestly saying, to me they’re all the same (except for ➡.ws for its cool name). With that being said however, it is interesting how they are doing it out there – what mechanism / algorithm / buzzword-here?

I curiously did some “research”es (well, another buzzword), and it seems in order to create the shorten URLs they are following the same steps:

  1. Insert the original (long) URL into the database
  2. Get the insert ID. If the URL already exists, take its row ID. Let’s say we got 123456.
  3. Convert the ID 123456 into something even shorter, let’s say “am4k”
  4. Make use of Apache’s mod_rewrite so that any request to http://host.com/am4k will reach http://host.com/redir_script.php?code=am4k instead.
  5. In redir_script.php the value “am4k” is converted back into base10’s 123456 and the corresponding URL is queried back from database
  6. If a URL is found, redirect the request to it.

It is simple enough… except for step 3 and 4. Which conversion is there, and how is the .htaccess written? Read more »

Referrer Detector 4.2.0.1 (and the IE pain)

Referrer Detector 4.2.0.1 (and the IE pain)

On May 12 I managed to release the latest major version of Referrer Detector. As it was a complete rewritten, bugs are not a doubt expected. Since then, there has been 5 newer versions:

  • 4.0.1 – A hot fix to for allow_call_time_pass_reference problem. As for version 5, PHP passes function parameters by reference by default, thus eliminate the need of the prefix &. This shouldn’t be anything big, if it didn’t generate a warning with any attempt to use & and totally break my JavaScript’s eval().
  • 4.0.2 – Some other hot fixes.
  • 4.1.0 – “Related posts” feature implemented, and a tiny “Powered by Referrer Detector” line added into the welcome div. If you mind, both options can be turned off via Options panel – one-click. Also, the CSS was nearly completely changed.
  • 4.1.0.1 – I accidentally (and stupidly) uploaded some 4.0.2 code in place of 4.1.0, and EVERYTHING was broken. This version is actually a quick roll-back, so the features were exactly the same with 4.0.2 – oops.
  • 4.1.1 – This IS 4.1.0 :D

So today I would like to announce the release of Referrer Detector 4.2.0.1 (code name: IE-PAIN). For this version we have another option on how to display the welcome box – in light box style. This is not a joke: I saw the light box in action in my dream, and started to implement it right when I woke up, basing on SimpleModal. Mendeleev’s style, haha. Actually I’m not sure if this welcome style fits normal needs, but for advertisements it seems to. At least it has some cool effects. Read more »