Thursday, September 6, 2012


XCache is awesome, at least for joomla. I've configured memcached on some high trafficed joomla sites but it didn't work well, even I saw some slowness.
Then I let the xcache to make a chance and it did ! I've seen reduce of load average and increase the speed of page loading using xcache.

Here's how configure xcache 2.x on centos 6.x.
Don't forget to :
- set a password for xcache-admin
- check the right module path in xcache.ini (zend_extension=/usr/lib/php/modules/xcache.so or zend_extension=/usr/lib64/php/modules/xcache.so)



yum install php-devel -y
cd /usr/src
wget http://xcache.lighttpd.net/pub/Releases/2.0.1/xcache-2.0.1.tar.gz
tar -zxf xcache-2.0.1.tar.gz
cd xcache-2.0.1
phpize --clean && phpize
./configure --enable-xcache --enable-xcache-optimizer
chown -R nobody /usr/src/xcache-2.0.1
sudo -u nobody make
make install
echo -e "[xcache-common]" > /etc/php.d/xcache.ini
echo -e "zend_extension=/usr/lib64/php/modules/xcache.so" >> /etc/php.d/xcache.ini
echo -e "[xcache.admin]" >> /etc/php.d/xcache.ini
echo -e "xcache.admin.enable_auth = Off" >> /etc/php.d/xcache.ini
echo -e "[xcache]" >> /etc/php.d/xcache.ini
echo -e "xcache.shm_scheme =        \"mmap\"" >> /etc/php.d/xcache.ini
echo -e "xcache.size  =               64M" >> /etc/php.d/xcache.ini
echo -e "xcache.count =                 1" >> /etc/php.d/xcache.ini
echo -e "xcache.slots =                8K" >> /etc/php.d/xcache.ini
echo -e "xcache.ttl   =                 0" >> /etc/php.d/xcache.ini
echo -e "xcache.gc_interval =           0" >> /etc/php.d/xcache.ini
echo -e "xcache.var_size  =            32M" >> /etc/php.d/xcache.ini
echo -e "xcache.var_count =             1" >> /etc/php.d/xcache.ini
echo -e "xcache.var_slots =            8K" >> /etc/php.d/xcache.ini
echo -e "xcache.var_ttl   =             0" >> /etc/php.d/xcache.ini
echo -e "xcache.var_maxttl   =          0" >> /etc/php.d/xcache.ini
echo -e "xcache.var_gc_interval =     300" >> /etc/php.d/xcache.ini
echo -e "xcache.readonly_protection = Off" >> /etc/php.d/xcache.ini
echo -e "xcache.mmap_path =    \"/dev/zero\"" >> /etc/php.d/xcache.ini
echo -e "xcache.coredump_directory =   \"\"" >> /etc/php.d/xcache.ini
echo -e "xcache.experimental =        Off" >> /etc/php.d/xcache.ini
echo -e "xcache.cacher =               On" >> /etc/php.d/xcache.ini
echo -e "xcache.stat   =               On" >> /etc/php.d/xcache.ini
echo -e "xcache.optimizer =           On" >> /etc/php.d/xcache.ini
echo -e "[xcache.coverager]" >> /etc/php.d/xcache.ini
echo -e "xcache.coverager =          Off" >> /etc/php.d/xcache.ini
echo -e "xcache.coveragedump_directory = \"\"" >> /etc/php.d/xcache.ini

# Check the admin page : http://localhost/xcache-admin/index.php
cp admin /var/www/xcache-admin -R



Tuesday, September 4, 2012

[Tutorial] How optimize images JPG/PNG/GIF on Linux using littleutils package centos 7.x

Littleutils package contains couple of little utils useful for production websites.
I've used the opt-png, opt-jpg, opt-gif to reduce and optimize the size of images on some high trafficed websites without any quality loss.

# Install pngcrush :
cd /usr/src
wget https://sourceforge.net/projects/pmt/files/pngcrush/1.8.10/pngcrush-1.8.10.tar.gz
tar -zxf pngcrush-1.8.10.tar.gz
cd pngcrush-1.8.10
chown -R nobody /usr/src/pngcrush-1.8.10
sudo -u nobody make
cp pngcrush /usr/local/bin

On CentOS 7 you can use : yum install pngcrush

yum install libpng-devel gifsicle lzip libjpeg-turbo-utils lzma imlib2-devel zlib-devel 
cd /usr/src
wget http://downloads.sourceforge.net/project/littleutils/littleutils-source/1.0.39/littleutils-1.0.39.tar.bz2
tar -jxf littleutils-1.0.39.tar.bz2
cd littleutils-1.0.39
./configure
chown -R nobody /usr/src/littleutils-1.0.39

sudo -u nobody make
make install
make install-extra


The following script first backup all images in the /home folder, then optimize each one :


#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
cd /home;
NOW=$(date +"%d-%m-%Y");
echo -e "Backup images ...\nBackup file : ./backup-pictures-$NOW.tar";
`find . -regextype posix-extended -iregex "(.*?)\.(gif|jpe?g|png)" -print | tar -cf backup-pictures-$NOW.tar -T -`;
echo "" > log;
echo -e "Backup size is :";
echo `du -hs ./backup-pictures-$NOW.tar`;
echo -e "\nStart optimizing images ...\nLog file: ./log"
pics=`find . -regextype posix-extended -iregex "(.*?)\.(gif|jpe?g|png)"`;
for pic in $pics; do
        type=`file "$pic" | awk '{print $2}' | tr '[:upper:]' '[:lower:]'`;
        case $type in
                        "gif" )
                                        opt-gif "$pic" >> log
                                        ;;
                        "png" )
                                        opt-png "$pic" >> log
                                        ;;
                        "jpeg" )
                                        opt-jpg "$pic" >> log
                                        ;;

                        *)
                                        echo -e "file $pic which has type $type is undefined" >> log

                                        ;;
        esac
done
IFS=$SAVEIFS

How to disable Debian 12 sleep on production servers

 Debian 12 has power saver enabled by default which causes your server to go to sleep if there is no mouse / keyboard interaction. To resolv...