Linux

Symfony2 and SQLite3 or PDO_SQLite extension error

If you are getting  

You need to enable either the SQLite3 or PDO_SQLite extension for the profiler to run properly

To resolved it install the php5-sqlite

sudo apt-get install php5-sqlite
#restart the apache
sudo /etc/init.d/apache2 restart

Installing Nodejs, NPM and Google V8 on UBUNTU

A) Install the essential compilers, packages and Google V8
sudo apt-get update
sudo apt-get install build-essential curl openssl libv8-2.0.3
B) Download and install the Nodejs from source
wget http://nodejs.org/dist/node-v0.4.11.tar.gz
gunzip node-v0.4.11.tar.gz
tar -xf node-v0.4.11.tar

cd  node-v0.4.11
./configure
make
make install
C) Installing the NPM
curl http://npmjs.org/install.sh | sh
Here is the lazy script to get things installed smoothly in your UBUNTU machine.

URL rewriting and add www to .htaccess for hosting multiple domain or multi sites

Adding the www to URL in .htaccess for hosting multiple domain or multisites and handle www issue for canonical URLs.
    ##Adding the www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
    RewriteRule ^(.*)$ "http://www.%1/$1" [L,R=301]

The other way around you can removing the www from URL.

Remove www and rewrite URL for multi-sites or subdomains in .htaccess

If you are running a Multisites or Subdomains sites this .htaccess RewriteRule code might come in handy specially for purpose of SEO. You can clean up your URL from http://www.yourdomain.com to http://yourdomain.com and remove the “www” with 301 redirect to non-www.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

If you want to add the www to URLs check this out.

Convert Linux/Unix timestamp to human readable format in PHP

This functin will help to convert the Linux/Unix timestamp to human readable format:

function unix_timestamp_to_human ($timestamp = "", $format = 'D d M Y - H:i:s')
{
    if (empty($timestamp) || ! is_numeric($timestamp)) $timestamp = time();
    return ($timestamp) ? date($format, $timestamp) : date($format, $timestamp);
}

$unix_time = "1251208071";

echo unix_timestamp_to_human($unix_time); //Return: Tue 25 Aug 2009 - 14:47:51