Friday, 27 June 2014

Windows 7 Panning Desktop Applications

Friday, 20 June 2014

Page caching for Buddypress? Transients, memcached, vs others

Since Buddypress works on having users login, page caches software such W3 Total Cache, BP Super Cache, Nginx microcache, APC, Memcached, etc. won't work.

What would work is a partial page caching software. But there doesn't seem to be any such software now.

However, by using the wordpress transients API, one can manually code fragment or partial page caching.

Problems with transients:

Starting with Wordpress 3.7, transients are garbage collected, so the issues mentioned above may be fixed.

Enabling Opcache in PHP

Here are the commands that can be entered in php.ini for configuration of the opcache. There is also an explanation ofthe features.

Here are some Opcache GUI reporting tools:

Some configuration tips:

More detailed configuration tips:

Tuesday, 17 June 2014

Wordpress: Disable heartbeat

If wordpress is taking too much server resources, you can disable wordpress heartbeat. If you are using buddypress, disable "Activity auto-refresh" in Buddypress settings.

In the above page, you will find the code to disable heartbeat on all pages except post.php and post-new.php (here it is required for autosave while creating new posts and commenting).

To be added in functions.php

add_action( 'init', 'stop_heartbeat', 1 );

function stop_heartbeat() {
        global $pagenow;

        if ( $pagenow != 'post.php' && $pagenow != 'post-new.php' )

Nginx with CPanel

Cpxstack is a plugin to cPanel that completely replaces Apache with nginx (other plugins keeps apache and configure nginx as a reverse proxy).

To install cpxstack, you need Incron. For this you need to enable the EPEL repository (see previous article for this).

You also need to install php-devel. Cpanel prevents installing any php related packages through an "exclude" entry in yum.conf. Open yum.conf and remove "php*".

After upgrading to the latest stable PHP version, you should enable the Remi repository and the php55 remi repository. You can now install php-devel.

You can run the script as per instructions here:

For incron and php-devel you can alternatively directly run the script to see if it installs these packages automatically.

After the script has run, you should go to WHM, when you click on the cpxstack icon in the sidebar, it will ask you to change a setting in the Tweak Settings area.
You also need to go to cPanel and manually enable nginx for your site. Also in WHM change the default number of worker processes to a lower number (default is 15).

Nginx: Allow selected IP addresses only

  server {
    listen 80;

    location / {

      deny    all;
You can have multiple "allow" lines.

301 permanently moved redirect with PHP

The following php commands will do a 301 redirect when using PHP FPM 
header('Status: 301 Moved Permanently', true);
header('Location: ' . $url); // or header('Location: ' . $url, true, 301); 

Nginx configuration for Wordpress

For wordpress pretty permalinks to work, you need to add this to your nginx.conf file where the wordpress directory is /wordpress:

location /wordpress {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;

Nginx configuration for Moodle

If the moodle directory is /moodle then put this in the configuration file nginx.conf or the appropriate file under the nginx.include.d folder:

server {
     rewrite ^/moodle/(.*\.php)(/)(.*)$ /moodle/$1?file=/$3 last;
In the same file, in the php section:
  location ~ \.php$ {
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
Putting the same rewrite rule in the location /moodle section does not work.
If you are using the cpXstack plugin for cPanel, make sure you follow this:
For any domain that has nginX+PHP-FPM enabled, additional nginX configuration can be added by the root user at
/opt/pifpm/nginx.include.d/<DOMAINNAME>.autoinclude where DOMAINNAME is the domain .
Changes made any where else may not be preserved during server shut down. 

Monday, 16 June 2014

cPanel: Install php-devel

CPanel disables installation of php related packages using yum. To enable it:

nano /etc/yum.conf

Remove php* from the "exclude" line.

EPEL repositories for Fedora and Cent OS

Certain applications such as incron can't be found in the default repositories of Cent OS. To get this software, you need to enable the EPEL (Extra Packages for Enterprise Linux) repository: