**
前言
**
Mac 默認的apache php環境下 安裝 phpredis的詳細步驟,基本上所有坑都趟過了 。。。
**
一、準備
**
如果沒安裝 autoconf, phpize 的時候會報錯:
----------------------------------------------------------------------
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
----------------------------------------------------------------------
1.1、如果沒安裝homebrew,先安裝homebrew,命令如下:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
1.2、安裝autoconf
- 1.2.1、安裝 autoconf
brew install autoconf
----------------------------------------------------------------------
Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
sudo chown -R $(whoami) /usr/local/Cellar
----------------------------------------------------------------------
//用戶及權限錯誤:(考慮到安全性,改完權限及用戶以後還得改回來)
$ ls -l /usr/local
----------------------------------------------------------------------
drwxr-xr-x 5 root wheel 170 8 5 17:10 Cellar
----------------------------------------------------------------------
// 解釋 開頭的 d 表示目錄,跟權限無關,忽略,權限數值(讀:4,寫:2,執行:1);rwx:可讀、可寫、可執行、(2+1+4=7);r-x:可讀、不可寫、可執行(4+0+1=5);r-x:可讀、不可寫、可執行(4+0+1=5); 好了,默認的權限是755 改完777以後要改回755
- 1.2.2、更改權限(把權限改成777)
$ sudo chmod -R 777 /usr/local/Cellar
- 1.2.3、更改用戶(可以輸入 whoami 查看當前用戶,用戶改成 zhangwei )
$ sudo chown -R zhangwei /usr/local/Cellar
- 1.2.4、 再次安裝 autoconf
$ brew install autoconf
----------------------------------------------------------------------
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.
You can try again using:
brew link autoconf
----------------------------------------------------------------------
//好吧,/usr/local/opt 目錄不可寫,但是 autoconf已經安裝完畢,只是沒關聯到brew。
- 1.2.5、關聯autoconf:
brew link autoconf
----------------------------------------------------------------------
Linking /usr/local/Cellar/autoconf/2.69... 19 symlinks created
----------------------------------------------------------------------
//關聯成功,注意:這裏不能用 sudo brew link autoconf 因爲系統認爲 sudo brew 是危險操作
1.3、下載並解壓phpredis
下載文件:
wget -c https://nodeload.github.com/nicolasff/phpredis/zip/master
解壓:
tar -zxvf master
//如果解壓失敗,可以用unzip解壓
**
二、安裝phpredis
**
2.1、phpize
進入安裝後的master目錄
cd master
$ sudo phpize
----------------------------------------------------------------------
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
----------------------------------------------------------------------
//出現上面提示,說明 /usr/下沒有include文件夾,需要先關聯,對於OSX10.11 以上的系統,蘋果設定了rootless機制,即使 sudo mkdir /usr/tmp 也會提示 “Permission denied” 沒有權限,需要先關閉rootless
- 2.1.1、先關閉 Rootless
重啓 Mac,聽到開機啓動聲後按住 Command+R,進入恢復模式,在上面的菜單實用工具中找到並打開 Terminal 終端(如果頂部沒出現菜單,請繼續重啓^_^)。輸入如下命令:
$ csrutil disable
執行完命令後,重啓電腦即可生效。爲了系統的安全,建議大家平時都開啓 Rootless($ csrutil enable),只有需要時才暫時關閉。
- 2.1.2、先找到你電腦對應的OSX版本號對應的 .sdk
ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
----------------------------------------------------------------------
//MacOSX.sdk MacOSX10.12.sdk
----------------------------------------------------------------------
//後面那個 “MacOSX10.12.sdk” 就是Mac對應的版本號的sdk
- 2.1.3、關聯MacOSX10.12.sdk/usr/include目錄到 usr/include
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include /usr/include
2.2、配置 /configure
- 2.2.1、查找 php-config 路徑
$ sudo find / -name php-config
----------------------------------------------------------------------
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/bin/php-config
find: /dev/fd/phpredis-master: No such file or directory
find: /dev/fd/phpredis-master: No such file or directory
/usr/bin/php-config
----------------------------------------------------------------------
//最後一個 /usr/bin/php-config 是我們需要的路徑
- 2.2.2、配置 .configure
$ ./configure --with-php-config=/usr/bin/php-config
2.3、make && make install
- 2.3.1、執行安裝
sudo make && make install
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@3913#: Permission denied
make: *** [install-modules] Error 1
----------------------------------------------------------------------
//又是用戶權限問題
- 2.3.2、改用戶及權限
sudo chmod -R 777 /usr/lib/php/extensions/no-debug-non-zts-20131226
sudo chown -R zhangwei /usr/lib/php/extensions/no-debug-non-zts-20131226
- 2.3.3、重新運行
sudo make && make install
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------------------------
//安裝成功了
看一下
ls /usr/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------------------------
redis.io
----------------------------------------------------------------------
//如果有 redis.so 擴展關聯成功了
**
三、更改 php.ini
**
sudo find / -name php.ini
----------------------------------------------------------------------
/private/etc/php.ini
----------------------------------------------------------------------
sudo vi /private/etc/php.ini
按 / 並輸入:redis
光標定位到
; extension=redis.so
把前面的 ; 去掉
按英文輸入法的 : 輸入wq
,(保存退出)
四、重啓 apache
sudo apachectl restart
phpredis已經安裝完成
驗證 phpredis是否成功
php -m |grep redis
----------------------------------------------------------------------
redis
----------------------------------------------------------------------
//如果有 redis 說明已成功安裝了phpredis