Category Archives: Technical Stuffs

Changing VPS Timezone

One of many things that you probably do when managing a VPS is setting up date and time to match your local date and time. Here’s a quick guide to change your VPS’ timezone.

You can find your own timezone at /usr/share/zoneinfo/ and copy it to /etc/localtime. Here’s the magic spell:

[server]# cp /usr/share/zoneinfo/Asia/Jakarta /etc/localtime

Of course you have to change that Asia/Jakarta thing into your own timezone.

The date command output before I change its timezone:

[server]# date
Wed Apr  4 16:34:20 EDT 2012

And this is after:

[server]# date
Thu Apr  5 03:36:05 WIT 2012

Tic.. tac.. tic.. tac..

Update PHP on Virtualmin

I’m using Virtualmin to manage some servers (both physical or VPS) and I’m pretty confidence to say that this is the best freeware for server control panel.

Virtualmin currently provide PHP 5.1 (I’m using CentOS 5.5) and here’s how to upgrade its PHP version to 5.2. This command will activate Bleeding Edge Packages for CentOS/RHEL 5 on Virtualmin:

[root@server01 ~]# rpm -ivh http://software.virtualmin.com/bleed/centos/5/i386/virtualmin-bleed-release-1.0-1.rhel.noarch.rpm

After that, simply run following command to update PHP:

[root@server01 ~]# yum update php

And just answer “yes” when your system ask. Update process will just take a few seconds to complete.

Redirect Non-WWW to WWW using htaccess

I’m using this script very often, for some customers to redirect their website from domain.com to www.domain.com. So I will put it here for easy access.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Just create or insert above script into your .htaccess. When a visitor visits domain.com he will be forwarded to www.domain.com.

Piece of cake.

Problem in Moodle 1.9 and PHP 5.3

Today someone ask me to check his Moodle installation in his website. He used to add resource(s) easily in any course he made and lately he’s unable to add any resource. In the resource page, Moodle just displays blank page. No error message at all.

After googling around, I found that the problem is (likely) caused by PHP upgrade from 5.2.x to 5.3.x. And thanks to Andrey who posted a script for a quick hack.

The trick is by adding a new function inside HTML_QuickForm_element class in moodle/lib/pear/HTML/QuickForm/element.php.

< ?php
public function __call($name, $args) {
    $name = str_replace('MoodleQuickForm_', '', $name);
    if ($name == 'passwordunmask') {
        $name = 'password';
    }
    return call_user_func_array(array($this, 'HTML_QuickForm_'.$name), $args);
}
?>

It works like a magic!

Error 404 on Drupal Admin Section

My Drupal installation was fine until I uploaded it into my web hosting. It always returned error 404 page (not found) every time I clicked on any admin section (i.e http://domain.com/admin/build, http://domain.com/admin/settings, etc).

I have tried bypassing clean URLs by using http://domain.com/?q=admin, renamed .htaccess file and so on. But all of my efforts still bring me the same error page.

Huft..

After many minutes, I figured out that the problem was caused by the update module that always loaded every time I open admin section. Thus I decided to disable this module.

Just open PHPMyAdmin, click my database and run this query:

update system set status=0 where name='update'

And…… it works! All my admin sections are now working fine with this little trick.

Install Nginx, PHP-FPM & MySQL in Centos

Warning: This shell script will remove your previous Apache installation.

After reading a tutorial of how to install Nginx, PHP and MySQL in a difficult way, now I would like to tell ya how to install them in a very easy way.

I found this method was very effective and completed just within few minutes in my Centos VPS.

  1. Download  this shell script to your VPS
    [root@power ~]# wget http://freevps.us/downloads/nginx-centos.sh
  2. Run that bash script
    [root@power ~]# bash nginx-centos.sh

    then wait..

  3. Voila! Nginx, PHP-FPM and MySQL are installed at glance!

Not only that, this shell script also installed a tool to create virtual host in Nginx named setup-vhost.

When I made virtual host for this blog, I just need to run this command:

[root@power ~]# setup-vhost sandalian.com

Then I uploaded all my files at /var/www/sandalian.com and configure database connection etc.

Thanks to you guys at freevps.us, installing this stack never been easier than this!

Wrong mail quota in CPanel

Today I found my CPanel displays wrong disk quota for an email account. It shows 58/100 MB (58 MB used, of 100 MB preserved) while actually the mailbox is empty.

I have checked with du -sh command (a command to check disk usage) and it returned 100 KB or something, so there must be something wrong.

After googling around, I got some trick to solve this problem. Perform this action from shell/SSH or simply using file manager in CPanel:

  1. Go to /home/usercpanel/mail/domain.com/emailaccount/.
  2. Delete file named maildirsize, this file stores disk usage information
  3. Change the number of disk quota for that email account from CPanel (inside menu Email Accounts), it will regenerate a new maildirsize file.

Refresh your browser and now you should see the correct disk quota for that email account.

Create PDF Files For Free

I was wondering why many people still using Adobe Acrobat for creating PDF files from their documents. It’s bloated –or you can say my computer is too old– and of course expensive! Some minutes ago I’ve checked the price on their website, it costs US$ 299.

Why don’t people find an alternative PDF-maker software which is free and lightweight? I know that you can get any serial number from Internet for Adobe Acrobat to turn that pricey software into a free one. But hey, it’s like stealing from a kid’s pocket.

A few days ago –when I needed a software to convert my documents into PDFs– I found doPDF which is free and lightweight. And most of all, it doesn’t require any Ghostscript installation just like any other PDF printers.

cap-0109

Perhaps it doesn’t have all the features you want and requires you to upgrade to the paid version but it’s enough for me. Awesome PDF printer.

This way I thank to doPDF developer(s) for their great work.

Redirect Old URLs to New URLs

When we have a completely new website and uses different CMS, there will be old URLs that already spread everywhere on the Net. Discarding old URLs is not an option because we will lost visitors from search engines. So we must redirect all old URLs into new URLs.

Using redirect in .htaccess is great, but when your old URLs contain question mark, most likely it will fail to redirect.

Following code will work:

redirect 301 /old-url.html http://domain.com/new-url.html
redirect 301 /very-old.html http://domain.com/very-new.html  

But following code will –at least in my case– failed:

redirect 301 /file.php?age=old http://domain.com/new-url.html
redirect 301 /file.php?age=old&id=12 http://domain.com/very-new.html  

Luckily there’s 404 directive from Apache using .htaccess. We can mix the power of custom 404 page with PHP to perform this directions stuff. Here’s how to mix them up:

Create custom 404 page using .htaccess

ErrorDocument 404 /redirect.php

Then create file redirect.php with following contents:

< ?php
$req = trim($_SERVER['REQUEST_URI']);
switch($req){
	case "/file.php?age=old":
		$goto = "http://domain.com/new-url.html";
	break;
	case "/file.php?age=old&id=12";
		$goto = "http://domain.com/im-very-new.html";
	break;
	default:
		$goto = "http://domain.com";
}
header ("HTTP/1.1 301 Moved Permanently");
header ("Location: $goto");
?>

By this method, old URLs that are no longer exist are forwarded to our custom 404 page (named redirect.php) and that redirect.php will bring visitors to new URLs.

Nice, isn’t it?

Error on Webmail, Query: SELECT “INBOX”

If you got following error message when accessing webmail using Squirrelmail or other brand:

Query: SELECT “INBOX”
Reason Given: Internal error occurred. Refer to server log for more information. [2009-11-03 15:47:40]

The cure is really easy. Check /home/user/mail/ and see its subdirectories’ permission.

In my case, I just need to perform chown command to assign the directories/files under user’s ownership and the problem is gone.