<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://www.majordojo.com/projects/FeedManager/atom.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html" />
  <link rel="self" type="application/atom+xml" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html" />
  <id>tag:www.thinkjam.org,2009:/zoptuno//2/tag:www.thinkjam.org,2006:/zoptuno//2.370-</id>
  <updated>2009-09-21T03:11:07Z</updated>
  <title>Comments for 自己动手，在DreamHost上安装所需的Perl模块</title>
  <subtitle>My think. My dream.</subtitle>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.31-zh-cn</generator>
  <entry>
    <id>tag:www.thinkjam.org,2006:/zoptuno//2.370</id>
    <link rel="alternate" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://www.thinkjam.org/loveblog/batom.cgi/weblog/blog_id=2/entry_id=370" title="自己动手，在DreamHost上安装所需的Perl模块" />
    <published>2006-09-19T14:16:09Z</published>
    <updated>2008-04-22T04:45:53Z</updated>
    <title>自己动手，在DreamHost上安装所需的Perl模块</title>
    <summary>发现自己是越来越喜爱Dreamhost的虚拟主机了。SSH支持和超强的可定制性，...</summary>
    <author>
      <name>平生一笑</name>
      <uri>http://www.thinkjam.org/zoptuno</uri>
    </author>
    
    <category term="服务器" />
    
    <content type="html" xml:lang="en" xml:base="http://www.thinkjam.org/zoptuno/">
      <![CDATA[<p id="fp">发现自己是越来越喜爱<a href="http://www.dreamhost.com" target="_blank">Dreamhost</a>的虚拟主机了。SSH支持和超强的可定制性，使Dreamhost的虚拟空间俨然化身成为可自主维护的独立服务器。这不，我今天就自己动手，在Dreamhost主机上编译安装了<a href="http://www.perl.com/" target="_blank">Perl</a>的<a href="http://cgicache.sourceforge.net/" target="_blank">CGI::Cache</a>模块，让本来没有安装相应模块的虚拟空间，也实现了<a href="http://www.sixapart.com/movabletype/" target="_blank">Movable Type</a> <a href="http://www.thinkjam.org/zoptuno/archives/2006/09/mt-xsearch-tag.html#more" target="_blank">MT-XSearch Tag搜索</a>的缓存化。</p>

<p>由于我们是以非超级用户身份登录Dreamhost的，因此在安装Perl模块时，还颇有些技巧可言。具体来说，整个安装过程是这样的：</p>]]>
      <![CDATA[<p><strong>1.以SSH方式登录到Dreamhost</strong></p>

<p>如果你是Windows用户，可以使用SSH客户端软件，譬如<a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">PuTTY</a>连接Dreamhost主机。如果是Linux用户，那就更加简单了，在shell下直接输入"ssh 你的域名"即可。</p>

<p><strong>2.下载<a href="http://cgicache.sourceforge.net/" target="_blank">CGI::Cache</a>源码包</strong></p>

<p>非超级用户的身份决定了我们不能以自动方式安装Perl模块，只能采用手工编译来实现。因此，请在<a href="http://search.cpan.org/" target="_blank">Search CPAN</a>搜索CGI::Cache，找到后复制其下载地址，在SSH终端输入"<em>wget http://search.cpan.org/CPAN/authors/id/D/DC/DCOPPIT/CGI-Cache-1.4200.tar.gz</em>"，将CGI::Cache的源码包下载到服务器上。</p>

<p><strong>3.解压缩CGI::Cache源码包</strong></p>

<blockquote>tar zxvf CGI-Cache-1.4200.tar.gz</blockquote>

<p>多用用Linux下的Tab键，自动补全，呵呵。</p>

<p><strong>4.准备Makefile</strong></p>

<p>由于不是超级用户，这里需要指定Perl模块要安装到的目录，例如我将Perl模块安装到了自己hoome目录的CPAN文件夹下：</p>

<blockquote>perl Makefile.PL PREFIX=/home/<em>user</em>/CPAN</blockquote>

<p>其中，<em>user</em>为你的home目录名。此时，屏幕会输出一些信息。如果没有错误，则可以进入下一步；如果有错误，请仔细观察，通常是缺少某些需要的模块，需要先安装此模块。若使用Dreamhost主机，这里会提示缺少Tie:Restore模块。</p>

<p><strong>5.安装<a href="http://search.cpan.org/dist/Tie-Restore/" target="_blank">Tie:Restore</a>模块</strong></p>

<p>同样从<a href="http://search.cpan.org/" target="_blank">Search CPAN</a>搜索下载<a href="http://search.cpan.org/dist/Tie-Restore/" target="_blank">Tie:Restore</a>模块的源码包，并依次执行下面命令安装。</p>

<blockquote>wget http://search.cpan.org/CPAN/authors/id/R/RO/ROBWALKER/Tie-Restore-0.11.tar.gz<br />
tar zxvf Tie-Restore-0.11.tar.gz<br />
cd Tie-Restore-0.11<br />
perl Makefile.PL PREFIX=/home/<em>user</em>/CPAN<br />
make<br />
make test<br />
make install</blockquote>

<p><strong>6.指定Perl模块目录搜索路径</strong></p>

<p>即使你安装好<a href="http://search.cpan.org/dist/Tie-Restore/" target="_blank">Tie:Restore</a>模块，再次回到CGI::Cache的目录，重新生成Makefile，还是会提示缺少Tie::Restore，这是由于系统并不知道你在哪个目录中添加了新模块，它们只会搜索默认的路径，我们需要将新的目录添加到Perl模块目录搜索路径中，才能够解决依赖性问题。</p>

<p>在shell下输入：</p>

<blockquote>export PERL5LIB=/home/<em>user</em>/CPAN/share/perl/5.8.4</blockquote>

<p>再输入：</p>

<blockquote>perl -V</blockquote>

<p>你将会看到/home/<em>user</em>/CPAN/share/perl/5.8.4加入了@INC，也就是说Perl会从此目录扫描模块了。</p>

<p>你还可以将这些命令加入.bashrc 文件， 当下次启动shell的时候，环境将会自动为你准备好相应的路径。对Dreamhost主机来说，应该这样做：</p>

<blockquote>nano .bashrc<br />
;在启动的编辑器中加入上面的命令，按Ctrl+X保存并退出

<p>nano .bash_profile<br />;在启动的编辑器最后面加上. .bashrc</blockquote></p>

<p>这里用了Dreamhost官方推荐的<a href="http://linuxreviews.org/man/nano/" target="_blank">nano</a>编辑器，你自然可以用顺手的vi或vim之流。<br />
<strong><br />
7.完成CGI::Cache的安装</strong></p>

<p>回到之前，用cd命令切换回CGI::Cache源码包的解压目录，输入以下命令安装此模块。</p>

<blockquote>perl Makefile.PL PREFIX=/home/<em>user</em>/CPAN<br />
make<br />
make test<br />
make install</blockquote>

<p><strong>8.模块的使用</strong></p>

<p>此时，模块已经安装完毕。如果在shell下直接运行Perl程序，则模块可以正常调用；但若是在浏览器中运行，由于我们此前设置的路径仅对当前用户起作用，Perl程序还是无法调用新添加的模块。解决的方法很简单，就是在你的脚本最上方加入要调用的模块的路径，这里应该是：</p>

<blockquote>use lib '/home/<em>user</em>/CPAN/share/perl/5.8.4'</blockquote>

<p>对于<a href="http://www.sixapart.com/movabletype/" target="_blank">Movable Type</a>，还可以把刚才编译的模块（例子中是在/home/<em>user</em>/CPAN/share/perl/5.8.4目录下）转移到Movable Type脚本目录的exlib文件夹下，这样无须修改脚本，新模块调用也能完成。</p>

<p>采用此方法，你还可以添加更多需要的Perl模块。</p>

<p>Dreamhost给了我们很大的自由度，我们可以用它尝试各种各样好玩的新玩意。不过Dreamhost续费真的比较贵，所以俺申请了一个<a href="http://www.dreamhost.com/donate.cgi?id=5390" target="_blank">捐助代码</a>，希望有能力的朋友能够帮助让<a href="http://www.thinkjam.org" target="_blank">原生脑浆</a>继续在Dreamhost上运行。</p>

<p><a href="http://www.dreamhost.com/donate.cgi?id=5390" target="_blank"><img border="0" alt="Donate towards my web hosting bill!" src="https://secure.newdream.net/donate4.gif" /></a></p>

<p>最后提一下，<a href="http://www.anysql.net/" target="_blank">AnySQL.Net</a>修改了Movable Type默认的Search代码，实现了<a href="http://www.anysql.net/2006/09/tag_search_cache.html" target="_blank">通过Cache提升MT基于Tag搜索的速度</a>，您要是不想这么麻烦，或者没有用Dreamhost的主机，对占用资源巨大的Movable Type搜索来说，anysql的方案真的是很好的解决办法。</p>]]>
    </content>
  </entry>

  <entry>
    <id>tag:www.thinkjam.org,2006:/zoptuno//2.370-comment:2289</id>
    <thr:in-reply-to ref="tag:www.thinkjam.org,2006:/zoptuno//2.370" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html"/>
    <link rel="alternate" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html#c2289" />
    <title>Comment from 墨神的凡龛 on 2006-09-20</title>
    <author>
        <name>墨神的凡龛</name>
