<?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>五四陈科学院-坚信科学，分享技术 &#187; wordpress</title>
	<atom:link href="http://www.54chen.com/tag/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://www.54chen.com</link>
	<description>PHP、JAVA、缓存、架构、经验、分享</description>
	<lastBuildDate>Sat, 11 Feb 2012 17:09:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>[54chen原创]简单好用的土办法抗击洋鬼子对wordpress系统的广告灌入</title>
		<link>http://www.54chen.com/php-tech/easy-method-to-antispam-wordpress.html</link>
		<comments>http://www.54chen.com/php-tech/easy-method-to-antispam-wordpress.html#comments</comments>
		<pubDate>Mon, 23 Aug 2010 15:24:02 +0000</pubDate>
		<dc:creator>54chen</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[antispam]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/easy-method-to-antispam-wordpress.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>自升级wordpress3.0以后，一切风调雨顺，自上周起，被洋鬼子的广告肉机盯上了，平均每三五分钟一条广告，评论内容大致相同，评论ip来自五湖四海，各不相同。 虽然说akismet是wordpress中antispam无二的选择，但是akismet那个验证码让人很纠结，于是只能自己山寨一把了。 土办法步骤一 转发默认评论地址 常见的洋鬼子的广告肉机，都是利用了wordpress公开的post地址来做到脚本灌入的，其默认地址是wp-comments-post.php，第一步要做的是，屏蔽这个地址（以nginx为例）： rewrite ^/wp\-comments\-post\.php$ http://www.54chen.com/ last; 土办法步骤二 伪造假地址 既然第一步中的真实地址无法访问了，那第二步肯定是假冒出来可以访问的地址： if (!-e $request_filename){ rewrite ^/wc([0-9]+)\.html$ /wp-comments-post.php?54chen=$1 last; } 土办法步骤三 javascript制造假post 完成上面两步之后 ，最后一步就是将原来的comments.php修改post action的地址为伪造的地址，为了更加有效果，使用js来产生随机的wc1234.html即可： 在评论的form中增加onsubmit="chenAntiSpam()" name="commentform"； 再增加js: &#60;script type="text/javascript"&#62; function chenAntiSpam() {  var param ='wc'+Math.round(Math.random()*1000)+'.html';  document.commentform.action = 'http://www.54chen.com/'+param; } &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p><img src="http://img04.taobaocdn.com/imgextra/i4/T1c3hJXb8pXXcVO1Z._112132.jpg" alt="54chen" /></p>
<p>自升级wordpress3.0以后，一切风调雨顺，自上周起，被洋鬼子的广告肉机盯上了，平均每三五分钟一条广告，评论内容大致相同，评论ip来自五湖四海，各不相同。<br />
虽然说akismet是wordpress中antispam无二的选择，但是akismet那个验证码让人很纠结，于是只能自己山寨一把了。<br />
<strong>土办法步骤一 转发默认评论地址</strong><br />
常见的洋鬼子的广告肉机，都是利用了wordpress公开的post地址来做到脚本灌入的，其默认地址是wp-comments-post.php，第一步要做的是，屏蔽这个地址（以nginx为例）：<br />
rewrite ^/wp\-comments\-post\.php$ http://www.54chen.com/ last;</p>
<p><strong>土办法步骤二 伪造假地址</strong><br />
既然第一步中的真实地址无法访问了，那第二步肯定是假冒出来可以访问的地址：<br />
if (!-e $request_filename){<br />
rewrite ^/wc([0-9]+)\.html$ /wp-comments-post.php?54chen=$1 last;<br />
}</p>
<p><strong>土办法步骤三 javascript制造假post</strong><br />
完成上面两步之后 ，最后一步就是将原来的comments.php修改post action的地址为伪造的地址，为了更加有效果，使用js来产生随机的wc1234.html即可：<br />
在评论的form中增加onsubmit="chenAntiSpam()" name="commentform"；<br />
再增加js:</p>
<p>&lt;script type="text/javascript"&gt;<br />
function chenAntiSpam() {<br />
 var param ='wc'+Math.round(Math.random()*1000)+'.html';<br />
 document.commentform.action = 'http://www.54chen.com/'+param;<br />
}<br />
&lt;/script&gt;</p>
<p>大功告成，有效防住了洋鬼子的灌。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/easy-method-to-antispam-wordpress.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>解读PHP开源项目中列表和hook方法：while(has_items()): thme_ite();和apply_filters</title>
		<link>http://www.54chen.com/php-tech/php-open-source-projects-reading-lists-and-hook-methods-while-has_items-thme_ite-and-apply_filters.html</link>
		<comments>http://www.54chen.com/php-tech/php-open-source-projects-reading-lists-and-hook-methods-while-has_items-thme_ite-and-apply_filters.html#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:23:55 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[开源]]></category>

		<guid isPermaLink="false">http://www.54chen.com/php-tech/php-open-source-projects-reading-lists-and-hook-methods-while-has_items-thme_ite-and-apply_filters.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>在wordpress,lilina等开源项目中，常常会看到一些莫名的代码，来无影去无踪，看上去很有意味，特地拿来分析分析，看看一般的作法。 part 1  列表 循环显示 先看代码： &#60;?php $num = 0; if(has_items()) { while(has_items()): the_item(); } ?&#62; 以上代码，出自某开源项目。。。 再进入the_item()函数内部，可以看到一个关键的函数： * Returns the current item * * @since 1.0 * * @return bool&#124;stdClass False if item doesn't exist, otherwise returns the specified &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>在<a href="http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html">wordpress</a>,lilina等开源项目中，常常会看到一些莫名的代码，来无影去无踪，看上去很有意味，特地拿来分析分析，看看一般的作法。</p>
