{"id":2652,"date":"2014-03-31T15:21:18","date_gmt":"2014-03-31T15:21:18","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=2652"},"modified":"2014-03-31T15:21:18","modified_gmt":"2014-03-31T15:21:18","slug":"optimise-mysql-apache-cpanelwhm","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2014\/03\/31\/optimise-mysql-apache-cpanelwhm\/","title":{"rendered":"How To Optimise MySQL &#038; Apache On cPanel\/WHM"},"content":{"rendered":"<p>On this optimization process we will go over the Apache core configuration and modules that are part of Apache core. We think that with the correct settings of Apache and MySQL you can get excellent results and the correct level of resource use without installing third-party\u00a0proxy and\u00a0cache modules. So let\u2019s start,<\/p>\n<p>&nbsp;<\/p>\n<h3>Apache &amp; PHP<\/h3>\n<p>In the first stage we run the Easy Apache and selected the following:<\/p>\n<p>* Apache Version 2.4+<\/p>\n<p>* PHP Version 5.4+<\/p>\n<p>* In step 5 \u201cExhaustive Options List\u201d select<\/p>\n<p>&#8211; Deflate<\/p>\n<p>&#8211; Expires<\/p>\n<p>&#8211; MPM Prefork<\/p>\n<p>&#8211; MPM Worker<\/p>\n<p>After\u00a0Easy Apache finished go to your WHM \u00bb Service Configuration \u00bb Apache Configuration \u00bb \u201cGlobal Configuration\u201d and set the values by the level of resources available on your server.<\/p>\n<pre>Apache Directive \t \t(From 2GB memory or less and up to 12GB memory) \t \t\n\nStartServers \t \t \t4 \t \t8 \t \t16 \t\nMinSpareServers \t \t4 \t \t8 \t \t16 \t\nMaxSpareServers \t \t8 \t \t16 \t \t32 \t\nServerLimit \t \t \t64 \t \t128 \t \t256 \t\nMaxRequestWorkers \t \t50 \t \t120 \t \t250 \t\nMaxConnectionsPerChild \t \t1000 \t \t2500 \t \t5000 \nKeep-Alive\t\t\tOn\t\tOn\t\tOn\nKeep-Alive Timeout\t \t5\t \t5\t \t 5\nMax Keep-Alive Requests\t\t50\t \t120\t \t120\nTimeout\t\t\t\t30\t\t60\t\t60<\/pre>\n<p>&nbsp;<\/p>\n<p>Now go to WHM \u00bb Service Configuration \u00bb Apache Configuration \u00bb Include Editor \u00bb \u201cPre VirtualHost Include\u201d and allow users minimal\u00a0cache and\u00a0data compression to allow the server to work less for the same things by pasting the code below into the text field.<\/p>\n<pre># Cache Control Settings for one hour cache\n&lt;FilesMatch \".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$\"&gt;\nHeader set Cache-Control \"max-age=3600, public\"\n&lt;\/FilesMatch&gt;\n\n&lt;FilesMatch \".(xml|txt)$\"&gt;\nHeader set Cache-Control \"max-age=3600, public, must-revalidate\"\n&lt;\/FilesMatch&gt;\n\n&lt;FilesMatch \".(html|htm)$\"&gt;\nHeader set Cache-Control \"max-age=3600, must-revalidate\"\n&lt;\/FilesMatch&gt;\n\n# Mod Deflate performs data compression\n&lt;IfModule mod_deflate.c&gt;\n&lt;FilesMatch \".(js|css|html|php|xml|jpg|png|gif)$\"&gt;\nSetOutputFilter DEFLATE\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html\nBrowserMatch ^Mozilla\/4.0[678] no-gzip\nBrowserMatch bMSIE no-gzip\n&lt;\/FilesMatch&gt;\n&lt;\/IfModule&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>Go to WHM \u00bb Service Configuration \u00bb \u201cPHP Configuration Editor\u201d and set the parameters according to your needs:<\/p>\n<p>&#8211; memory_limit<\/p>\n<p>&#8211; max_execution_time<\/p>\n<p>&#8211; max_input_time<\/p>\n<p>&nbsp;<\/p>\n<h3>MySQL<\/h3>\n<p>For MySQL you need to update the configuration file that\u00a0usually in \/etc\/my.cnf<\/p>\n<p>Best config base on 1 core &amp; 2GB memory MySQL 5.5:<\/p>\n<pre>[mysqld]\n    local-infile = 0\n    max_connections = 250\n    key_buffer = 64M\n    myisam_sort_buffer_size = 64M\n    join_buffer_size = 1M\n    read_buffer_size = 1M\n    sort_buffer_size = 2M\n    max_heap_table_size = 16M\n    table_cache = 5000\n    thread_cache_size = 286\n    interactive_timeout = 25\n    wait_timeout = 7000\n    connect_timeout = 15\n    max_allowed_packet = 16M\n    max_connect_errors = 10\n    query_cache_limit = 2M\n    query_cache_size = 32M\n    query_cache_type = 1\n    tmp_table_size = 16M\n    open_files_limit=2528\n\n[mysqld_safe]\n\n[mysqldump]\n    quick\n    max_allowed_packet = 16M\n[myisamchk]\n    key_buffer = 64M\n    sort_buffer = 64M\n    read_buffer = 16M\n    write_buffer = 16M\n[mysqlhotcopy]\n    interactive-timeout<\/pre>\n<p>&nbsp;<\/p>\n<p>Best config base on 8 core &amp; 12GB memory (Shared server) MySQL 5.5:<\/p>\n<pre>[mysqld]\nlocal-infile=0\nmax_connections = 600\nmax_user_connections=1000\nkey_buffer_size = 512M\nmyisam_sort_buffer_size = 64M\nread_buffer_size = 1M\ntable_open_cache = 5000\nthread_cache_size = 384\nwait_timeout = 20\nconnect_timeout = 10\ntmp_table_size = 256M\nmax_heap_table_size = 128M\nmax_allowed_packet = 64M\nnet_buffer_length = 16384\nmax_connect_errors = 10\nconcurrent_insert = 2\nread_rnd_buffer_size = 786432\nbulk_insert_buffer_size = 8M\nquery_cache_limit = 5M\nquery_cache_size = 128M\nquery_cache_type = 1\nquery_prealloc_size = 262144\nquery_alloc_block_size = 65535\ntransaction_alloc_block_size = 8192\ntransaction_prealloc_size = 4096\nmax_write_lock_count = 8\nslow_query_log\nlog-error\nexternal-locking=FALSE\nopen_files_limit=50000\n\n[mysqld_safe]\n\n[mysqldump]\nquick\nmax_allowed_packet = 16M\n\n[isamchk]\nkey_buffer = 384M\nsort_buffer = 384M\nread_buffer = 256M\nwrite_buffer = 256M\n\n[myisamchk]\nkey_buffer = 384M\nsort_buffer = 384M\nread_buffer = 256M\nwrite_buffer = 256M\n\n#### Per connection configuration ####\nsort_buffer_size = 1M\njoin_buffer_size = 1M\nthread_stack = 192K<\/pre>\n<p>&nbsp;<\/p>\n<p>Repair &amp; optimize databases then restart MySQL:<\/p>\n<pre>mysqlcheck --check --auto-repair --all-databases\nmysqlcheck --optimize --all-databases\n\/etc\/init.d\/mysql restart<\/pre>\n<p>&nbsp;<\/p>\n<h3>Security &amp; Limit Resources<\/h3>\n<p>&nbsp;<\/p>\n<p>Install\u00a0CSF (ConfigServer Security &amp; Firewall) at: http:\/\/configserver.com\/free\/csf\/install.txt<\/p>\n<p><strong>1)<\/strong>\u00a0Go to WHM \u00bb Plugins \u00bb ConfigServer Security &amp; Firewall \u00bb \u201cCheck Server Security\u201d And pass on what appears as required to repair:<\/p>\n<p><strong>2)<\/strong>\u00a0Go to WHM \u00bb Plugins \u00bb ConfigServer Security &amp; Firewall \u00bb \u201cFirewall Configuration\u201d and set the parameters according to your needs:<\/p>\n<p>PT_USERMEM=180<\/p>\n<p>PT_USERTIME=180<\/p>\n<p>PT_USERKILL=1<\/p>\n<p>PT_USERKILL_ALERT=1 (Optional)<\/p>\n<p>&nbsp;<\/p>\n<p>Now enjoy your new fast and more effective server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On this optimization process we will go over the Apache core configuration and modules that are part of Apache core. We think that with the correct settings of Apache and MySQL you can get excellent results and the correct level of resource use without installing third-party\u00a0proxy and\u00a0cache modules. So let\u2019s start, &nbsp; Apache &amp; PHP [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[58,60],"tags":[192,193,194,195,196],"class_list":["post-2652","post","type-post","status-publish","format-standard","hentry","category-cpanel-control-panel","category-linux","tag-cpanelwhm-optimisation","tag-optimisation-apache-mysql","tag-optimise-apache","tag-optimise-httpd","tag-optimise-mysql"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/2652","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=2652"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/2652\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=2652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=2652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=2652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}