更新 OS X 至 El Capitan 后的 Mcrypt 问题

3

我在将Yosemite升级到El Capitan后,使用mcrypt(和Laravel)时遇到了问题。当我运行本地站点(Laravel框架版本4.2.17)时,会出现以下错误:

需要Mcrypt PHP扩展。

以下是我的设置:

1)which php

/usr/local/bin/php

2) php --version

PHP 5.6.14 (cli) (built: Oct  3 2015 14:54:13) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

3) php --ini

Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File:         /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed:      /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.6/conf.d/ext-xdebug.ini,
/usr/local/etc/php/5.6/conf.d/redis.ini

4) 使用命令"cat /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini | grep --color -i mcrypt"来查找是否安装了mcrypt插件。

[mcrypt]
extension="/usr/local/opt/php56-mcrypt/mcrypt.so"

5) ll /usr/local/opt/php56-mcrypt/

total 112
drwxr-xr-x  5 olga  admin    170 Oct 29 07:31 .
drwxr-xr-x  5 olga  admin    170 Oct 29 07:31 ..
-rw-r--r--  1 olga  admin    373 Oct 29 07:31 INSTALL_RECEIPT.json
-rw-r--r--  1 olga  admin    107 Sep 30 01:35 TODO
-rwxr-xr-x  1 olga  admin  45284 Oct 29 07:31 mcrypt.so

6) php -i | grep --color -i mcrypt

Additional .ini files parsed => /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini,
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
PHP Warning:  Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

7) php -m | grep --color -i mcrypt

mcrypt

8) 输出 $PATH

/Volumes/project1/code/scripts/:/usr/local/mysql:/Applications/Adobe Flash Builder 4.6/sdks/4.5.0/bin:/Volumes/project1/code/tools/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/olga/.rvm/bin:~/Applications/arcanist/bin/:/usr/local/Cellar/php56/5.6.14/bin:~/.composer/vendor/phpunit/phpunit:/usr/local/bin:/usr/local/mysql/bin:/Users/olga/.composer/vendor/bin:/opt/apache-maven-3.3.3/bin

9) (PHP来自$ PATH)/usr/local/Cellar/php56/5.6.14/bin/php --ini

意思是在$ PATH中指定的路径中找到了PHP,该路径为/usr/local/Cellar/php56/5.6.14/bin/php,然后运行--ini命令来查看PHP的配置信息。
Configuration File (php.ini) Path: /usr/local/etc/php/5.6
Loaded Configuration File:         /usr/local/etc/php/5.6/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.6/conf.d
Additional .ini files parsed:      /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini,
/usr/local/etc/php/5.6/conf.d/ext-xdebug.ini,
/usr/local/etc/php/5.6/conf.d/redis.ini

我缺少什么?

先行致谢


你看过这个问题吗?https://dev59.com/b2Qn5IYBdhLWcg3wcWzM - Mihai
@Mihai 是的,我做了。我已经将PATH更改为export PATH="/usr/local/opt/php56/bin":$PATH,但没有帮助。 - Olga Zhe
1个回答

2
最终我解决了它!虽然还不知道原因,但是......这就是我的解决方法:
1)将Homebrew PHP放置在PATH中。
export PATH="/usr/local/opt/php56/bin":other_paths

2) 在apache(httpd.conf)中更改php模块

LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
#LoadModule php5_module libexec/apache2/libphp5.so`

3) 卸载所有版本的mcrypt和phpXX_mcrypt

4) 删除phpXX_mcrypt ini文件

5) 重启apache。确保mcrypt不在php中(例如,php -i | grep --color -i mcrypt

6) 使用brew安装mcrypt和phpXX_mcrypt

brew search mcrypt
brew install mcrypt
brew install phpXX_mcrypt

7) 重启Apache

希望这能有所帮助 :)


这个问题!这个问题出现了好多次!整整一天的搜索,才发现为什么通过Homebrew设置PHP等环境后,新的MBP无法运行mcrypt函数(尽管显示模块已加载)- 关键是上面的LoadModule更改! - matt.chatterley
我不使用Apache,而是使用内置的PHP服务器,但遇到了同样的问题。在安装El Capitan之后,我的PHP版本指向系统PHP,而不是Homebrew的PHP。通过更新我的.zshrc(或.bashrc)中的路径为export PATH="$(brew --prefix homebrew/php/php55)/bin:$PATH"来解决了这个问题。 - Ludder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接