<p><strong>part 1  列表 循环显示</strong></p>
<p>先看代码：</p>
<blockquote><p>&lt;?php<br />
$num = 0;<br />
if(has_items()) {<br />
while(has_items()): the_item();<br />
}<br />
?&gt;</p></blockquote>
<p>以上代码，出自某开源项目。。。</p>
<p>再进入the_item()函数内部，可以看到一个关键的函数：</p>
<blockquote><p>* Returns the current item<br />
*<br />
* @since 1.0<br />
*<br />
* @return bool|stdClass False if item doesn't exist, otherwise returns the specified item<br />
*/<br />
public function current_item() {<br />
$this-&gt;previous_item = $this-&gt;current_item;<br />
$this-&gt;current_item = '';</p>
<p>$item = each($this-&gt;items);<br />
$item = $item['value'];<br />
if(!$item)<br />
return false;</p>
<p>$this-&gt;current_item = $item;<br />
$this-&gt;current_feed = $item-&gt;feed;</p>
<p>return $item;<br />
}</p></blockquote>
<p>这个关键的函数是each()，来看手册：</p>
<h1>each</h1>
<div class="refnamediv"><a name="AEN12322"></a>(PHP 3, PHP 4, PHP 5)</p>
<p>each --       返回数组中当前的<a href="http://www.54chen.com/translate/dynamo-based-systems-designed-linkin-voldemort-voldemort-design-chinese-documents-i-am-a-chan-academy-of-sciences-translation-finalized.html">键／值</a>对并将数组指针向前移动一步</div>
<div class="refsect1"><a name="AEN12325"></a></p>
<h2>说明</h2>
<p>array <strong class="methodname">each</strong> ( array &amp;array )</p>
<p>返回 <var class="parameter">array</var> 数组中当前指针位置的键／值对并向前移动数组指针。键值对被返回为四个单元的数组，键名为      <var class="literal">0</var>，<var class="literal">1</var>，<var class="literal">key</var> 和 <var class="literal">value</var>。单元 <var class="literal">0</var> 和      <var class="literal">key</var> 包含有数组单元的键名，<var class="literal">1</var> 和      <var class="literal">value</var> 包含有数据。</p>
<p>如果内部指针越过了数组的末端，则 <strong class="function">each()</strong> 返回 <tt class="constant"><strong>FALSE</strong></tt>。</p>
<p>综合来看，其实就是一个做了一个游标一样的模型，利用each来操作一个数组或者相似的结构，每次在显示的时候，都有对数据数组的本身操作，而while里的has_item，只是作简单的判断有无而已。</p>
<p><strong>part2 hook</strong></p>
<p>第二种情况，是一个叫apply_filters的函数的<a href="http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html">实现</a>。先看代码：</p>
<blockquote><p>function the_item() {<br />
global $lilina_items, $item;</p>
<p>$item = apply_filters('the_item', $lilina_items-&gt;current_item());<br />
}</p></blockquote>
<p>这是lilina里的一个函数，要看的是这个apply_filters方法，有一个简单的例子：</p>
<blockquote><p>function example_hook($string, $arg1, $arg2)<br />
{<br />
//Do stuff<br />
return $string;<br />
}<br />
$value = apply_filters('example_hook', 'filter me', 'arg1', 'arg2');</p></blockquote>
<p>apply_filters里面最关键的一个函数：</p>
<h1>call_user_func_array</h1>
<div class="refnamediv"><a name="AEN50629"></a>(PHP 4 &gt;= 4.0.4, PHP 5)</p>
<p>call_user_func_array --       Call a user function given with an array of parameters</p></div>
<div class="refsect1"><a name="AEN50632"></a></p>
<h2>Description</h2>
<p>mixed <strong class="methodname">call_user_func_array</strong> ( callback function, array param_arr )</p>
<p>Call a user defined function given by      <var class="parameter">function</var>, with      the <a href="http://www.54chen.com/php-tech/multi-nginx-configuration-of-single-php-fpm-approach-from-academy-of-sciences.html">parameters</a> in <var class="parameter">param_arr</var>.</p>
<p>其实这些渐渐被遗忘的<a href="http://www.54chen.com/webfe/academy-of-sciences-in-recent-years-a-good-article-summing-up.html">函数</a>，在高手们的使用下，对项目化的开发很有优势，随手记之。</div>
</div>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/php-tech/php-open-source-projects-reading-lists-and-hook-methods-while-has_items-thme_ite-and-apply_filters.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: redirect WordPress RSS feeds to feedburner with nginx[原创]</title>
		<link>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html</link>
		<comments>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html#comments</comments>
		<pubDate>Sat, 15 Aug 2009 14:01:49 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[feedburner]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[转载请注明：http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/ 作者：陈臻] 可能有大多数朋友都会在用wordpress的时候需要从原始的feed地址转到feedburner上，看到一个老外的博客上说了apache的htaccess的修改方案： &#60;IfModule mod_rewrite.c&#62; RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/-aboutJavaAndPhp [R=302,NC,L] &#60;/IfModule&#62; 心想这nginx也不能没个着落下，于是就试验了一下，nginx作如下修改即可： if ($http_user_agent !~ FeedBurner) {   rewrite ^/feed$ http://feeds.feedburner.com/-aboutJavaAndPhp redirect;   rewrite ^/feed/$ http://feeds.feedburner.com/-aboutJavaAndPhp redirect; } 都是302跳，可能对seo不是太好，不过可能是对一些rss客户端比较好。<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[转载请注明：<a href="http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/">http://www.54chen.com/727-how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original/</a> 作者：陈臻]</p>
