linux下安装PEAR,Zend Debugger和Smarty

来源:岁月联盟 编辑:exp 时间:2012-02-08
  虽然之前就在我的ubuntu11.04搭建了eclipse+PHP+MySQL+Apache,但到最近接触了PEAR和Amarty,想在上面再搞上这俩插件时才发现很多东西之前没装好,所以就搞了好久才把东西都弄上。顺手就记录了一下。
 
一、PEAR
 
    pear的安装其实挺简单的,他的官网也有非常详细的讲解。简化如下:
 
 1、安装,在终端敲入
 
1
$ sudo wget http://pear.php.net/go-pear.phar
2
$ sudo php go-pear.phar
2、检查pear是否工作,在终端敲入“pear”,如果正常的话应该显示下面的东西:
 
1
$pear
2
Commands:
3
build                  Build an Extension From C Source
4
bundle                 Unpacks a Pecl Package
5
channel-add            Add a Channel
6
channel-alias          Specify an alias to a channel name
7
channel-delete         Remove a Channel From the List
8
channel-discover       Initialize a Channel from its server
9
。。。
3、检查路径。在服务器根目录,即/var/www/ ,新建一个php文件,写入下面的内容:
 
1
<?php
2
    require_once 'System.php';
3
    var_dump(class_exists('System', false));
4
?>
    如果路径是正确的,那么由浏览器打开此文件应该会显示
 
1
bool(true)
    如果出现了warning,便是路径不对了,那么就要到php.ini文件里修改include_path。在终端敲入如下内容可以查找php.ini文件的位置
1
$ php --ini
    在终端敲入如下内容可以查找pear的位置
 
$ php -c /path/to/php.ini -r 'echo get_include_path()."/n";'
   修改完记得重启apache:
 
1
sudo /etc/init.d/apache2 restart
二、Smarty
 
1、在http://www.smarty.net/download 下载Smarty,然后找个方便的地方解压。
 
2、在服务器根目录新建一个Smarty的文件夹,将刚才解压的软件包下的lib目录里的文件复制过来。
 
3、在根目录下创建应用程序目录。在根目录下创建目录myapp(这个可以随便取的),在myapp下创建smarty目录。再在smarty目录下创建4个文件夹:templates,templates_c,cache和config。(虽然不知道为什么要这么建,但看起来似乎是必需的)。
 
4创建myapp/smarty.php文件,告诉PHP程序要包含的Smarty类文件和应用程序的位置
 
1
<?php
2
    $base_path=basename(dirname(__FILE__));
3
    require('/var/www/Smarty/Smarty.class.php');//这里是你复制lib目录下文件到的地方
4
    $smarty=new Smarty();
5
    $smarty->template_dir=$base_path.'/smarty/templates';
6
    $smarty->compile_dir=$base_path.'/smarty/templates_c';
7
    $smarty->cache_dir=$base_path.'/smarty/cache';
8
    $smarty->config_dir=$base_path.'/smarty/configs';
9
?>
    此后,require_once这个文件就可以用Smarty了。
 
三、smartypdt。
 
    smartypdt是一个让eclipse更好的地支持smarty的插件,包括语法高亮,代码补全等。但smartypdt要求eclipse用zend debugger,但我之前装的是Xdebug,只好卸了重装。
 
[Zend Debugger]
 
1、卸载xdebug
 
www.2cto.com
$ sudo apt-get remove php5-xdebug
2、下载Zend Debugger:http://downloads.zend.com/pdt/server-debugger/,解压后找到你的php版本对应的文件夹下的ZendDebugger.so。我的是PHP 5.3.5,所以找的是5_3_x_comp文件夹下的ZendDebugger.so,然后复制到/usr/lib/php5/20090626+lfs/目录下。
 
3、配置PHP.ini文件,加上
 
1
[Zend Debug]
2
zend_extension=/usr/lib/php5/20090626+lfs/ZendDebugger.so
4、将软件包里的dummy.php文件复制到服务器根目录下。
 
5、重启服务器
 
6、然后就是搞eclipse的事了。
 
    window->preferences->PHP->Debug->PHP Debuger 选择  Zend Debugger
 
    window->preferences->PHP->Editor->php Executables->Add,配置如下:
 
    Name:PHP 5.3.5 (CLI)(可以自己取一个)
 
    Executable path: /usr/bin/php
 
    SAPI Type: CLI
 
     PHP Debugger: Zend Debugger
 
    到这里,Zend dedebugger 就算是安装完成了。
 
[smartypdt]
 
1、在这里下载http://code.google.com/p/smartypdt/downloads/list
 
2、在eclipse下Help-> Install New Software->Add..->Archive ,选择你下载的smartypdt文件(不用解压),名字随便给一个就行。OK后如果“Group items by category”被选中了,取消他,然后就可以看到一个叫“Smarty Feature”的软件可以安装,后面的就按提示Next或Finish就可以了。
 
3、Window->Preferences->General->Content Type,检查HTML 和PHP Content Type是关联了*.tpl,如果是的话,取消他。
 
5、打开PHP Explore板块,选中PHP project,右键->Configure->Add Smarty Support
 
    到这里,就可以使用smartypdt了。