How to duplicate database record in Yii with 1 line

Well this will be quick since Yii is so powerful in their active record implementation. In Yii, if you ever want to duplicate a database record, all you have to do is to issue the following line.

$model = $this->loadModel($id); // record that we want to duplicate
$mode->id = null;
$model->isNewRecord = true;
if($model->save()){
//duplicated
}

The above implementation is pretty straight forward, we load the database record into a variable called model and set its primary key to null. Next, we set the variable isNewReocord to true and save the model. Once the model is saved, you will get yourself a new duplicated data where the Id is different from the one you just loaded. (well, there's more than 1 line but the key word to this is isNewRecord =x)

How to enable gzip on your cpanel shared hosting

I've explained how to install memcache, htmltidy and csstidy on your centos machine. However,  the most important thing that every webmaster should know and enable would be your gzip. By default, cpanel did not enable gzip for you. You will have to access your cpanel to enable gzip yourself. This can significantly increase your website speed and its a must to do list if you are a webmaster. In order to enable your gzip, you will have to access your cpanel. Once you are in your cpanel, find the following icon.

and click on the following option.

And click update. It is that simple to enable gzip for your shared hosting and speed up your website!

 

Installing CSS Tidy For WordPress W3 Total Cache Plugin

In my previous two article where i explain how to install Memcache and HTML Tidy for WordPress W3 Total Cache plugin, i forgotten about CSS tidy as shown below,

CSS Tidy allows the server to minimize your CSS without you doing it yourself. However, this largely depend on whether your web hosting provider had installed it for you. Nonetheless,  it is a great additional for every webmaster to have!

Installing CSS Tidy For WordPress W3 Total Cache Plugin

Installing CSSTidy is quite simple on a centos linux machine. All you have to do is to issue the following command.

yum install -y csstidy.x86_64

If its successfully installed, it would really be that simple. However, if you can't find this option, it will be time to do some work.

Installing CSS Tidy alternative

Since the simple step wasn't there for you, we will have to try something manual. Fire up the below command,

rpm -ivh http://download.fedora.redhat.com/pub/epel/5/x86_64/csstidy-1.4-1.el5.x86_64.rpm

and see whether it went successful. If it does, csstidy is installed. If it doesn't try download it and rpm again.

wget http://download.fedora.redhat.com/pub/epel/5/x86_64/csstidy-1.4-1.el5.x86_64.rpm
rpm -ivh csstidy-1.4-1.el5.x86_64.rpm

If it still doesn't work, you should find it on your yum using the following command.

yum install -y csstidy.x86_64

since the rpm was added into your repo. Hope it works 🙂

Installing HTML Tidy For WordPress W3 Total Cache Plugin

In my previous article where i explain how to install memcache on my centos server to use on WordPress W3 Total Cache plugin. The next thing we will want to have on our W3 total cache plugin would be to optimize our html code. In WordPress W3 total cache plugin, it allows us to do that with Html tidy. Html tidy comes with PHP 5.2 and above. However, not all web hosting will provide you with this. If they do not, simply ask them to install it for you so that you can speed up your website for better seo score!

Installling HTML Tidy on Linux Centos

In order to install this on a centos merchant is pretty simple, all you have to do is issue the following command on your linux machine.

yum install -y php-tidy

if you can't find this, simply issue the following command to search for all tidy component in yum.

yum search tidy

the results shown will be the one you want to yum install it.

Installing HTML Tidy on cPanel Server

Well, in order to install html tidy, you can't simply use the command above as it will not work since cpanel blocks certain repo away. You can go to issue in following command and remove the link "exclude".

vi /etc/yum.conf

removing the exclude link will open up the repo that cpanel do not want you to have. However, this will not work. Like i said, html tidy comes with php 5.2 and above. This means that cPanel has disable this functionality and we all know that cPanel uses easyapache to install and configure our webserver in our linux machine. Hence, you should login to your cpanel account and visit easyapache as shown below,

click on EasyApache and Start customize until you see the button "exhaustive options list" as shown below,

click on it and search for the tidy as shown below,

tick on it and click on rebuild. Wait until its done and you will have the option HTML Tidy on your W3 total cache plugin for either you or your client. Once it is installed, you should head down to the option Minify as shown below

and start configure your html tidy 🙂

 

Installing Memcache For WordPress W3 Total Cache Plugin

Today is a very distracted day. I was busy programming until i lose interest and read up google seo blog. There was this article about google page speed that suddenly makes me feel like speeding up all my website just for some seo benefits. The number one thing i notice about speeding up my website are surrounding caching. Hence, i digged down to my WordPress cache plugin W3 total cache and start exploring him a bit (after 10 months). However i was in a shared environment so the only option other than disk caching would be to install memcache on the server (quite some resources for some speed gain). But it does the trick. My server was using Centos 5.6 with cPanel installed.

Installing Memcache on WordPress Server

Follow the below sequence to get memcache install on your server.

#install require library
yum install libevent libevent-devel
#download the latest memcached. take note i'm downloading version 1.4.6
cd /usr/local/src && wget http://memcached.googlecode.com/files/memcached-1.4.6.tar.gz && tar -xzf memcached-1.4.6.tar.gz && cd memcached-1.4.6
#install it and compile
./configure && make && make install
# make sure memcache starts on boot
touch /etc/init.d/memcached
echo '#!/bin/sh -e' >> /etc/init.d/memcached
echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u nobody -l localhost' >> /etc/init.d/memcached
chmod u+x /etc/init.d/memcached
echo '/etc/init.d/memcached' >> /etc/rc.local
# start memcached
/etc/init.d/memcached
# install memcache
pecl install memcache
# restart apache
/etc/init.d/httpd restart
# test whether we get memcahce
php -r 'phpinfo();' | grep 'memcache'

Upon completing the above steps, you should get yourself the option in W3 total cache plugin to use memcache as an option to use as a cache mechanism.