本文為原創作品,轉載請注明出處!
首先說明Yar是干什么的。
新浪著名的大神級人物鳥哥,開發的一個支持并行的PHP擴展。
源地址?http://www.laruence.com/2012/09/15/2779.html
其特點就是可以高效的封裝好供外部訪問的接口,用途嘛,
,你懂的。
下面開始實況直播,如何才能把大神的yar用上。
### 一、下載。
恩,沒錯,在那個文章的底部,鳥哥提供了github的[下載地址](https://github.com/laruence/yar)。
但是,這是不夠的,因為這個框架需要 一個名為?Msgpack 的[擴展](https://github.com/msgpack/msgpack-php),同樣的,這個也是鳥哥維護的,再次膜拜!!
### 二、msgpack。
恩。。。。。
貌似下載好發現里面都是寫.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
````
~~~
恩,我們發現原來這個可以通過pecl在線安裝
打開一個終端,輸入
~~~
pecl install msgpack
~~~
發現沒有成功,給的提示是這樣的
~~~
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還沒有穩定版本,按照上面的提示,我們這樣輸入
~~~
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
~~~
看來是我們對文件夾沒有寫入權限,下面我們切換到root用戶后重新執行上面的命令

內容太多,截下最后的一段吧。
~~~
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
~~~
下面的操作就是打開配置文件,把擴展寫到文件中去
~~~
sudo gedit /etc/php5/apache2/php.ini
~~~
然后重啟apache
~~~
sudo /etc/init.d/apache2 restart
~~~
查看phpinfo


到此為止,我們就安裝完了msgpack的PHP擴展。
### 三、Yar
解壓下載的 yar-master.zip 我們還是先看 README.md 這個文件,其實直接在github上看也是一樣的。。。。
安裝要求,要求安裝一下的php擴展,這就是上一步的重要性!
~~~
## 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命令直接進行安裝啊,貌似不是那么順利
~~~
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
~~~
在這里我們可以看到是由于我們缺少一個 re2c 0.13.4 或者更新的版本才行,還有,我們的curl模塊也不太符合要求,要求重裝一下。
下面開始解決問題!
我在這個地址里找到了 re2c?http://download.csdn.net/download/morre/5702707 ,在下面的解決過程中跳過了re2c的安裝,看來上面的只是警告,沒有太大問題。
讓我們回到yar的編譯
編譯需要?phpize,所以我們要安裝?phpize,安裝phpize需要運行
~~~
yum install php-devel
~~~
返回的提示是
~~~
程序“yum”尚未安裝。 您可以使用以下命令安裝:
sudo apt-get install yum
~~~
恩,所以先安裝yum,在安裝phpize,注意,安裝phpize的時候要以**root**用戶執行!
然后重新安裝了curl庫,重啟apache
~~~
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
~~~
sudo /etc/init.d/apache2 restart
下面再次執行pecl的安裝
pecl install yar
然后就沒有問題啦,經過短暫的等待,顯示下面的提示,就安裝完成啦!
~~~
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中并沒有看見對應的擴展。
- 前言
- php編寫RSS源
- PHP編寫rss源(續)
- ubuntu 上給PHP安裝擴展 Msgpack 和 Yar
- PHPCMS廣告模塊詳細分析——廣告的生成
- Yii配合Yar在php5.3.3環境下的錯誤以及解決方案
- 【Yaf】Yaf的環境安裝遇到的問題以及解決方案
- 【PHP擴展】centos給PHP安裝擴展
- 【MYSQL】PHPMYADMIN出現的問題以及解決方案
- 【PHP】阿里云升級PHP到5.5詳解
- 【phpMyAdmin】修改配置文件連接到其他服務器
- 【PHP】PHP5.4.0版本ChangeLog詳解(上)
- 【PHP】編譯安裝 PHP5.6.13遇到問題以及解決方案
- 【翻譯】PHP7——新特性
- 【PHP】數組foreach引發的小問題
- 【CURL】PHP的CURL開發項目最佳實踐
- 【PHP】PHP轉換圖片為ico格式源碼
- 【PHP】PHP圖像裁剪縮略裁切類源代碼及使用方法