本文為原創(chuàng)作品,,轉(zhuǎn)載請注明出處!
首先說明Yar是干什么的,。
新浪著名的大神級人物鳥哥,,開發(fā)的一個(gè)支持并行的PHP擴(kuò)展,。
源地址 http://www./2012/09/15/2779.html
其特點(diǎn)就是可以高效的封裝好供外部訪問的接口,,用途嘛,,,你懂的,。
下面開始實(shí)況直播,,如何才能把大神的yar用上。
一,、下載,。
恩,沒錯,,在那個(gè)文章的底部,,鳥哥提供了github的下載地址。
但是,,這是不夠的,因?yàn)檫@個(gè)框架需要 一個(gè)名為 Msgpack 的擴(kuò)展,,同樣的,,這個(gè)也是鳥哥維護(hù)的,再次膜拜??!
二、msgpack,。
恩,。。,。,。,。
貌似下載好發(fā)現(xiàn)里面都是寫.c .h 的文件,沒錯,,我們需要自己來編譯,!
1.msgpack
解壓壓縮包,直接看 README.md
- ## Install
-
- ### Install from PECL
- Msgpack is an PECL extension, thus you can simply install it by:
- ````
- pecl install msgpack
- ````
- ### Compile Msgpack from source
- ````
- $/path/to/phpize
- $./configure
- $make && make install
- ````
恩,,我們發(fā)現(xiàn)原來這個(gè)可以通過pecl在線安裝
打開一個(gè)終端,,輸入
發(fā)現(xiàn)沒有成功,給的提示是這樣的
- 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
- install failed
這是由于msgpack還沒有穩(wěn)定版本,,按照上面的提示,,我們這樣輸入
- pecl install channel://pecl.php.net/msgpack-0.5.5
還是沒有成功,但是提示變了
- 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
- Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user
看來是我們對文件夾沒有寫入權(quán)限,,下面我們切換到root用戶后重新執(zhí)行上面的命令
內(nèi)容太多,,截下最后的一段吧。
- Build process completed successfully
- Installing '/usr/lib/php5/20121212/msgpack.so'
- Installing '/usr/include/php5/ext/msgpack/php_msgpack.h'
- install ok: channel://pecl.php.net/msgpack-0.5.5
- configuration option "php_ini" is not set to php.ini location
- You should add "extension=msgpack.so" to php.ini
下面的操作就是打開配置文件,,把擴(kuò)展寫到文件中去
- sudo gedit /etc/php5/apache2/php.ini
然后重啟apache
- sudo /etc/init.d/apache2 restart
查看phpinfo
到此為止,,我們就安裝完了msgpack的PHP擴(kuò)展。
三,、Yar
解壓下載的 yar-master.zip 我們還是先看 README.md 這個(gè)文件,,其實(shí)直接在github上看也是一樣的。,。,。。
安裝要求,,要求安裝一下的php擴(kuò)展,,這就是上一步的重要性!
- ## Requirement
- - PHP 5.2+
- - Curl
- - Json
- - Msgpack (Optional)
安裝yar
- ### Install Yar
- Yar is an PECL extension, thus you can simply install it by:
- ```
- pecl install yar
- ```
看來我們也可以通過pecl命令直接進(jìn)行安裝啊,,貌似不是那么順利
- downloading yar-1.2.1.tgz ...
- Starting to download yar-1.2.1.tgz (35,174 bytes)
- .........done: 35,174 bytes
- 28 source files, building
- running: phpize
- Configuring for:
- PHP Api Version: 20121113
- Zend Module Api No: 20121212
- Zend Extension Api No: 220121212
- building in /tmp/pear/temp/pear-build-rootoSsn5u/yar-1.2.1
- running: /tmp/pear/temp/yar/configure
- checking for grep that handles long lines and -e... /bin/grep
- checking for egrep... /bin/grep -E
- checking for a sed that does not truncate output... /bin/sed
- checking for cc... cc
- checking whether the C compiler works... yes
- checking for C compiler default output file name... a.out
- checking for suffix of executables...
- checking whether we are cross compiling... no
- checking for suffix of object files... o
- checking whether we are using the GNU C compiler... yes
- checking whether cc accepts -g... yes
- checking for cc option to accept ISO C89... none needed
- checking how to run the C preprocessor... cc -E
- checking for icc... no
- checking for suncc... no
- checking whether cc understands -c and -o together... yes
- checking for system library directory... lib
- checking if compiler supports -R... no
- checking if compiler supports -Wl,-rpath,... yes
- checking build system type... x86_64-unknown-linux-gnu
- checking host system type... x86_64-unknown-linux-gnu
- checking target system type... x86_64-unknown-linux-gnu
- checking for PHP prefix... /usr
- 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
- checking for PHP extension directory... /usr/lib/php5/20121212
- checking for PHP installed headers prefix... /usr/include/php5
- checking if debug is enabled... no
- checking if zts is enabled... no
- checking for re2c... no
- configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
- checking for gawk... no
- checking for nawk... nawk
- checking if nawk is broken... no
- checking whether to enable yar support... yes, shared
- checking for curl protocol support... yes, shared
- checking for msgpack packager support... no
- checking for cURL in default path... not found
- configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
- ERROR: `/tmp/pear/temp/yar/configure' failed
在這里我們可以看到是由于我們?nèi)鄙僖粋€(gè) re2c 0.13.4 或者更新的版本才行,,還有,我們的curl模塊也不太符合要求,,要求重裝一下,。
下面開始解決問題!
我在這個(gè)地址里找到了 re2c http://download.csdn.net/download/morre/5702707 ,在下面的解決過程中跳過了re2c的安裝,,看來上面的只是警告,,沒有太大問題。
讓我們回到y(tǒng)ar的編譯
編譯需要 phpize,,所以我們要安裝 phpize,,安裝phpize需要運(yùn)行
返回的提示是
- 程序“yum”尚未安裝。 您可以使用以下命令安裝:
- sudo apt-get install yum
恩,所以先安裝yum,在安裝phpize,,注意,,安裝phpize的時(shí)候要以
root用戶執(zhí)行!
然后重新安裝了curl庫,,重啟apache
- sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
sudo /etc/init.d/apache2 restart
下面再次執(zhí)行pecl的安裝
pecl install yar
然后就沒有問題啦,,經(jīng)過短暫的等待,顯示下面的提示,,就安裝完成啦,!
- Build process completed successfully
- Installing '/usr/lib/php5/20121212/yar.so'install ok:
- 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,。
- sudo gedit /etc/php5/apache2/php.ini
- sudo /etc/init.d/apache2 restart
重啟之后,在phpinfo中并沒有看見對應(yīng)的擴(kuò)展,。