有个项目使用了ThinkPHP,直接clone来后支持一片空白,在检查配置的时候看到一段:
$config['memcache']['prefix'] = '';
$config['memcache'][1]['port'] = 11211;
$config['memcache'][1]['host'] = '127.0.0.1';
$config['memcache'][1]['pconnect'] = 0;
1
2
3
4
$config['memcache']['prefix']='';
$config['memcache'][1]['port']=11211;
$config['memcache'][1]['host']='127.0.0.1';
$config['memcache'][1]['pconnect']=0;
使用了memcache,但我本地是没有装这个模块的,于是开始安装,本以为也就一分钟的事,结果耗了我一天时间!
过程如下:
安装memcache
sudo brew install memcached
1
sudobrewinstallmemcached
只要安装这个,所依赖的相关会自动一并安装。
安装后启动看看
sudo memcached -m 32 -p 11211 -d
1
sudomemcached-m32-p11211-d
正常启动。但是这个只是服务端,还需要安装PHP端的。
因为我使用了XAMPP,就用pecl安装:
sudo ./pecl install memcache
1
sudo./peclinstallmemcache
这里报错
/usr/local/bin/phpize: line 61: /usr/local/Library/ENV/4.3/sed: No such file or directory
/usr/local/bin/phpize: line 62: /usr/local/Library/ENV/4.3/sed: No such file or directory
/usr/local/bin/phpize: line 63: /usr/local/Library/ENV/4.3/sed: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
/usr/local/bin/phpize: line 155: /usr/local/Library/ENV/4.3/sed: No such file or directory
autoheader: error: AC_CONFIG_HEADERS not found in configure.in
1
2
3
4
5
6
7
8
9
/usr/local/bin/phpize:line61:/usr/local/Library/ENV/4.3/sed:Nosuchfileordirectory
/usr/local/bin/phpize:line62:/usr/local/Library/ENV/4.3/sed:Nosuchfileordirectory
/usr/local/bin/phpize:line63:/usr/local/Library/ENV/4.3/sed:Nosuchfileordirectory
Configuringfor:
PHPApiVersion:
ZendModuleApiNo:
ZendExtensionApiNo:
/usr/local/bin/phpize:line155:/usr/local/Library/ENV/4.3/sed:Nosuchfileordirectory
autoheader:error:AC_CONFIG_HEADERSnotfoundinconfigure.in
解决方法如下:
vi 'which phpize'
1
vi'which phpize'
找到 SED="/usr/local/Library/ENV/4.3/sed" 改成 SED="/usr/bin/sed"
接着又报错:
checking for the location of zlib... configure: error: memcache support requires ZLIB.
Use --with-zlib-dir=
1
2
checkingforthelocationofzlib...configure:error:memcachesupportrequiresZLIB.
Use--with-zlib-dir=
看错是没有zlib导致,安装:
brew install zlib
1
brewinstallzlib
安装后发现还是不错,检查list明显已经有了zlib,什么原因?后找到解决方法:
xcode-select --install
1
xcode-select--install
要安装xcode命令行工具,至于原因原理,我也不明白~~。但是zlib错误不报了,又报如下错误:
/private/tmp/pear/install/memcache/memcache.c:40:10: fatal error: 'ext/standard/php_smart_str.h' file not found
#include "ext/standard/php_smart_str.h"
^
1 error generated.
make: *** [memcache.lo] Error 1
ERROR: `make' failed
1
2
3
4
5
6
/private/tmp/pear/install/memcache/memcache.c:40:10:fatalerror:'ext/standard/php_smart_str.h'filenotfound
#include "ext/standard/php_smart_str.h"
^
1errorgenerated.
make:***[memcache.lo]Error1
ERROR:`make'failed
心情糟糕,接连不断的意外错误,浪费了我很多时间,但不能放弃,继续找问题。
根据错误提示,网上说是因为PHP7已经不存在php_smart_str.h文件,变成了其它名字,有遇到同样问题的人尝试把该文件复制改名后依然无法编译通过,所以我就不试了。。问题真是PHP7吗? 虽然有人说git上有一个针对PHP7的分支版本可以试试,但我显然不想去入坑了。于是我果断的换版本,我换了PHP Version 5.6.24。
虽然XAMPP上已经换成了PHP5,但我再编译的时候依然有上面那个错误,再看:
running: make
/bin/sh /private/tmp/pear/install/pear-build-rootkWwXGn/memcache-2.2.7/libtool --mode=compile cc
-I/usr/local/Cellar/php71/7.1.0-alpha.2/include/php
1
2
3
running:make
/bin/sh/private/tmp/pear/install/pear-build-rootkWwXGn/memcache-2.2.7/libtool--mode=compilecc
-I/usr/local/Cellar/php71/7.1.0-alpha.2/include/php
引用的依然是PHP7,什么鬼,果断的brew list后发现一个PHP71,于是brew uninstall PHP71后,再次
sudo ./pecl install memcache
1
sudo./peclinstallmemcache
好了,这回顺利编译通过。
Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20121212/memcache.so'
install ok: channel://pecl.php.net/memcache-2.2.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcache.so" to php.ini
1
2
3
4
5
Buildprocesscompletedsuccessfully
Installing'/usr/lib/php/extensions/no-debug-non-zts-20121212/memcache.so'
installok:channel://pecl.php.net/memcache-2.2.7
configurationoption"php_ini"isnotsettophp.inilocation
Youshouldadd"extension=memcache.so"tophp.ini
往下的,你就修改php.ini,把模块加载进去就行了。