Installing mod_pagespeed into cpanel/whm in centos

Here is another exciting thing that google has release and i really wish to document this down so that i could reuse it on all of my servers since i can see a good amount of optimization done on the server by mod_pagespeed. Anyway without anymore bull crap, i shall starts.

Firstly, you might want to visit mod_pagespeed download page and standby for the time being. And my machine is a 64bit machine so if you are running on 32bit just remove all the '64' you see in the instruction. eg. "lib64"

Firstly login into your server as "root" and start firing the below commands,

cd /usr/local/src
mkdir mod_pagespeed
cd mod_pagespeed
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
rpm2cpio mod-pagespeed-stable_current_x86_64.rpm | cpio -idmv
cp /usr/local/src/mod_pagespeed/usr/lib64/httpd/modules/mod_pagespeed.so /usr/local/apache/modules/
cp /usr/local/src/mod_pagespeed/etc/httpd/conf.d/pagespeed.conf /usr/local/apache/conf/
chmod 755 /usr/local/apache/modules/mod_pagespeed.so
mkdir /var/mod_pagespeed/{cache,files} -p
chown nobody:nobody /var/mod_pagespeed/*

mod_pagespeed has a dependency that you'll want to enable: mod_deflate (the httpd source directory (httpd-2.2.21) may vary depending on your install):

/usr/local/apache/bin/apxs -c -i /home/cpeasyapache/src/httpd-2.2.21/modules/filters/mod_deflate.c

After that, we'll have to edit the mod_pagespeed configuration file located at /usr/local/apache/conf/pagespeed.conf to reflect the correct paths, the LoadModule directives should fetch the modules in "modules/module_name.so":

LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed.so
LoadModule deflate_module /usr/local/apache/modules/mod_deflate.so
ModPagespeedFileCachePath            "/var/mod_pagespeed/cache/"
ModPagespeedGeneratedFilePrefix      "/var/mod_pagespeed/files/"

And then open /usr/local/apache/conf/includes/pre_main_global.conf and add:

Include "/usr/local/apache/conf/pagespeed.conf"

Next restart apache

/scripts/buildhttpdconf
/etc/init.d/httpd restart

And we are done!

Yii CClientScript Disable RegisterScript

I though this might be useful since its not widely spread yet. There will be times when you want to disable some scripts on CClientScript so that your ajax or JSON will print properly. In this case, depending on what you want to disable, these methods might be helpful.

Disable JavaScript or CSS files in CClientScript

Well, you if want to disable JavaScript or CSS files that were included via registerCssFile or registerScriptFile you can fire the following code into your filer or anywhere your action is being fired

        $cs = Yii::app()->clientScript;
        $cs->scriptMap['jquery.js'] = false;
        $cs->scriptMap['bootstrap.min.css'] = false;
        $cs->scriptMap['bootstrap.min.js']  = false;
        $cs->scriptMap['bootstrap-yii.css'] = false;

scriptMap will disable the file mentioned (example jquery,js) and replace with 'false', this is similar to how you would go about optimizing js and css scripts on Yii as well 😉

Removing CSS or JavaScript code in CClientScript

this will be a little bit tougher than you would imagine since the array 'scripts' which suppose to be available isn't really 'public' but you can still remove the code via the following,

Yii::app()->clientScript->registerScript('mykey', "jQuery('{$selector}').{$name}({$options});");

basically, to remove the custom script i have wrote above, i will fire something like this

Yii::app()->clientScript->registerScript('mykey', false);

basically i am overwriting whatever i have registered and this will remove the custom script that i have written. Neat isn't it 😉

Remove every single custom scripts on CClientScript

if the above isn't what you were looking for, may be you are like me who manage to remove custom scripts using the above method but the script tags still appear, in this case, i fire the following code to stop my headache

        $cs = Yii::app()->clientScript;
        $cs->reset();

since we can't make 'hasScripts' to be false (which is the reason why the script tags still appear), we will reset all the calling scripts instead. but this won't always work as neat as you would want to but its a good solution so far.

Disable JavaScripts entirely on CClientScript

Well, its so irritating that i wanted everything to be disable on cclientscript, in this case, use the following,

        $cs = Yii::app()->clientScript;
        $cs->reset();
        $cs->enableJavaScript = false;

This will ensure everything is disabled.

This should be useful for people working on Ajax, restful and JSON implementation on Yii 😉

Disable Yii Log on Action Controller

Well, i found something interesting yesterday that might be useful for Yii developer when they deal with restful api or JSON output with Yii framework. Sometimes it is good to disable Log output in order to return proper JSON or restful api calls. In that case, you can try to do the following,

        foreach (Yii::app()->log->routes as $route)
        {   
                if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute)
                {   
                        $route->enabled = false;
                }   
        } 

However, if you still seeing your JSON or Restful api output being 'unclean', this is most likely caused by preload options on your config.php file. Preload will always run earlier than whatever you have defined in your action controller. In order to bypass this, the only way is to dive into these extensions and provide certain validation to prevent it from running unnecessary. Sometimes, you will see facebook api appending javascript and meta tag into your json call, in that case, you can add in a new 'enabled' property on your facebook extension and disabled upon your action controller initialization. You can place the following code below to shut up facebook entirely upon running your action controller method.

Yii::app()->facebook->enabled = false;

the enabled property have to be written by you as a new property on facebook extension class file. And the other condition to prevent certain method to run will also have to be written by you since Yii doesn't provide a more graceful method to disable output before preload or extensions that are not managed by them

Get WordPress Custom Post Taxonomy Categories and Tags

Here's another problem with WordPress post where you want to know whether a particular custom post has a particular taxonomy categories or tags. In a normal post cast, you will highly likely used either get_categories or get_terms but for custom post type you might need to use another method which is what i am using currently as well. In order to determine whether a post category or tag is used by your custom post type, try the following

$terms = wp_get_object_terms($post->ID, 'review_category');

The first parameter is obviously the post id but the second parameter here is actually the custom post type taxonomy which you can find on your custom post type 'categories' section (on the url). Once you have determine your taxonomy name, getting post taxonomy categories or tags should be a piece of cake.

Check Whether a page is using WordPress Custom Taxonomy Category

Well, today i faced a little problem on checking whether a page displaying on WordPress site is using a custom taxonomy post type. I need to determine whether that particular page is using a custom taxonomy post type and that particular page is using a particular custom taxonomy post category as well. In this case, i search a bit but couldn't find this answer easily which resulted me to write this in the case i need this in the future as well.

In order to find whether a particular page is a custom taxonomy category type, we test with the following sentence

 if(is_single()){
          } else if(is_tax('reviews', $term = 'Games')){
            $args = array( 'post_type' => 'reviews', 'showposts' => 72, 'tax_query' => array(
		array(
			'taxonomy' => 'review_category',
			'field' => 'slug',
			'terms' => 'games'
		)
            ) );
          }else if(is_tax('reviews', $term = 'Apps')){
            $args = array( 'post_type' => 'reviews', 'showposts' => 72, 'tax_query' => array(
		array(
			'taxonomy' => 'review_category',
			'field' => 'slug',
			'terms' => 'apps'
		)
            ) );
          }else
            $args = array( 'post_type' => 'reviews', 'showposts' => 72);

My custom taxonomy is 'reviews' and i wanted to check whether a particular page is type 'Apps' or 'Games', this way i am able to determine whether the particular page is using a custom taxonomy category which is different from using is_category which check post category.