How to Optimize a Magento Installation

I recently had to install a website powered by Magento and perform some optimizations. Being kind of new in the subject, there was much to learn, so I documented the process. After all the changes, we could see our server respond around 320% faster than before, and I’m sure there’s still some more things we could do to further increase performance.

1- Installing eAccelerator

eAccelerator is a PHP accelerator and optimizer. It caches the PHP code in it’s compiled state in order to reduce the overhead produced by compilations. Normally it will increase the page loading speed between 1 to 10 times, and Magento is no exception: in our case, we halved the response time. To install eAccelerator (make sure you’re downloading the latest version):

yum groupinstall 'Development Tools'
cd /mnt
wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2
tar -xjvf eaccelerator-0.9.6.tar.bz2
cd eaccelerator-0.9.6
phpize
./configure
make
make install
vi /etc/php.d/eaccelerator.ini
Type this into the new file:
extension="eaccelerator.so"
eaccelerator.shm_size="0"
eaccelerator.cache_dir="/var/cache/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

Save the file and return to the terminal.

mkdir -p /var/cache/eaccelerator
chmod 0777 /var/cache/eaccelerator
service httpd restart

If when trying to access the front-end or the back-end you get an error saying you should only pass variables by reference, then:

Open /var/www/html/lib/Zend/Db/Select.php and change line 216 to the following:

$arrayKeys = array_keys($this->_parts[self::FROM]);
$correlationName = current($arrayKeys);

Open /var/www/html/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php and change line 353 to:

$arrayKeys = array_keys($this->_availableMode);
return current($arrayKeys);

Continue to the next page to see how to configure the MySQL and Apache services.

Leave a Reply