OSX下为php安装redis扩展~~~

想在OSX 下安装php的redis扩展,下载phpredis,然后phpize,报错:


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:  


第一种方法:

然后这个原因是因为OSX自带的PHP没有此目录,此目录只有编译过的PHP才有,所以我们去找一个php版本去编译,

因为我这边OSX10.9下自带的php版本是5.4.24,所以我们下载了5.4.29版本进行编译安装:


php版本从这里下载:http://cn2.php.net/downloads.php


下载之后cd到目录中,但是在./configure时碰到错误:


configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>


通过brew安装:

brew install libiconv



configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>
someoneMacBook-Pro:php-5.4.29 someone$ brew search iconv
libiconv
someoneMacBook-Pro:php-5.4.29 someone$ brew install libiconv
==> Downloading http://ftpmirror.gnu.org/libiconv/libiconv-1.14.tar.gz
######################################################################## 100.0%
==> Downloading https://trac.macports.org/export/89276/trunk/dports/textproc/lib
######################################################################## 100.0%
==> Downloading https://trac.macports.org/export/89276/trunk/dports/textproc/lib
######################################################################## 100.0%
==> Patching
patching file Makefile.devel
Hunk #1 succeeded at 106 (offset 1 line).
patching file lib/converters.h
patching file lib/encodings.def
patching file lib/utf8mac.h
patching file lib/flags.h
==> ./configure --prefix=/usr/local/Cellar/libiconv/1.14 --enable-extra-encoding
==> make -f Makefile.devel CFLAGS= CC=clang
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.


Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.


Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:


    LDFLAGS:  -L/usr/local/opt/libiconv/lib
    CPPFLAGS: -I/usr/local/opt/libiconv/include


==> Summary
��  /usr/local/Cellar/libiconv/1.14: 26 files, 1.4M, built in 2.8 minutes
someoneMacBook-Pro:php-5.4.29 someone$ 



安装之后,我们再使用./configure安装php,还是报相同错误,也就是:configure: error: Please specify the install prefix of iconv with --with-iconv=<DIR>


这是因为我们虽然安装了libiconv,但是没有指定目录,我们这样:


./configure --with-iconv=/usr/local/Cellar/libiconv/1.14/



这样就可以编译成功了~~


反正我是成功了:


Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+


Thank you for using PHP.


config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands



第二种方法:

或者我们可以在OSX 10.9下使用这个命令:


ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include


这一条命令就可以搞定


好像所有osx下得用户include 文件都在这个目录下,估计是OSX 10.9将原来的/usr/include 路径迁移了~~



之后我们就可以到phpredis目录中phpize


someoneMacBook-Pro:phpredis someone$ phpize
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
someoneMacBook-Pro:phpredis someone$ 


然后我们再./configure


然后make && make install 


AndyMacBookPro:phpredis andy$ make test


Build complete.
Don't forget to run 'make test'.




=====================================================================
PHP         : /usr/bin/php 
PHP_SAPI    : cli
PHP_VERSION : 5.4.24
ZEND_VERSION: 2.4.0
PHP_OS      : Darwin - Darwin AndyMacBookPro.local 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
INI actual  : /Users/andy/Documents/phpredis/tmp-php.ini
More .INIs  :  
CWD         : /Users/andy/Documents/phpredis
Extra dirs  : 
VALGRIND    : Not used
=====================================================================
TIME START 2014-06-23 05:50:36
=====================================================================
No tests were run.
AndyMacBookPro:phpredis andy$ 




someoneMacBook-Pro:phpredis someone$ make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20100525/
cp: /usr/lib/php/extensions/no-debug-non-zts-20100525/#INST@40628#: Permission denied
make: *** [install-modules] Error 1
someoneMacBook-Pro:phpredis someone$ 


报错是因为没有权限,我们sudo之后试下:


someoneMacBook-Pro:phpredis someone$ sudo make install
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20100525/
someoneMacBook-Pro:phpredis someone$ 


redis扩展成功了~~


之后我们寻找下redis.so


someoneMacBook-Pro:phpredis someone$ sudo find / -name redis.so
Password:
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Users/someone/Downloads/phpredis/.libs/redis.so
/Users/someone/Downloads/phpredis/.libs/redis.so.dSYM/Contents/Resources/DWARF/redis.so
/Users/someone/Downloads/phpredis/modules/redis.so
/usr/lib/php/extensions/no-debug-non-zts-20100525/redis.so
someoneMacBook-Pro:phpredis someone$ 



然后我们可以放心的去找到php.ini (这个文件在哪里?可以根据phpinfo()打印出来的信息:

Loaded Configuration File /etc/php.ini

ps:其实如果你在/etc/下面没有php.ini的时候,这里Loaded Configuration File有可能会显示空,你只需要将此/etc/目录下的php.ini.default拷贝一份:


cp php.ini.default php.ini

然后再次重启apache,就能看见Loaded Configuration File有值了


来找到这个文件,然后在里面加入这一段:


extension=redis.so


然后重启apache:


sudo apachectl restart


之后我么再一次phpinfo()


就看到了这个:


redis

Redis Support enabled
Redis Version 2.2.5


到这里php的redis扩展安装大功告成~~



*********************************************************************************************************

然后我们可以写一段php访问redis的脚本测试:


$redis = new redis();
$result = $redis->connect('192.168.100.60',6379);
var_dump($result);


如果返回true,则说明成功!



参照和引用:

http://www.douban.com/note/246191125/

http://blog.csdn.net/wkupaochuan/article/details/8627304

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页