Speeding up Drupal 7 on Centos 6 with Memcache APC and some modules
This page is mainly a list of the commands and config file changes used in the tutorial, there are also some comments, but the main information can be seen in the tutorial which is on youtube at:
https://www.youtube.com/watch?v=DZk_MT19wq8
First you start off with a minimal install of Centos 6 and you should set up its networking, then update it. Next you should install the EPEL repository, then the services and extensions that are required by Drupal:
yum -y install epel-release
yum -y install httpd mysql-server php php-mysql php-pdo php-common php-cli php-gd php-mbstring php-dom p7zip libcgroup
If you have a fast machine then you can also limit the performance of apache so that the speed improvements are more obvious
/etc/cgconfig.conf
group limitcpu{
cpu {
cpu.cfs_quota_us = 100000;
cpu.cfs_period_us = 1000000;
}
}
/etc/sysconfig/httpd
CGROUP_DAEMON="cpu:/limitcpu"
Then you have to start the relevant cgroup services and restart apache
ntsysv
reboot && exit
Then run the mysql client and set up an empty database and user for Drupal:
create database drupal;
GRANT ALL PRIVILEGES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'password';
Download drupal and copy it to the webroot, then install the modules that match the Drupal database file that you can download below:
https://www.drupal.org/project/drupal
chown -R apache /var/www/html/sites/default
chown -R apache /var/www/html/sites/all/modules
https://www.drupal.org/project/ctools
https://www.drupal.org/project/views
https://www.drupal.org/project/devel
https://www.drupal.org/project/backup_migrate
I have prepared a backup file that has 100000 dummy content nodes and a view that displays them that you can download at the bottom of this page. You need all of the above modules because they were the ones that were installed when the backup was made. The login username for this backup is 'admin', with a password of 'password'.
You should now edit /etc/my.cnf and put in the below settings, then delete the log files in /var/lib/mysql and restart the mysqld service:
innodb_buffer_pool_size = 6G
innodb_flush_method = O_DIRECT
innodb_log_file_size = 256M
innodb_log_buffer_size = 4M
innodb_flush_log_at_trx_commit = 0
innodb_fast_shutdown = 0
If you want to test drupal with a slightly heavier theme then you can download this Zymphonies one:
https://www.drupal.org/project/parallax_zymphonies_theme
You can then open up another terminal and run this apache bench command to see how Drupal is currently performing:
ab -n 100 -c 10 http://drupal.localdomain/
You can then turn on Drupals caching and see how this has changed the apache bench results.
You can also now run the below command to see how slow the view is. It is best to run it now, because it would probably take too long if run before the database config was adjusted
ab -n 10 -c 10 http://drupal.localdomain/?q=test-view
Then you can install memcache with its php extensions and install the Drupal memcache module, along with the apc php cache extension, then see how the apache bench results have changed:
yum -y install memcached php-pecl-apc php-devel gcc automake autoconf libtool make zlib-devel
pecl install memcache-3.0.8
nano /etc/sysconfig/memcached
CACHESIZE="128"
OPTIONS="-s /var/run/memcached/memcached.sock -a 0766"
https://www.drupal.org/project/memcache
nano /var/www/html/sites/default/settings.php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['memcache_servers'] = array('unix:///var/run/memcached/memcached.sock' => 'default');
nano /etc/php.d/memcache.ini
extension=memcache.so
[memcache]
; Data will be transferred in chunks of this size
memcache.chunk_size = 32768
memcache.hash_strategy = consistent
memcache.default_port = 0
session.save_handler = memcache
session.save_path = "unix:///var/run/memcached/memcached.sock?persistent=1&weight=1&timeout=1&retry_interval=15"
nano /etc/php.d/apc.ini
extension=apc.so
apc.shm_size=128M
apc.stat=1
service memcached start
service httpd restart
Finally you can try out these other Drupal caching modules to see how they change the results that apache bench is giving:
https://www.drupal.org/project/httprl
https://www.drupal.org/project/advagg
When AdvAgg destroys your css, you then have to make sure that your clean urls are working, by editing the apache config
If you feel brave you can also try to enable the jsmin php module, which will then lead you into the below adventure:
pecl install jsmin
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
nano /etc/yum.repos.d/remi.repo
yum -y update php*
yum install php-pecl-memcache
pecl install jsmin
nano /etc/php.d/jsmin.ini
service httpd restart
yum install php-opcache
service httpd restart