{"id":821,"date":"2018-01-17T12:17:08","date_gmt":"2018-01-17T06:47:08","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=821"},"modified":"2018-02-16T17:17:12","modified_gmt":"2018-02-16T11:47:12","slug":"how-to-optimize-mysql-apache-on-cpanelwh","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/how-to-optimize-mysql-apache-on-cpanelwh\/","title":{"rendered":"How to optimize Mysql &#038; apache on cpanel\/whm,"},"content":{"rendered":"<p>From this post we are going to see how to optimize MySQL &amp; Apache on cPanel\/WHM server.<\/p>\n<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 proxy and cache modules. So let\u2019s start,<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-optimize-mysql-apache-on-cpanelwh\/#Apache_PHP\" >Apache &amp; PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-optimize-mysql-apache-on-cpanelwh\/#MySQL\" >MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-optimize-mysql-apache-on-cpanelwh\/#Repair_optimize_databases_then_restart_MySQL\" >Repair &amp; optimize databases then restart MySQL:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-optimize-mysql-apache-on-cpanelwh\/#Security_Limit_Resources\" >Security &amp; Limit Resources:<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"Apache_PHP\"><\/span><strong><span style=\"text-decoration: underline;\">Apache &amp; PHP<\/span><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\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.6+<\/p>\n<p>* In step 5 \u201cExhaustive Options List\u201d select<\/p>\n<p>\u2013 Deflate<\/p>\n<p>\u2013 Expires<\/p>\n<p>\u2013 MPM Worker<\/p>\n<p>After&nbsp;Easy 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 (From 2GB memory or less and to 12GB+ memory)\r\n\r\nStartServers       4             8               16 \r\nMinSpareServers    4             8               16 \r\nMaxSpareServers    8             16              32 \r\nServerLimit        128           256             512 \r\nMaxRequestWorkers  150           250             500 \r\nMaxConnectionsPerChild 1000      2500            5000 \r\nKeep-Alive         On            On              On\r\nKeep-Alive Timeout  1            1               1\r\nMax Keep-Alive Requests 30       30              30\r\nTimeout            60            60              60\r\n<\/pre>\n<p>Now go to WHM \u00bb Service Configuration \u00bb Apache Configuration \u00bb Include Editor \u00bb \u201cPre VirtualHost Include\u201d and allow users minimal cache and data 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\r\n&lt;FilesMatch \".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$\"&gt;\r\nHeader set Cache-Control \"max-age=3600, public\"\r\n&nbsp;\r\n&lt;FilesMatch \".(xml|txt)$\"&gt;\r\nHeader set Cache-Control \"max-age=3600, public, must-revalidate\"\r\n&nbsp;\r\n&lt;FilesMatch \".(html|htm)$\"&gt;\r\nHeader set Cache-Control \"max-age=3600, must-revalidate\"\r\n&nbsp;\r\n# Mod Deflate performs data compression\r\n&lt;FilesMatch \".(js|css|html|php|xml|jpg|png|gif)$\"&gt;\r\nSetOutputFilter DEFLATE\r\nBrowserMatch ^Mozilla\/4 gzip-only-text\/html\r\nBrowserMatch ^Mozilla\/4.0[678] no-gzip\r\nBrowserMatch bMSIE no-gzip\r\n<\/pre>\n<p>Go to WHM \u00bb Service Configuration \u00bb \u201cPHP Configuration Editor\u201d and set the parameters according to your needs:<\/p>\n<p>\u2013 memory_limit<\/p>\n<p>\u2013 max_execution_time<\/p>\n<p>\u2013 max_input_time<\/p>\n<h4><span class=\"ez-toc-section\" id=\"MySQL\"><\/span><span style=\"text-decoration: underline;\"><strong>MySQL<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>For MySQL you need to update the configuration file that usually in \/etc\/my.cnf<\/p>\n<p>Best config base on 2 core &amp; 4GB memory MySQL 5.6 \\ MariaDB 10:<\/p>\n<pre>[mysqld]\r\n        local-infile = 0\r\n        max_connections = 250\r\n        key_buffer = 64M\r\n        myisam_sort_buffer_size = 64M\r\n        join_buffer_size = 1M\r\n        read_buffer_size = 1M\r\n        sort_buffer_size = 2M\r\n        max_heap_table_size = 16M\r\n        table_cache = 5000\r\n        thread_cache_size = 286\r\n        interactive_timeout = 25\r\n        wait_timeout = 7000\r\n        connect_timeout = 15\r\n        max_allowed_packet = 16M\r\n        max_connect_errors = 10\r\n        query_cache_limit = 2M\r\n        query_cache_size = 32M\r\n        query_cache_type = 1\r\n        tmp_table_size = 16M\r\n        open_files_limit=25280\r\n\r\n[mysqld_safe]\r\n\r\n[mysqldump]\r\n       quick\r\n       max_allowed_packet = 16M\r\n[myisamchk]\r\n       key_buffer = 64M\r\n       sort_buffer = 64M\r\n       read_buffer = 16M\r\n       write_buffer = 16M\r\n[mysqlhotcopy]\r\n       interactive-timeout\r\n&nbsp;\r\n<\/pre>\n<p>Best config base on 8 core &amp; 16GB+ memory (Shared server) MySQL 5.6 or MariaDB 10:<\/p>\n<pre>[mysqld]\r\nlocal-infile=0\r\nmax_connections = 600\r\nmax_user_connections=1000\r\nkey_buffer_size = 512M\r\nmyisam_sort_buffer_size = 64M\r\nread_buffer_size = 1M\r\ntable_open_cache = 5000\r\nthread_cache_size = 384\r\nwait_timeout = 20\r\nconnect_timeout = 10\r\ntmp_table_size = 256M\r\nmax_heap_table_size = 128M\r\nmax_allowed_packet = 64M\r\nnet_buffer_length = 16384\r\nmax_connect_errors = 10\r\nconcurrent_insert = 2\r\nread_rnd_buffer_size = 786432\r\nbulk_insert_buffer_size = 8M\r\nquery_cache_limit = 5M\r\nquery_cache_size = 128M\r\nquery_cache_type = 1\r\nquery_prealloc_size = 262144\r\nquery_alloc_block_size = 65535\r\ntransaction_alloc_block_size = 8192\r\ntransaction_prealloc_size = 4096\r\nmax_write_lock_count = 8\r\nslow_query_log\r\nlog-error\r\nexternal-locking=FALSE\r\nopen_files_limit=50000\r\n\r\n[mysqld_safe]\r\n\r\n[mysqldump]\r\nquick\r\nmax_allowed_packet = 16M\r\n\r\n[isamchk]\r\nkey_buffer = 384M\r\nsort_buffer = 384M\r\nread_buffer = 256M\r\nwrite_buffer = 256M\r\n\r\n[myisamchk]\r\nkey_buffer = 384M\r\nsort_buffer = 384M\r\nread_buffer = 256M\r\nwrite_buffer = 256M\r\n\r\n#### Per connection configuration ####\r\nsort_buffer_size = 1M\r\njoin_buffer_size = 1M\r\nthread_stack = 192K\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Repair_optimize_databases_then_restart_MySQL\"><\/span><span style=\"text-decoration: underline;\">Repair &amp; optimize databases then restart MySQL:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<pre>mysqlcheck --check --auto-repair --all-databases\r\nmysqlcheck --optimize --all-databases\r\n\/etc\/init.d\/mysql restar\r\n<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Security_Limit_Resources\"><\/span><span style=\"text-decoration: underline;\">Security &amp; Limit Resources:<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Install CSF (ConfigServer Security &amp; Firewall) at: http:\/\/configserver.com\/free\/csf\/install.txt<br \/>\n1) Go 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>2) Go 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>Along with the above, tweak the CSF by checking your server\u2019s security.<\/p>\n<p>That\u2019s it we are done the optimization of our Mysql and Apache on cPanel\/Whm server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From this post we are going to see how to optimize MySQL &amp; Apache on cPanel\/WHM server. 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":840,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-latest"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/01\/OPTIMIZE.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-df","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=821"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/821\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/840"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}