分享

ubuntu 上给PHP安装扩展 Msgpack 和 Yar

 昵称11482448 2014-05-28

本文为原创作品,转载请注明出处!


首先说明Yar是干什么的。


新浪著名的大神级人物鸟哥,开发的一个支持并行的PHP扩展。

源地址 http://www./2012/09/15/2779.html


其特点就是可以高效的封装好供外部访问的接口,用途嘛,偷笑,你懂的。


下面开始实况直播,如何才能把大神的yar用上。


一、下载。


恩,没错,在那个文章的底部,鸟哥提供了github的下载地址


但是,这是不够的,因为这个框架需要 一个名为 Msgpack 扩展,同样的,这个也是鸟哥维护的,再次膜拜!!


二、msgpack。


恩。。。。。


貌似下载好发现里面都是写.c .h 的文件,没错,我们需要自己来编译!


1.msgpack

解压压缩包,直接看 README.md 

  1. ## Install  
  2.   
  3. ### Install from PECL  
  4. Msgpack is an PECL extension, thus you can simply install it by:  
  5. ````  
  6. pecl install msgpack  
  7. ````  
  8. ### Compile Msgpack from source  
  9. ````  
  10. $/path/to/phpize  
  11. $./configure   
  12. $make && make install  
  13. ````  

恩,我们发现原来这个可以通过pecl在线安装

打开一个终端,输入

  1. pecl install msgpack  

发现没有成功,给的提示是这样的

  1. Failed to download pecl/msgpack within preferred state "stable", latest release is version 0.5.5, stability "beta", use "channel://pecl.php.net/msgpack-0.5.5" to install  
  2. install failed  

这是由于msgpack还没有稳定版本,按照上面的提示,我们这样输入

  1. pecl install  channel://pecl.php.net/msgpack-0.5.5  

还是没有成功,但是提示变了

  1. WARNING: configuration download directory "/build/buildd/php5-5.5.3+dfsg/pear-build-download" is not writeable.  Change download_dir config variable to a writeable dir to avoid this warning  
  2. Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user  

看来是我们对文件夹没有写入权限,下面我们切换到root用户后重新执行上面的命令


大笑内容太多,截下最后的一段吧。


  1. Build process completed successfully  
  2. Installing '/usr/lib/php5/20121212/msgpack.so'  
  3. Installing '/usr/include/php5/ext/msgpack/php_msgpack.h'  
  4. install ok: channel://pecl.php.net/msgpack-0.5.5  
  5. configuration option "php_ini" is not set to php.ini location  
  6. You should add "extension=msgpack.so" to php.ini  

下面的操作就是打开配置文件,把扩展写到文件中去

  1. sudo gedit /etc/php5/apache2/php.ini  

然后重启apache

  1. sudo /etc/init.d/apache2 restart  

查看phpinfo


大笑到此为止,我们就安装完了msgpack的PHP扩展。



三、Yar


解压下载的 yar-master.zip 我们还是先看 README.md 这个文件,其实直接在github上看也是一样的。。。。


安装要求,要求安装一下的php扩展,这就是上一步的重要性!

  1. ## Requirement  
  2. - PHP 5.2+  
  3. - Curl  
  4. - Json  
  5. - Msgpack (Optional)  


安装yar

  1. ### Install Yar   
  2. Yar is an PECL extension, thus you can simply install it by:  
  3. ```  
  4. pecl install yar  
  5. ```  

看来我们也可以通过pecl命令直接进行安装啊,貌似不是那么顺利

  1. downloading yar-1.2.1.tgz ...  
  2. Starting to download yar-1.2.1.tgz (35,174 bytes)  
  3. .........done: 35,174 bytes  
  4. 28 source files, building  
  5. running: phpize  
  6. Configuring for:  
  7. PHP Api Version:         20121113  
  8. Zend Module Api No:      20121212  
  9. Zend Extension Api No:   220121212  
  10. building in /tmp/pear/temp/pear-build-rootoSsn5u/yar-1.2.1  
  11. running: /tmp/pear/temp/yar/configure  
  12. checking for grep that handles long lines and -e... /bin/grep  
  13. checking for egrep... /bin/grep -E  
  14. checking for a sed that does not truncate output... /bin/sed  
  15. checking for cc... cc  
  16. checking whether the C compiler works... yes  
  17. checking for C compiler default output file name... a.out  
  18. checking for suffix of executables...  
  19. checking whether we are cross compiling... no  
  20. checking for suffix of object files... o  
  21. checking whether we are using the GNU C compiler... yes  
  22. checking whether cc accepts -g... yes  
  23. checking for cc option to accept ISO C89... none needed  
  24. checking how to run the C preprocessor... cc -E  
  25. checking for icc... no  
  26. checking for suncc... no  
  27. checking whether cc understands -c and -o together... yes  
  28. checking for system library directory... lib  
  29. checking if compiler supports -R... no  
  30. checking if compiler supports -Wl,-rpath,... yes  
  31. checking build system type... x86_64-unknown-linux-gnu  
  32. checking host system type... x86_64-unknown-linux-gnu  
  33. checking target system type... x86_64-unknown-linux-gnu  
  34. checking for PHP prefix... /usr  
  35. checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib  
  36. checking for PHP extension directory... /usr/lib/php5/20121212  
  37. checking for PHP installed headers prefix... /usr/include/php5  
  38. checking if debug is enabled... no  
  39. checking if zts is enabled... no  
  40. checking for re2c... no  
  41. configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.  
  42. checking for gawk... no  
  43. checking for nawk... nawk  
  44. checking if nawk is broken... no  
  45. checking whether to enable yar support... yes, shared  
  46. checking for curl protocol support... yes, shared  
  47. checking for msgpack packager support... no  
  48. checking for cURL in default path... not found  
  49. configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/  
  50. ERROR: `/tmp/pear/temp/yar/configure' failed  

在这里我们可以看到是由于我们缺少一个 re2c 0.13.4 或者更新的版本才行,还有,我们的curl模块也不太符合要求,要求重装一下。


下面开始解决问题!


我在这个地址里找到了 re2c http://download.csdn.net/download/morre/5702707 ,在下面的解决过程中跳过了re2c的安装,看来上面的只是警告,没有太大问题。


让我们回到yar的编译


编译需要 phpize,所以我们要安装 phpize,安装phpize需要运行

  1. yum install php-devel  

返回的提示是

  1. 程序“yum”尚未安装。 您可以使用以下命令安装:  
  2. sudo apt-get install yum  

恩,所以先安装yum,在安装phpize,注意,安装phpize的时候要以root用户执行!


然后重新安装了curl库,重启apache


  1. sudo apt-get install curl libcurl3 libcurl3-dev php5-curl  

sudo /etc/init.d/apache2 restart

下面再次执行pecl的安装

pecl install yar

然后就没有问题啦,经过短暂的等待,显示下面的提示,就安装完成啦!

  1. Build process completed successfully  
  2. Installing '/usr/lib/php5/20121212/yar.so'install ok:   
  3. channel://pecl.php.net/yar-1.2.1configuration option "php_ini" is not set to php.ini locationYou should add "extension=yar.so" to php.ini  


下面的步骤和上次一样,修改配置文件,重启apache。

  1. sudo gedit /etc/php5/apache2/php.ini  
  2. sudo /etc/init.d/apache2 restart  


重启之后,在phpinfo中并没有看见对应的扩展。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多