<p>可能有大多数朋友都会在用wordpress的时候需要从原始的feed地址转到feedburner上，看到一个老外的博客上说了apache的htaccess的修改方案：</p>
<blockquote><p>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]<br />
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]<br />
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> [R=302,NC,L]<br />
&lt;/IfModule&gt;</p></blockquote>
<p>心想这nginx也不能没个着落下，于是就试验了一下，nginx作如下修改即可：</p>
<blockquote><p>if ($http_user_agent !~ FeedBurner) {<br />
  rewrite ^/feed$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> redirect;<br />
  rewrite ^/feed/$ <a href="http://feeds.feedburner.com/-aboutJavaAndPhp">http://feeds.feedburner.com/-aboutJavaAndPhp</a> redirect;<br />
}</p></blockquote>
<p>都是302跳，可能对seo不是太好，不过可能是对一些rss客户端比较好。</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/_linux_/how-to-redirect-wordpress-rss-feeds-to-feedburner-with-nginx-original.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress nginx php-cgi mysql在128m内存下的vps安装和优化手记[原创]</title>
		<link>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</link>
		<comments>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html#comments</comments>
		<pubDate>Sun, 02 Aug 2009 07:34:49 +0000</pubDate>
		<dc:creator>cc0cc</dc:creator>
				<category><![CDATA[架构研究]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-cgi]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html</guid>
		<description><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/ ] 选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。 图1。   首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包： yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel &#8230;<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></description>
			<content:encoded><![CDATA[<a href="http://www.54chen.com"><img border="0" src="http://www.54chen.com/wp-content/themes/54chen2011/images/54chen-logo.gif"></a><br>以下内容由<a href="http://www.54chen.com">[五四陈科学院]</a>提供<br><p>[ 文章作者：陈臻 本文版本：v1.0 最后修改：2009.8.2 转载请注明原文链接：<a href="http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/">http://www.54chen.com/688-wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes/</a> ]</p>
<p>选取CentOS，因为它是号称最安全及性能都相对较好的Linux系统。系统内存128m，系统用掉30m，有100m左右可用（如图1所示），swap已经有256M，硬盘为5G，除去系统后大约有4G可供捣腾。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg"><img class="alignleft size-full wp-image-689" title="图1" src="http://www.54chen.com/wp-content/uploads/2009/08/1.jpg" alt="" width="500" height="78" /></a><br />
图1。</p>
<p> </p>
<p>首先，在空白的系统上使用下面的命令，安装gcc等一堆工具和后面php会用到的一些包：</p>
<p><code>yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers</code></p>
<p>yum这一堆东西会有点慢，这里正好插播一下，mysql的编译在128的内存下非常慢，所以呆会儿我们会采取直接yum，php、nginx都下源码编译，经过以往的经验eAccelerator、Xcache和Zend Optimizer这三者，最好是用eAccelerator搭配Zend Optimizer能给php加速得到最佳效果，当然了，Zend Optimizer需要Zend Guard来搭配，而后者是收费的，伟大的中国人有伟大的破解。</p>
<p>我执行的时候耗时32分钟左右。</p>
<p>言归正传，继续：<br />
<code>wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz<br />
wget http://www.php.net/get/php-5.2.10.tar.gz/from/this/mirror<br />
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz<br />
wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2<br />
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz [nginx rewrite使用]</code></p>
<p>【安装<a href="http://www.54chen.com/19-mysql%e6%93%8d%e4%bd%9c%e8%a6%81%e7%82%b9%e6%95%b4%e7%90%86/">MySQL</a>】<br />
<code>yum install -y mysql-server<br />
启动MySQL:<br />
service mysqld start<br />
设置mysql数据库root帐号密码:<br />
mysqladmin -u root password 'newpassword' [引号内填密码]<br />
让mysql更安全：<br />
mysql -u root -p [此时会要求你输入刚刚设置的密码，输入后回车即可]</code></p>
<p>mysql&gt; DROP DATABASE test; [删除test数据库]<br />
mysql&gt; DELETE FROM mysql.user WHERE user = ''; [删除匿名帐户]<br />
mysql&gt;DELETE FROM mysql.user WHERE password = '';[删除无密码帐户]<br />
mysql&gt; FLUSH PRIVILEGES; [重载权限]</p>
<p>【优化MySQL】<br />
此时的mysql直接吃掉20m左右的内存，如图2所示。我们要对其进行优化，关掉<a href="http://www.54chen.com/358-mysql%e7%9a%84%e6%80%a7%e8%83%bd%e8%b0%83%e4%bc%98%e5%b7%a5%e5%85%b7%ef%bc%9a%e6%af%94mysqlreport%e6%9b%b4%e6%96%b9%e4%be%bf%e7%9a%84tuning-primersh/">innodb</a>。</p>
<p><a href="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg"><img class="alignleft size-full wp-image-691" title="图2" src="http://www.54chen.com/wp-content/uploads/2009/08/2.jpg" alt="" width="499" height="170" /></a>图2。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>vi /etc/my.cnf<br />
在后面增加如下内容：</p>
<p><code>skip-innodb<br />
[mysql]<br />
no-auto-rehash</code></p>
<p>[mysqld]<br />
user = mysql<br />
port = 3306<br />
open_files_limit = 600<br />
back_log = 20<br />
max_connections = 100<br />
max_connect_errors = 200<br />
table_cache = 60<br />
external-locking = FALSE<br />
max_allowed_packet = 16M<br />
sort_buffer_size = 128K<br />
join_buffer_size = 128K<br />
thread_cache_size = 10<br />
thread_concurrency = 8<br />
query_cache_size = 0M<br />
query_cache_limit = 2M<br />
query_cache_min_res_unit = 2k<br />
default_table_type = MyISAM<br />
thread_stack = 192K<br />
transaction_isolation = READ-UNCOMMITTED<br />
tmp_table_size = 512K<br />
max_heap_table_size = 32M<br />
long_query_time = 1<br />
log_long_format<br />
server-id = 1<br />
binlog_cache_size = 2M<br />
max_binlog_cache_size = 4M<br />
max_binlog_size = 512M<br />
expire_logs_days = 7<br />
key_buffer_size = 4M<br />
read_buffer_size = 1M<br />
read_rnd_buffer_size = 2M<br />
bulk_insert_buffer_size = 2M<br />
myisam_sort_buffer_size = 4M<br />
myisam_max_sort_file_size = 10G<br />
myisam_max_extra_sort_file_size = 10G<br />
myisam_repair_threads = 1<br />
myisam_recover</p>
<p>[mysqldump]<br />
quick<br />
max_allowed_packet = 16M</p>
<p>【重启MySQL】<br />
service mysqld restart<br />
再看mysql吃掉的内存，已经降低了四分之一，如图3所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg"><img class="alignleft size-full wp-image-692" title="图3" src="http://www.54chen.com/wp-content/uploads/2009/08/3.jpg" alt="" width="500" height="170" /></a>图3。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>【安装php】<br />
首先使用yum安装上mysql的开发包，供<a href="http://www.54chen.com/490-%e5%a6%82%e4%bd%95%e7%94%a8php%e4%bb%a3%e7%a0%81%e6%b8%85%e7%a9%basquid%e7%bc%93%e5%ad%98%e4%b8%8b%e7%9a%84%e6%8c%87%e5%ae%9a%e6%96%87%e4%bb%b6/">php</a>扩展mysql使用：<br />
<code>yum -y install mysql-devel<br />
安装patch工具：<br />
yum -y install patch<br />
tar zxvf php-5.2.10.tar.gz<br />
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1<br />
cd php-5.2.10<br />
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/usr/share/mysql --with-mysqli=/usr/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --without-pear<br />
make &amp;&amp; make install</code><br />
把pear手动装上(这个是5.2.10的一个bug，后面可能已经打补丁了)：<br />
curl http://pear.php.net/go-pear | /opt/php/bin/php<br />
cp php.ini-dist /opt/php/etc/php.ini</p>
<p>【安装eaccelerator】<br />
<code>tar jxvf eaccelerator-0.9.5.3.tar.bz2<br />
cd eaccelerator-0.9.5.3<br />
/opt/php/bin/phpize<br />
./configure --enable-eaccelerator=shared --with-php-config=/opt/php/bin/php-config<br />
make &amp;&amp; make install</code><br />
mkdir -p /opt/eaccelerator_cache<br />
vi /opt/php/etc/php.ini</p>
<p>添加下面的内容：<br />
<code>[eaccelerator]<br />
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"<br />
eaccelerator.shm_size="64"<br />
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"<br />
eaccelerator.enable="1"<br />
eaccelerator.optimizer="1"<br />
eaccelerator.check_mtime="1"<br />
eaccelerator.debug="0"<br />
eaccelerator.filter=""<br />
eaccelerator.shm_max="0"<br />
eaccelerator.shm_ttl="3600"<br />
eaccelerator.shm_prune_period="3600"<br />
eaccelerator.shm_only="0"<br />
eaccelerator.compress="1"<br />
eaccelerator.compress_level="9"</code></p>
<p> </p>
<p>【安装<a href="http://www.54chen.com/157-php%e4%bb%a3%e7%a0%81%e7%9a%84%e4%bc%98%e4%b8%8e%e5%8a%a3/">Zend</a> Optimizer】<br />
要去zend.com上注册用户名后进download页面下载，这里太弱智了，不知道zend是否有专门的产品人员，这种注册下载有什么意义，只是一堆死账号而已。<br />
下载ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
<code>tar -zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz<br />
cd ZendOptimizer-3.3.3-linux-glibc23-i386<br />
./install</code></p>
<p>运行过程中会要求你写些安装路径啥的，照着写就是。<br />
如果出现类似下面的错误：<br />
./install-tty: line 139: ./php: cannot execute binary file<br />
那说明你下错了包了，这种情况是因为你32位的系统下了64位的包或者是反过来。</p>
<p>【安装nginx】<br />
<code>tar -zxvf pcre-7.9.tar.gz<br />
cd pcre-7.9<br />
./configure<br />
make &amp;&amp; make install<br />
cd ..</code></p>
<p>tar zxvf nginx-0.7.61.tar.gz<br />
cd nginx-0.7.61<br />
./configure --user=www --group=www --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module<br />
make &amp;&amp; make install</p>
<p>增加www用户：<br />
groupadd www<br />
useradd -g www www</p>
<p>【优化php\nginx】<br />
1.优化php-fpm.conf<br />
<code>vi /opt/php/etc/php-fpm.conf<br />
修改log level为error:<br />
error<br />
修改max_children:<br />
5<br />
修改listen_address为unix socket方式运行：<br />
/tmp/php-cgi.sock</code></p>
<p>2.优化nginx.conf<br />
vi /opt/nginx/conf/nginx.conf<br />
在events中增加：<br />
<code>use epoll;<br />
在http中增加下面的代码，打开gzip：<br />
gzip on;<br />
gzip_min_length 1k;<br />
gzip_buffers 4 16k;<br />
gzip_http_version 1.0;<br />
gzip_comp_level 2;<br />
gzip_types text/plain application/x-javascript text/css application/xml;<br />
gzip_vary on;<br />
在使用php的server中使用unix socket通信方式：<br />
fastcgi_pass unix:/tmp/php-cgi.sock;</code></p>
<p>【设置开机启动】<br />
/sbin/chkconfig --add mysqld [在服务清单中添加mysql服务]<br />
/sbin/chkconfig mysqld on [设置mysql服务开机启动]</p>
<p>vi /etc/rc.locale<br />
加入两行：<br />
/opt/php/sbin/php-fpm start<br />
/opt/nginx/sbin/nginx</p>
<p>【误区提示】<br />
XEN更像物理服务器，会尽量把剩余的内存当成buffer和cache，所以看到下图的时候不要惊慌，其实内存都在cache里了。<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg"><img class="alignleft size-full wp-image-693" title="图4" src="http://www.54chen.com/wp-content/uploads/2009/08/x.jpg" alt="" width="500" height="94" /></a>图4</p>
<p> </p>
<p> </p>
<p>【wordpress专项优化】<br />
使用wp-super-cache插件，将页面生成html，省去php的开销，性能有提升。<br />
对照access log，刷新页面，看堵在什么地方</p>
<p>【几个建议】<br />
合并css js个数 并且压缩 速度提升明显<br />
wordpress没有任何插件的时候，效率是很不错的，但是有些不负责任的插件会导致整体看起来很慢，下面是一些常用的插件的问题：<br />
1.twitter tools插件：用来从后端取twitter数据的，这个插件搞了一个js一个css在head里，并且都是通过php生成的，两个php请求，让首页很慢。建议去掉（可能会影响自动化？没来得及分析细节）。<br />
2.wp-spamfree插件：用来做antispam的，这是一个动态生成的js，不知道为什么非常慢。建议换别的插件。</p>
<p>【结果展示】<br />
在完成上述一系列的操作后，http://54chen.com 我是陈科学院的打开速度已经非常迅速了，基本上一秒钟就能全部显示。内存还有40m空闲，如图5所示：<br />
<a href="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg"><img class="alignleft size-full wp-image-694" title="图5" src="http://www.54chen.com/wp-content/uploads/2009/08/5.jpg" alt="" width="500" height="79" /></a>图5</p>
<br><br>想快点找到作者也可以到Twitter上留言: <a href="https://www.twitter.com/54chen" target="_blank">@54chen</a><br>或者你懒得带梯子上墙，请到新浪微博：<a href="http://t.sina.com.cn/54chen" target="_blank">@54chen</a>]]></content:encoded>
			<wfw:commentRss>http://www.54chen.com/architecture/wordpress-nginx-php-cgi-mysql-memory-in-the-128m-to-install-and-optimize-the-vps-notes.html/feed</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
	</channel>
</rss>