<!--        <uri>http://www.thinkjam.org/mercury/</uri> -->
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.thinkjam.org/mercury/">
	<![CDATA[<p>哈哈，貌似托儿～</p>]]>
    </content>
    <published>2006-09-19T16:26:24Z</published>
    <updated>2006-09-19T16:26:24Z</updated>
  </entry>

  <entry>
    <id>tag:www.thinkjam.org,2006:/zoptuno//2.370-comment:2290</id>
    <thr:in-reply-to ref="tag:www.thinkjam.org,2006:/zoptuno//2.370" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html"/>
    <link rel="alternate" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html#c2290" />
    <title>Comment from caicairooms on 2006-09-20</title>
    <author>
        <name>caicairooms</name>
<!--         -->
    </author>
    <content type="html" xml:lang="en" xml:base="">
	<![CDATA[<p>呵呵，BBS的程序不错，就是不清楚是否有使用的版权。</p>]]>
    </content>
    <published>2006-09-20T01:44:32Z</published>
    <updated>2006-09-20T01:44:32Z</updated>
  </entry>

  <entry>
    <id>tag:www.thinkjam.org,2006:/zoptuno//2.370-comment:2291</id>
    <thr:in-reply-to ref="tag:www.thinkjam.org,2006:/zoptuno//2.370" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html"/>
    <link rel="alternate" type="text/html" href="http://www.thinkjam.org/zoptuno/archives/2006/09/dreamhost-perl-module-install.html#c2291" />
    <title>Comment from sleetdrop on 2006-09-21</title>
    <author>
        <name>sleetdrop</name>
<!--        <uri>http://blog.vetcafe.net</uri> -->
    </author>
    <content type="html" xml:lang="en" xml:base="http://blog.vetcafe.net">
	<![CDATA[<p>Not bad.<br />
mark.</p>]]>
    </content>
    <published>2006-09-21T05:59:52Z</published>
    <updated>2006-09-21T05:59:52Z</updated>
  </entry>

</feed>
