<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>php scripts Archives - Chris Gilligan » new media</title>
	<atom:link href="http://chrisgilligan.com/tag/php-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>https://chrisgilligan.com/tag/php-scripts/</link>
	<description>portfolio of web work</description>
	<lastBuildDate>Wed, 05 Feb 2014 15:32:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</title>
		<link>https://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/</link>
					<comments>https://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/#comments</comments>
		
		<dc:creator><![CDATA[Chris Gilligan]]></dc:creator>
		<pubDate>Mon, 22 Aug 2011 15:13:20 +0000</pubDate>
				<category><![CDATA[Consulting]]></category>
		<category><![CDATA[Web Server Performance Tuning]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[buffer length]]></category>
		<category><![CDATA[buffer pool]]></category>
		<category><![CDATA[buffer size]]></category>
		<category><![CDATA[cache size]]></category>
		<category><![CDATA[configured server]]></category>
		<category><![CDATA[email servers]]></category>
		<category><![CDATA[force probes]]></category>
		<category><![CDATA[innodb]]></category>
		<category><![CDATA[lfd]]></category>
		<category><![CDATA[max connections]]></category>
		<category><![CDATA[memory usage]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[php scripts]]></category>
		<category><![CDATA[pool size]]></category>
		<category><![CDATA[software accounts]]></category>
		<category><![CDATA[stateful packet inspection]]></category>
		<category><![CDATA[static html files]]></category>
		<category><![CDATA[virtual hosts]]></category>
		<guid isPermaLink="false">https://chrisgilligan.com/?p=508</guid>

					<description><![CDATA[<p>Web hosting has changed dramatically in the last few years. The majority of accounts are now running PHP scripts and MySQL, whereas in the past most accounts were only serving static HTML files. This presents challenges in security as well as performance tuning. It is impossible to predict whether a certain configuration will work properly [&#8230;]</p>
<p>The post <a href="https://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</a> appeared first on <a href="https://chrisgilligan.com">Chris Gilligan » new media</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p style="float: right; margin: 0 0 10px 15px; width:240px; height: auto;">
		<img src="https://d2lehxir4n36oh.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php.jpg?x25141" width="240" style="max-width: 100%; height: auto;" />
		</p><p><strong><img decoding="async" class="alignright size-thumbnail wp-image-515" title="LAMP-linux-apache-mysql-php" alt="" src="https://d2lehxir4n36oh.cloudfront.net/wp-content/uploads/2011/08/LAMP-linux-apache-mysql-php-e1314060599892-150x81.jpg?x25141" width="150" height="81" />Web hosting has changed dramatically in the last few years.</strong> The majority of accounts are now running PHP scripts and MySQL, whereas in the past most accounts were only serving static HTML files. This presents challenges in security as well as performance tuning.</p>
<p>It is impossible to predict whether a certain configuration will work properly for a given server, unless the hardware, software, accounts, network and traffic are identical to a previously configured server… therefore it is impossible to give a configuration which will cover all applications.</p>
<h3>Firewall Unnecessary Traffic from Affecting the Server</h3>
<p>Before you begin performance tuning, please consider using a stateful packet inspection (SPI) firewall &amp; login failure daemon (LFD) for your server: <a title="ConfigServer free firewall for web servers" href="http://configserver.com/cp/csf.html">ConfigServer Firewall is an excellent free firewall</a> &amp; LFD. This will help prevent brute force probes, port flooding, DDOS, etc. If you have 600 virtual hosts running on a server, it is very likely that the server is experiencing constant malicious exploits, especially if you are also running email servers on the same IP addresses.</p>
<p>If your host does not support ConfigServer (e.g. Amazon AWS and some VPS may not play well with CSF), you may use <a title="Fail2Ban Regex for RedHat, Fedora, CentOS and Amazon Linux 2013" href="https://chrisgilligan.com/consulting/amazon-web-services/fail2ban-regex/">Fail2Ban</a>.</p>
<h3>Tune Apache the Sane Way (Requires Basic Math Skills)</h3>
<p>If you wish to tune your Apache MPM settings, you should consider following this method:<br />
<a href="http://web.archive.org/web/20120620141433/https://telvps.com/clients/knowledgebase/25/HOW-TO-Optimize-Apache-for-Low-Memory-Usage.html">https://telvps.com/clients/knowledgebase/25/HOW-TO-Optimize-Apache-for-Low-Memory-Usage.html</a><br />
(the formula works well as a basic guide&#8230; but does not take into account PHP memory requirements&#8230; see Ovidiu&#8217;s comment below).</p>
<h3>MySQL Tuning Is More Difficult: Trial and Error</h3>
<p>To test your MySQL server performance, you may try:</p>
<ul>
<li><strong>mysqltuner:</strong> <a title="MySQL performance tuning script" href="https://github.com/rackerhacker/MySQLTuner-perl">https://github.com/rackerhacker/MySQLTuner-perl</a> (or http://mysqltuner.pl for the script only)</li>
<li><strong>MySQL Tuning Primer:</strong> <a title="MySQL Tuning Primer script" href="https://launchpad.net/mysql-tuning-primer">https://launchpad.net/mysql-tuning-primer</a></li>
<li><strong><a title="Secure phpMyAdmin with SSL on CentOS, Amazon Linux, RedHat" href="https://chrisgilligan.com/consulting/amazon-web-services/secure-phpmyadmin-with-ssl-on-centos-amazon-linux-redhat/">phpMyAdmin 3.5</a>+:</strong> Status Monitor and Advisor are excellent tools, but require <a title="Secure phpMyAdmin with SSL on CentOS, Amazon Linux, RedHat" href="https://chrisgilligan.com/consulting/amazon-web-services/secure-phpmyadmin-with-ssl-on-centos-amazon-linux-redhat/">proper phpMyAdmin setup</a></li>
</ul>
<p>These scripts will analyze MySQL performance and make suggestions regarding your my.cnf configuration. mysqltuner is now deprecated, but it still widely used and is very simple. Tuning Primer is the most up-to-date, and provides more complete recommendations.</p>
<p><strong>If you are running MySQL 5 or later, the configuration statements can be in the following form (example from one of my servers):</strong></p>
<p><code>[mysqld]<br />
datadir=/var/lib/mysql<br />
socket=/var/lib/mysql/mysql.sock<br />
user=mysql</code></p>
<p><code>symbolic-links=0<br />
innodb_file_per_table = 1<br />
thread_concurrency = 8<br />
query_cache_size = 64M<br />
query_cache_limit = 4M<br />
thread_cache_size = 8<br />
myisam_sort_buffer_size = 64M<br />
read_rnd_buffer_size = 8M<br />
read_buffer_size = 2M<br />
sort_buffer_size = 2M<br />
table_cache = 1600<br />
table_definition_cache = 1600<br />
max_allowed_packet = 4M<br />
key_buffer = 1G<br />
interactive_timeout = 2<br />
wait_timeout = 5<br />
long_query_time = 1<br />
log_slow_queries = ON<br />
open_files_limit = 3200<br />
innodb_buffer_pool_size = 26M<br />
join_buffer_size = 4M<br />
tmp_table_size = 72M<br />
max_heap_table_size = 72M<br />
max_connections = 80</code></p>
<p><code>[mysqld_safe]<br />
log-error=/var/log/mysqld.log<br />
pid-file=/var/run/mysqld/mysqld.pid</code></p>
<p>This is for example only! table_cache should be set a little higher than the total number of tables (sum of MYISAM,INNODB,MEMORY etc.), as reported by mysqltuner. If you anticipate adding more virtual hosts, or clients adding more databases or tables, you will need to raise table_cache value.</p>
<p>Follow the recommendations from the Apache tuning, and then follow the recommendations of the tuning scripts. The apache tuning will give you the number of maxclients, and from this you will know the appropriate beginning value for [mysqld] max_connections. Begin with max_connections set slightly higher than Apache&#8217;s maxclients. If you are running database caching via APC, you may lower max_connections, because APC will serve the busiest queries directly from cache.</p>
<h3>Take Time to Get a Realistic Assessment of MySQL Performance</h3>
<p>If you have a PHP opcode and database caching strategy (such as APC) implemented on your web server and for your PHP script packages, you will be able to lower maxconnections, based on the information you receive from mysqltuner after 24-48 hours of steady traffic. For example, I have a server with Apache set to 256 maxclients, but the MySQL maxconnections set to 200, because many web requests do not require direct interaction with the MySQL server.</p>
<p>Take a look at &#8220;Highest usage of available connections&#8221;, and lower maxconnections accordingly. It is safe to lower maxconnections to a number slightly above the reported highest usage. Doing so will allow you to set higher values for the individual cache settings which affect the thread cache size, because the total thread buffer memory size is multiplied by maxconnections. Feedback is available in the reports for &#8220;Total buffers&#8221; and &#8220;Highest usage of available connections&#8221;.</p>
<p>After you have the proper settings for maxclients and maxconnections, restart httpd and mysqld. Wait 1 hour, and run mysqltuner to see if there are any recommended changes. Mysqltuner will show you the maximum memory which will be used by mysql. You should adjust config variables to take up no more than 60% of total RAM. Wait 24-48 hours and run mysqltuner again.</p>
<h4>Example mysqltuner results:</h4>
<p><code>------- Performance Metrics -------------------------------------------------<br />
[--] Up for: 13d 2h 34m 16s (1M q [1.561 qps], 67K conn, TX: 81B, RX: 449M)<br />
[--] Reads / Writes: 91% / 9%<br />
[--] Total buffers: 298.0M global + 6.4M per thread (151 max threads)<br />
[OK] Maximum possible memory usage: 1.2G (61% of installed RAM)<br />
[OK] Slow queries: 0% (0/1M)<br />
[OK] Highest usage of available connections: 6% (10/151)<br />
[OK] Key buffer size / total MyISAM indexes: 256.0M/9.7M<br />
[OK] Key buffer hit rate: 99.6% (3M cached / 13K reads)<br />
[OK] Query cache efficiency: 75.2% (1M cached / 1M selects)<br />
[!!] Query cache prunes per day: 1360<br />
[OK] Sorts requiring temporary tables: 0% (4 temp sorts / 13K sorts)<br />
[!!] Temporary tables created on disk: 38% (6K on disk / 16K total)<br />
[OK] Thread cache hit rate: 99% (13 created / 67K connections)<br />
[OK] Table cache hit rate: 51% (115 open / 223 opened)<br />
[OK] Open file limit used: 20% (212/1K)<br />
[OK] Table locks acquired immediately: 99% (408K immediate / 409K locks)</code><br />
<code>-------- Recommendations -----------------------------------------------------<br />
General recommendations:<br />
Add skip-innodb to MySQL configuration to disable InnoDB<br />
Run OPTIMIZE TABLE to defragment tables for better performance<br />
Enable the slow query log to troubleshoot bad queries<br />
When making adjustments, make tmp_table_size/max_heap_table_size equal<br />
Reduce your SELECT DISTINCT queries without LIMIT clauses<br />
Variables to adjust:<br />
query_cache_size (&gt; 16M)<br />
tmp_table_size (&gt; 16M)<br />
max_heap_table_size (&gt; 16M)</code></p>
<p>I suggest you NOT enable the slow query log unless the Slow Queries result is very high. Slow Queries result % will be somewhat high if MySQL has run for less than 24 hours.</p>
<h4>Example MySQL Tuning Primer results:</h4>
<p><code>SLOW QUERIES<br />
The slow query log is NOT enabled.<br />
Current long_query_time = 10.000000 sec.<br />
You have 0 out of 1768137 that take longer than 10.000000 sec. to complete<br />
Your long_query_time seems to be fine<br />
</code></p>
<p><code>BINARY UPDATE LOG<br />
The binary update log is NOT enabled.<br />
You will not be able to do point in time recovery<br />
See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html<br />
</code></p>
<p><code>WORKER THREADS<br />
Current thread_cache_size = 8<br />
Current threads_cached = 7<br />
Current threads_per_sec = 0<br />
Historic threads_per_sec = 0<br />
Your thread_cache_size is fine<br />
</code></p>
<p><code>MAX CONNECTIONS<br />
Current max_connections = 151<br />
Current threads_connected = 1<br />
Historic max_used_connections = 10<br />
The number of used connections is 6% of the configured maximum.<br />
You are using less than 10% of your configured max_connections.<br />
Lowering max_connections could help to avoid an over-allocation of memory<br />
See "MEMORY USAGE" section to make sure you are not over-allocating<br />
</code></p>
<p><code>INNODB STATUS<br />
Current InnoDB index space = 0 bytes<br />
Current InnoDB data space = 0 bytes<br />
Current InnoDB buffer pool free = 96 %<br />
Current innodb_buffer_pool_size = 8 M<br />
Depending on how much space your innodb indexes take up it may be safe<br />
to increase this value to up to 2 / 3 of total system memory<br />
</code></p>
<p><code>MEMORY USAGE<br />
Max Memory Ever Allocated : 345 M<br />
Configured Max Per-thread Buffers : 962 M<br />
Configured Max Global Buffers : 282 M<br />
Configured Max Memory Limit : 1.21 G<br />
Physical Memory : 2.00 G<br />
Max memory limit seem to be within acceptable norms<br />
</code></p>
<p><code>KEY BUFFER<br />
Current MyISAM index space = 9 M<br />
Current key_buffer_size = 256 M<br />
Key cache miss rate is 1 : 247<br />
Key buffer free ratio = 80 %<br />
Your key_buffer_size seems to be fine<br />
</code></p>
<p><code>QUERY CACHE<br />
Query cache is enabled<br />
Current query_cache_size = 16 M<br />
Current query_cache_used = 12 M<br />
Current query_cache_limit = 1 M<br />
Current Query cache Memory fill ratio = 77.74 %<br />
Current query_cache_min_res_unit = 4 K<br />
MySQL won't cache query results that are larger than query_cache_limit in size<br />
</code></p>
<p><code>SORT OPERATIONS<br />
Current sort_buffer_size = 1 M<br />
Current read_rnd_buffer_size = 4 M<br />
Sort buffer seems to be fine<br />
</code></p>
<p><code>JOINS<br />
Current join_buffer_size = 132.00 K<br />
You have had 0 queries where a join could not use an index properly<br />
Your joins seem to be using indexes properly<br />
</code></p>
<p><code>OPEN FILES LIMIT<br />
Current open_files_limit = 1024 files<br />
The open_files_limit should typically be set to at least 2x-3x<br />
that of table_cache if you have heavy MyISAM usage.<br />
Your open_files_limit value seems to be fine<br />
</code></p>
<p><code>TABLE CACHE<br />
Current table_open_cache = 256 tables<br />
Current table_definition_cache = 256 tables<br />
You have a total of 97 tables<br />
You have 115 open tables.<br />
The table_cache value seems to be fine<br />
</code></p>
<p><code>TEMP TABLES<br />
Current max_heap_table_size = 16 M<br />
Current tmp_table_size = 16 M<br />
Of 10325 temp tables, 37% were created on disk<br />
Perhaps you should increase your tmp_table_size and/or max_heap_table_size<br />
to reduce the number of disk-based temporary tables<br />
Note! BLOB and TEXT columns are not allow in memory tables.<br />
If you are using these columns raising these values might not impact your<br />
ratio of on disk temp tables.<br />
</code></p>
<p><code>TABLE SCANS<br />
Current read_buffer_size = 1 M<br />
Current table scan ratio = 199 : 1<br />
read_buffer_size seems to be fine<br />
</code></p>
<p><code>TABLE LOCKING<br />
Current Lock Wait ratio = 1 : 2405<br />
You may benefit from selective use of InnoDB.<br />
If you have long running SELECT's against MyISAM tables and perform<br />
frequent updates consider setting 'low_priority_updates=1'<br />
If you have a high concurrency of inserts on Dynamic row-length tables<br />
consider setting 'concurrent_insert=2'.</code></p>
<p>The post <a href="https://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/">Tuning Apache and MySQL for Best Performance in a Shared Virtual Hosting Environment</a> appeared first on <a href="https://chrisgilligan.com">Chris Gilligan » new media</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://chrisgilligan.com/consulting/tuning-apache-and-mysql-for-best-performance-in-a-shared-virtual-hosting-environment/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Page Caching using Disk: Enhanced 
Content Delivery Network via Amazon Web Services: CloudFront: d2lehxir4n36oh.cloudfront.net
Lazy Loading (feed)

Served from: chrisgilligan.com @ 2026-06-20 00:37:36 by W3 Total Cache
-->