Magento Optimised Template CentOS 6 with cpanel/whm V1.0 Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 1
Contents Introduction... 2 Objectives... 3 Web Server Optimisation... 5 Web Server & Caching Nginx & Varnish... 7 Database Optimisation... 9 PHP Optimisation... 11 Alternative PHP Cache (APC)... 12 Additional Optimisations... 15 IMPORTANT: If you have NOT purchased the Server Management add-on for your service, Technical Support cannot provide any assistance regarding the features, settings, modifications or changes offered in this guide. For more information please see: http://www.crucial.com.au/services/server-management Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 2
Introduction This template does not include an installation of Magento, it is purely an optimised operating system for your Magento installation to run on. Objectives The purpose of this template is to provide a range of performance based configuration options for your Magento installation. As you should be well aware, Magento is both highly resource intensive and highly configurable. Configurations will also vary wildly based on your available resources, your actual site and your actual traffic. Whilst we are attempting to lay the groundwork for a high-performance OS environment for your Magento install as a compliment to your SSD based Blaze Cloud VPS, please be aware that you will need to ensure you both understand the environment configuration and how to tune it in order to gain optimal performance for your Magento installation. Before You Start Please note that a temporary 192.168.x.x IP address has been specified in the default shared IP in WHM. Your first step should be to modify this to one of your assigned Blaze VPS IP addresses eg. your primary IP. You can modify this when you first login to WHM, on Step 3 of the cpanel Setup Wizard (Click Remove for the 192.160.x.x IP). Or after logging into WHM; WHM >> Server Configuration >> Basic cpanel & WHM Setup>> Basic Config >> The IP Address (only one address) that will be used for setting up shared IP virtual hosts >> Enter in your primary IP Address. If this is not set correctly, any cpanel account you create will be setup in the Apache httpd.conf with a non-existent private IP. This will cause numerous issues with Nginx. Updating Your Hostname Once you have updated your server hostname (during the cpanel Setup Wizard or manually), you will need to reboot to complete the change. This will also prevent any issues with MySQL. Updating cpanel/whm You may also wish to perform a cpanel update to ensure you re running the latest version. WHM >> Server Configuration >> Update Preferences >> Choose your Release Tier eg. Release >> Click Save >> Click Update Now Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 3
Or via command line run: # /scripts/upcp --force Starting ApacheBooster (Nginx+Varnish) Once you have created a cpanel account for your Magento installation and once DNS is pointing to the server if your domain is failing to load you should ensure Apachebooster is started correctly. Via command line run: # service apachebooster restart This service will restart the 3 underlying services and should return pid s for nginx, varnishd & httpd (apache) Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 4
Web Server Optimisation Apache Configuration Apache has been configured via EasyApache. A profile named magento-optimized with the values below has been saved which you can modify as required. Apache 2.2.24 PHP 5.3.26 -------- Asis AuthnDefault Deflate Env Expires ModFCGID (fastcgi support) Fileprotect Headers MPM Prefork Mod SuPHP Proxy Version -------- Bcmath CGI Calendar CurlSSL FTP GD Gettext Iconv Imap Mbregex Mbstring Mcrypt Mysql Mysql of the system Openssl PDO PDO MySQL POSIX Path Info Check Pear Phar SOAP SQLite3 Sockets Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 5
TTF(FreeType) Zip Zlib Additional Changes The following changes have been made to Apache via the WHM include editor, modifying the pre_main_global.conf include file with the following: KeepAlive On KeepAliveTimeout 2 KeepAlive allows multiple requests to be sent over the same TCP connection. You will need to make sure your Magento installation is making use of this feature. Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 6
Web Server & Caching Nginx & Varnish ApacheBooster v1.9 Nginx is a superior static web server to Apache. Varnish is a caching HTTP reverse proxy and allows you to cache PHP content and deliver it extremely fast. The two combined together results in an extremely high performance solution. As cpanel is installed with this template, getting Nginx and/or Varnish to work as web server requires a little more work than on a standalone OS. However, it is ready to go out of the box and greatly simplifies setup & configuration. There are several Nginx and/or Varnish plugin options for cpanel servers. Most have license fees ranging from $5-20/month or one-time fees. Most of these plugins are very well received and your license fee may include additional support features. If you have a particular preference or existing plugin license, certainly remove the plugin (see Uninstall step below) included in this template and install your plugin of choice. You can view a list of available Nginx and Varnish related plugins in the cpanel App catalog here: http://applications.cpanel.net/?s=nginx+varnish&cat=select+a+category&x=0&y=0 For this template we have chosen ApacheBooster as it has matured greatly over the last 1-2 years, is well regarded and is free! ApacheBooster integrates Nginx & Varnish to help reduce the server load and memory usage that would be present with just Apache. Note: as this is a free plugin, support is obviously limited, your system administrator should make sure they are familiar with Nginx, Varnish and troubleshooting operations of ApacheBooster eg. restarting services & changing config variables. URL: http://applications.cpanel.net/apachebooster-4/ Homepage: http://www.prajith.in/category/apachebooster/ Install (Already done) wget http://prajith.in/downloads/apachebooster.tar.gz tar -zxf apachebooster.tar.gz cd apachebooster sh install.sh Uninstall (if required) cd apachebooster sh uninstall.sh Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 7
Configuration ApacheBooster can be configured from WHM >> Plugins >> ApacheBooster IMPORTANT: ApacheBooster inserts Nginx as the default web server instead of Apache. This is done by moving Nginx to handle http traffic on port 80 and moving Apache to port 82. Port 8082 is also required while Varnish operates on port 6082. If you are running a firewall (strongly recommended) please make sure you enable port 82, 8082 and 6082 in your firewall configuration. From the ApacheBooster panel you can perform the following operations which are extremely simple & intuitive: Restart ApacheBooster (this will restart apache, nginx & varnish) Modify the Nginx & Varnish configuration Tune Varnish variables (such as the Memory Cache amount & Static & Dynamic File Cache TTL values) Purge Varnish cache Rebuild your Vhosts (This should be done after adding any cpanel accounts) Show Connection Stats Check for Upgrade Magento & Varnish: For easier management of Varnish from you Magento backend, we recommend installing the PageCache extension: http://www.magentocommerce.com/magento-connect/phoenix/extension/6322/varnish_cache Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 8
Database Optimisation MySQL Configuration innodb_file_per_table = 1 #innodb_buffer_pool_size = >50% of total RAM innodb_buffer_pool_size = 1G #innodb_thread_concurrency = 2 * [numberofcpus] + 2 innodb_thread_concurrency = 6 innodb_flush_log_at_trx_commit = 2 innodb_autoextend_increment=512 #thread_concurrency = [number of CPUs] * 3 thread_concurrency = 6 thread_cache_size = 32 table_cache = 1024 query_cache_size = 64M query_cache_limit = 2M join_buffer_size = 8M tmp_table_size = 256M key_buffer = 32M max_allowed_packet = 16M max_heap_table_size = 256M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 NOTE: these settings will depend greatly on your available resources and your Magento installation requirements. A perl MySQL tuner script is has been downloaded in the /root/ folder. You can run via command line: # perl mysqltuner.pl Additional MySQL Tuning Slow Query Log has been enabled in My.cnf slow_query_log = 1 slow_query_log_file = /var/lib/mysql/slow-query.log long_query_time=2 The purpose of the slow_query_log setting is to log any database queries that are over a certain, in this instance 2 seconds set by long_query_time=2 Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 9
Note: This does not mean all queries that appear in the slow-query.log file will be problematic, it merely logs slow results as a source for tracking down queries that are a potential performance drain. Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 10
PHP Optimisation PHP 5.3.26 has been specified (Note 5.4 is 20% faster than v5.3.x however current Magento compatibility may pose issues for some installations and not recommended just yet). Magento Required PHP extensions PDO_MySQL simplexml mcrypt hash GD DOM iconv curl SOAP (required for Webservices API) PHP.ini Recommended Settings memory_limit = 256M //256M as minimum 512M or higher preferred! safe_mode = Off log_errors = On output_buffering = On realpath_cache_size = 32k realpath_cache_ttl = 7200 max_execution_time = 30 //As low as possible requires testing under load max_input_time = 30 default_socket_timeout = 90 pdo_mysql.cache_size = 2000 output_buffering = On PHP Error Reporting Error reporting is set to E_ALL and display_errors turned Off by default. In development/testing set display_errors = On. This provides you with visual troubleshooting cues that you have PHP errors. In production set display_errors = Off. Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 11
Alternative PHP Cache (APC) APC caches PHP code and runs it from memory, thus drastically reducing overhead on each PHP request and thus the server response time and is an extremely easy to configure performance boost. As Varnish is configured via the ApacheBooster plugin, we have left APC enabled. However running both Varnish + APC may be redundant. Should you wish to disable APC all you need to do is modify the php.ini with apc.enabled = 0 (1 = enable). APC version 3.1.13 has been pre-installed. Installation has been done via WHM under the Module Installers section. WHM >> Software >> Module Installers >> PHP Pecl >> Manage extension=apc.so has been added in the php.ini along with following APC configuration variables: apc.enabled = 1 //enabled by default however Varnish is performing PHP caching under Apachebooster apc.optimization = 0 apc.shm_segments = 1 apc.shm_size = 256M apc.ttl = 7200 apc.user_ttl = 7200 apc.num_files_hint = 10000 Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 12
apc.user_entries_hint = 10000 apc.enable_cli = 1 apc.nmap_file_mask = /tmp/apc.xxxxxx apc.cache_by_default = 1 apc.max_file_size = 10M apc.include_once_override = 0 NOTE: In order to enable APC for your Magento install you must complete the following: 1) Copy the following file /usr/local/lib/php/apc.php to the root web directory of your Magento installation. 2) You must also specify a username and password by modifying this file 3) In order to use APC as the opcode cache storage for your Magento install you must modify your app/etc/local.xml file. For example: 1) cp /usr/local/lib/php/apc.php /home/<cpaneluser>/public_html/ 2) vi /home/<cpaneluser>/public_html/apc.php Edit lines 41 & 42 specifying ADMIN_USERNAME & ADMIN_PASSWORD Additionally you may: You can then load this file in a browser eg. http://domain.com/apc.php -- click on login and use the details you have set. 3) vi /home/<cpaneluser>/public_html/app/etc/local.xml Edit the file making sure the lines in bold are added. <global> <cache> <backend>apc</backend> <prefix>mgt_</prefix> </cache> </global> Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 13
Recommended Settings apc.enabled = 1 //enables apc apc.shm_size = 256M //this is the shared memory size for APC ie. The amount of memory dedicated to cache. Set as high as possible depending on your catalog single installation 128-256Mb. Consider allocating >1-2GB if you are using full page caching apc.enable_cli = 1 // allows cron processes to use the magento cache apc.ttl = 0 //used to auto clean the data cache. Fragmentation will grow as items expire setting to zero will prevent expiry. You will have to manually clear the cache on occasion should it become full or set higher value for apc.shm_size Monitoring & Fine Tuning You will need to utilise the apc.php file installed in your web root to monitor the opcode caching efficiency of APC and adjust accordingly. Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 14
Additional Optimisations Disk Optimisation Your Blaze Cloud VPS is already operating on all SSD Storage with blazing fast IO capabilities. This alone makes several Magento performance tweaks required for traditional SATA or SAS based storage redundant. For example, a common tweak is to store dynamic data (var/cache, var/session) in a memory-based file system such as a RAMdisk or tmpfs which reduces overall Disk IO. Our testing has shown this is general unnecessary on Blaze SSD VPS performs fast enough to cover this. Even so, we recommend enabling the noatime variable for your primary partition variable in the mount options area of /etc/fstab Edit /etc/fstab eg. # vi /etc/fstab Make sure your primary partition mount options look like the following. Add in noatime as below, save & reboot. /dev/xvda1 / ext3 usrjquota=quota.user,jqfmt=vfsv0,noatime 1 1 The noatime variable is a Linux file system mount option which disables recording of last access time (not to be confused with last modified time which is not effected). This saves the file system from a write operation every time a file is accessed which can lead to significant performance gains. Extra Yum Repositories & Packages The CentOS EPEL repository & REMI repositories have been added to the server. wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm; rpm -Uvh epel-release-6*.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm The following additional system administration packages have been pre-installed: atop htop sysstat dstat innotop All of these packages provide invaluable advanced system admin & monitoring output options for Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 15
system performance tweak. Please consult the relevant manual pages for these packages to familiarise you with their usage. Common File Locations PHP Configuration = php.ini = /usr/lib/php.ini APC Configuration = apc.php = /usr/local/lib/php/apc.php MySQL Configuration = my.cnf = /etc/my.cnf MySQL Error Log = /var/lib/mysql/<hostname>.err MySQL Slow Query Log = /var/lib/mysql/slow-query.log Apache Configuration = /usr/local/apache/conf/httpd.conf (Note: this file is modified by cpanel. Changes must be done using includes: WHM >> Apache Configuration >> Include editor) Apache Global Includes = vi /usr/local/apache/conf/includes/pre_main_global.conf Nginx Vhost directory = /usr/local/nginx/vhost/<domainname>.conf End. Magento Optimised Template CentOS 6 with cpanel/whm Crucial Cloud Hosting 16