Adding New VirtualHost in Apache2

On linux Ubuntu
1. If your apache has /etc/apache2/sites-available directory then just create a new file “”
with the following content:

DocumentRoot "/var/www/"

# Error handlers
ErrorDocument 500 /errordocs/500.html

AllowOverride All
Options -Indexes FollowSymLinks
Allow from all

2. Also copy the same file into /etc/apache2/sites-enabled

3. Restart your apache

$ /etc/init.d/apach2 restart

4. Edit your hosts file: /etc/hosts
add the following line to it

5. Open your web browser and open

If you are a windows user and are using xampp then you need to alter the vhost configuration file.
The default xampp file is in
Then restart your apache

Memcache test connection script

connect('', 11211) or die ("Could not connect");

// Add it to memcached server
$memcache->set('MyKey1', 'The value of My Key1 is me', false, 100);

echo $memcache->get('MyKey1');
// It will show you: The value of My Key1 is me

Redis connection test script

"host" => "",
"port" => 6379));
echo "Connected to Redis";
catch (Exception $e) {
echo "Unable to connect to Redis";
echo $e->getMessage();

$redis->set("var1", "The value for var1 is me");
echo $redis->get("var1");

// You can alos use exits() function to test if a variable exists or not
echo ($redis->exists("var2")) ? "true" : "false";

Learning Ontario G1 Test through IOS App

Several colleagues of mine produced an app for iPhones and iPad to help people study Ontario G1 driver license test.

This app can potentially boost your study in a very cost effective way at $1.99. Take a peak of the most common questions and answers during the exam.

Please see the detail link below for the “G1 Test Ontario Learner ONTARIO SAFETY LEAGUE (OSL) Driver’s Education” app by Radiant Design Studio

SVN Tricks in Linux

To show colorized svn diff

sudo aptitude install colordiff

Then on your home directory there is a hidden file called .bashrc.
Edit it.

vim ~/.bashrc

Append the following code at the end of the file

svn diff "${@}" | colordiff

Reload the .bashrc file:


Next to view the diff use svndiff instead of svn diff

Removing all .svn subfolders

rm -rf `find . -type d -name .svn`

SVN Revert All

svn st -q | awk '{print $2;}' | xargs svn revert

Introduction to Logging and Tracing in PHP

If you still tracing variable in php using print_r() or var_dump() then you’ll see them directly in the screen or the web page that you’re working on. This is easy to see, but also prone to problems:

  1. What if visitors see your error trace? Surely you don’t want that.
  2. What if you have a function call that relies on no string has been printed yet, e.g.: header(), ini_set(), these functions will fail and depending on your settings most likely when they fail they don’t show any sign of error.

Best way to do code tracing in PHP is to write the following code into your file – one of the early-executed file, such as config/header file, where you don’t have any output yet:

ini_set('error_log', '/var/wwwtmp/php.log');
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));

And at the part where you want to trace a certain variable

error_log(__FILE__.' ('.__LINE__.') '.__CLASS__.' :: '. __FUNCTION__ .' :: '. print_r($YOUR_VARIABLE_HERE,true));

By default apache2 and php will output their error in /var/log/apache2/error.log ,but after executing the ini_set above, the error log will be produced in /var/wwwtmp/php.log. And you need to make sure you that directory exists, if not use other directory that www-data has write access to. Why do we need to setup in a different location? Because the default file output doesn’t support showing new lines, you’ll see lot’s of \n. Thus make tracing hard to read.