<?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>ProjeKt D.K &#187; MySQL</title>
	<atom:link href="http://blog.punkid.org/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.punkid.org</link>
	<description>Where We ROT!</description>
	<lastBuildDate>Sun, 04 Jul 2010 07:51:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<atom:link rel='hub' href='http://blog.punkid.org/?pushpress=hub'/>
		<item>
		<title>Gentoo 使用笔记 Part 4</title>
		<link>http://blog.punkid.org/2007/04/10/gentoo-notes-part-4/</link>
		<comments>http://blog.punkid.org/2007/04/10/gentoo-notes-part-4/#comments</comments>
		<pubDate>Tue, 10 Apr 2007 13:37:52 +0000</pubDate>
		<dc:creator>punkid</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[LAMPP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://blog.punkid.org/2007/04/10/gentoo-notes-part-4/</guid>
		<description><![CDATA[往期回顾: Gentoo 使用笔记 Part 1 Gentoo 使用笔记 Part 2 Gentoo 使用笔记 Part 3 在Gentoo下打造LAMPP 最终还是选择了自己编译LAMPP平台，放弃了已整合好的XAMPP For Linux，执行效率和启动速度有了很大的提高。 安装LAMPP 添加以下use到 /etc/portage/package.use 中 net-www/apache apache2 dev-lang/php apache2 bzip2 gd mysql xml xmlrpc zip ctype pcre session unicode #其中php里的有些use不一定是必须的，不过这些use基本上都是常用的或是将来可能会用到的 编译apache和mysql # emerge apache mysql 在编译php前先修改下/etc/conf.d/apache2，加入php5的模块选项 APACHE2_OPTS=&#34;-D DEFAULT_VHOST -D PHP5&#34; 然后编译php和phpmyadmin吧 # emerge dev-lang/php phpmyadmin 设置LAMPP Gentoo下的Apache已经设置的很好了，基本上无须修改就能使用了。 在使用MySQL前还需要进行初始化设置，执行#emerge --config [...]]]></description>
			<content:encoded><![CDATA[<h3>往期回顾:</h3>
<ol>
<li><a href="http://pp.punkid.org/2006/09/30/gentoo-notes-part-1/" title="Gentoo 使用笔记 Part 1">Gentoo 使用笔记 Part 1</a></li>
<li><a href="http://pp.punkid.org/2006/09/30/gentoo-notes-part-2/" title="Gentoo 使用笔记 Part 2">Gentoo 使用笔记 Part 2</a></li>
<li><a href="http://pp.punkid.org/2006/10/09/gentoo-notes-part-3/" title="Gentoo 使用笔记 Part 3">Gentoo 使用笔记 Part 3</a></li>
</ol>
<h3>在Gentoo下打造LAMPP</h3>
<p>最终还是选择了自己编译<abbr title="Linux+Apache+MySQL+PHP+phpMyAdmin">LAMPP</abbr>平台，放弃了已整合好的<a href="http://www.apachefriends.org/en/xampp-linux.html" title="XAMPP For Linux">XAMPP For Linux</a>，执行效率和启动速度有了很大的提高。</p>
<h4>安装LAMPP</h4>
<p>添加以下use到 /etc/portage/package.use 中</p>
<pre class="bash">net-www<span style="color: #000000; font-weight: bold;">/</span>apache apache2
dev-lang<span style="color: #000000; font-weight: bold;">/</span>php apache2 <span style="color: #c20cb9; font-weight: bold;">bzip2</span> gd mysql xml xmlrpc <span style="color: #c20cb9; font-weight: bold;">zip</span> ctype pcre session unicode
<span style="color: #666666; font-style: italic;">#其中php里的有些use不一定是必须的，不过这些use基本上都是常用的或是将来可能会用到的</span></pre>
<p><span id="more-56"></span><br />
编译apache和mysql</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># emerge apache mysql</span></pre>
<p>在编译php前先修改下/etc/conf.d/apache2，加入php5的模块选项</p>
<pre class="bash"><span style="color: #007800;">APACHE2_OPTS</span>=<span style="color: #ff0000;">&quot;-D DEFAULT_VHOST -D PHP5&quot;</span></pre>
<p>然后编译php和phpmyadmin吧</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># emerge dev-lang/php phpmyadmin</span></pre>
<h4>设置LAMPP</h4>
<p>Gentoo下的Apache已经设置的很好了，基本上无须修改就能使用了。</p>
<p>在使用MySQL前还需要进行初始化设置，执行<code>#emerge --config mysql</code>进行设置，然后启动MySQL，进行安全设置:</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># /etc/init.d/mysql start</span>
<span style="color: #666666; font-style: italic;"># mysql_secure_installation</span></pre>
<p>设置phpMyAdmin:</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># mysql -u root -p&lt; /usr/share/webapps/phpmyadmin/2.10.0.2/sqlscripts/mysql/2.10.0.2_create.sql</span>
<span style="color: #666666; font-style: italic;"># mkdir /var/www/localhost/htdocs/phpmyadmin/config</span>
<span style="color: #666666; font-style: italic;"># chmod o+rw /var/www/localhost/htdocs/phpmyadmin/config</span>
<span style="color: #666666; font-style: italic;"># cp /var/www/localhost/htdocs/phpmyadmin/config.sample.inc.php /var/www/localhost/htdocs/phpmyadmin/config/config.inc.php</span>
<span style="color: #666666; font-style: italic;"># chown -R apache:apache /var/www/localhost/htdocs/phpmyadmin/config</span></pre>
<p>OK,启动Apache和MySQL试试看，看看能不能进入phpMyAdmin进行数据库操作，你也可以建立一个内容为&lt;?php phpinfo() ?&gt;的php文件来查看apache是否正常启用了php。</p>
<h4>小技巧</h4>
<p>我实在不喜欢那个/var/www/localhost/htdocs的目录，操作起来太不方便，我也不愿意去修改httpd.conf文件。我的做法是在/home目录下新建个web文件夹，设置owner为自己的普通日常用户，然后做个链接到htdocs目录里就是了。</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># mkdir /home/web</span>
<span style="color: #666666; font-style: italic;"># chown -R punkid:apache /home/web</span>
<span style="color: #000000; font-weight: bold;">/*</span>我选择把wordpress什么的都放到这个web目录下了，并设置所有者为apache组和个人用户<span style="color: #000000; font-weight: bold;">*/</span>
<span style="color: #666666; font-style: italic;"># chmod ug+rw -R /home/web</span>
<span style="color: #000000; font-weight: bold;">/*</span>给予apache组和个人用户读写权限<span style="color: #000000; font-weight: bold;">*/</span></pre>
<p>然后切换到htdocs文件夹下做几个链接进来吧</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># cd /var/www/localhost/htdocs</span>
<span style="color: #666666; font-style: italic;"># ln -sf /home/web/wordpress wp</span>
<span style="color: #666666; font-style: italic;"># ln -sf /home/web/drupal drupal</span></pre>
<p>这样我输入<code>http://localhost/wp</code>时就可以访问/home/web/wordpress下的wp blog了，同理<code>http://localhost/drupal</code>则进入了/home/web/drupal的目录操作</p>
<p>顺带把win下的几个音乐，电影资源文件夹也链接进来以便给我的朋友们下载</p>
<pre class="bash"><span style="color: #666666; font-style: italic;"># ln -sf /mnt/win_f/Audio Audio</span>
<span style="color: #666666; font-style: italic;"># ln -sf /mnt/win_f/Movie Movie</span></pre>
<p>如果你不想别人从外部访问的话，在你不希望别人访问的文件夹下建立个<code>.htaccess</code>的隐藏文件，输入以下内容:</p>
<pre class="apache"><span style="color: #00007f;">Order</span> <span style="color: #00007f;">deny</span>,<span style="color: #00007f;">allow</span>
<span style="color: #00007f;">Deny</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
<span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> 127.0.0.1</pre>
<p>如果你不愿意把apache和MySQL都加入开机启动程序，而又嫌分别输入<code>/etc/init.d/apache start</code>和 <code>/etc/init.d/mysql start</code>麻烦的话，可以在/etc/init.d/下建立一个lampp启动脚本。你在该目录下输入<code>vi lampp</code>会自动帮你填补好脚本框架的，我的脚本是这样的(有点粗糙，不过能用:D )</p>
<pre class="bash"><span style="color: #666666; font-style: italic;">#!/sbin/runscript</span>
<span style="color: #666666; font-style: italic;"># Copyright 1999-2007 Gentoo Foundation</span>
<span style="color: #666666; font-style: italic;"># Distributed under the terms of the GNU General Public License v2</span>
<span style="color: #666666; font-style: italic;"># $Header: $</span>
&nbsp;
depend<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    need net
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
svc_start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    ebegin <span style="color: #ff0000;">&quot;Starting LAMPP&quot;</span>
    <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 start <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql start
    eend <span style="color: #800000;">${?}</span> <span style="color: #ff0000;">&quot;Failed to start LAMPP&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
svc_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    ebegin <span style="color: #ff0000;">&quot;Stopping LAMPP&quot;</span>
    <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 stop <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql stop
    eend <span style="color: #800000;">${?}</span> <span style="color: #ff0000;">&quot;Failed to stop LAMPP&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
svc_restart<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    ebegin <span style="color: #ff0000;">&quot;Restarting LAMPP&quot;</span>
    <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache2 restart <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql restart
    eend <span style="color: #800000;">${?}</span> <span style="color: #ff0000;">&quot;Failed to restart LAMPP&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre>
<p>执行<code>/etc/init.d/lampp start</code>,<code>/etc/init.d/lampp stop</code>,<code>/etc/init.d/lampp restart</code>即可启用，停用以及重新启动apache和MySQL。</p>
<p>另外，我自己用python写了个小程序，用来监视apache的访问记录的。你可以copy以下代码到任意.py文件中，加入执行权限( <code>chmod +x logmonitor.py</code> )就可以运行了</p>
<pre class="python"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>,<span style="color: #dc143c;">time</span>
&nbsp;
today = <span style="color: #dc143c;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%d/%b/%Y'</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;">#specify the date format</span>
log_path = <span style="color: #483d8b;">'/usr/lib/apache2/logs/access_log'</span> <span style="color: #808080; font-style: italic;">#如果你更改了apache log存放路径设置的话，请更改此处地址</span>
logline = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cat %s | grep '%s' | wc -l&quot;</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span>log_path,today<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
showlog = <span style="color: #483d8b;">&quot;tail -f -n 20 %s | grep '%s'&quot;</span> <span style="color: #66cc66;">%</span><span style="color: black;">&#40;</span>log_path,today<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> logline.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'0'</span><span style="color: black;">&#41;</span>:
   <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'no activies recently'</span> <span style="color: #808080; font-style: italic;">#如果当天没有活动记录，则不显示</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
   <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span>showlog<span style="color: black;">&#41;</span></pre>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.punkid.org/2008/05/26/tips-in-aggregate/" title="Tips in Aggregate (May 26, 2008)">Tips in Aggregate</a> (1)</li>
	<li><a href="http://blog.punkid.org/2009/03/23/free-sms-notification-on-amule-completed-download/" title="给aMule增加下载完成短信通知功能 (March 23, 2009)">给aMule增加下载完成短信通知功能</a> (9)</li>
	<li><a href="http://blog.punkid.org/2008/11/09/why-to-upgrade-to-libgpod-svn-build/" title="Why to Upgrade to Libgpod SVN Build (November 9, 2008)">Why to Upgrade to Libgpod SVN Build</a> (3)</li>
	<li><a href="http://blog.punkid.org/2007/11/10/why-i-love-gentoo-and-its-community-so-much/" title="Why I &lt;3 Gentoo and Its Community So Much (November 10, 2007)">Why I &lt;3 Gentoo and Its Community So Much</a> (6)</li>
	<li><a href="http://blog.punkid.org/2008/08/23/use-gentoo-bashrc-under-archlinux/" title="Use gentoo-bashrc under Archlinux (August 23, 2008)">Use gentoo-bashrc under Archlinux</a> (7)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.punkid.org/2007/04/10/gentoo-notes-part-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
