在 Mountain Lion 上使用 Homebrew 安装 mcrypt 支持 php54 的问题

Posted

技术标签:

【中文标题】在 Mountain Lion 上使用 Homebrew 安装 mcrypt 支持 php54 的问题【英文标题】:Problems with installing mcrypt support for php54 using Homebrew on Mountain Lion 【发布时间】:2013-01-19 06:08:37 【问题描述】:

我正在尝试使用 Homebrew 在 Mountain Lion 上的 php 5.4.11 中安装 mcrypt 支持,但遇到了无法解决的问题。

我已经在我的 Mac 上手动安装了 PHP 5.4.11。 mcrypt 之前是使用 Homebrew 安装的。

当我加载 phpMyAdmin 时,它会告诉我 mcrypt 未启用。

所以,搜索谷歌,我意识到不知何故,mcrypt 没有被加载,因为当我加载我的 phpinfo 文件时没有引用它。

@DavidYell 在回答另一个问题时,Installing mcrypt extension for PHP on OSX Mountain Lion 建议进行以下修复

brew install mcrypt php53-mcrypt

下面是我发出命令的结果:

$ brew install mcrypt php54-mcrypt
Error: mcrypt-2.5.8 already installed
==> Installing php54-mcrypt dependency: autoconf
==> Downloading http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/autoconf/2.69
==> make install
????  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M, built in 29 seconds
==> Installing php54-mcrypt dependency: freetype
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/freetype-2.4.10.mountainlion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring freetype-2.4.10.mountainlion.bottle.tar.gz
????  /usr/local/Cellar/freetype/2.4.10: 56 files, 2.5M
==> Installing php54-mcrypt dependency: gettext
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gettext-0.18.2.mountain_lion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring gettext-0.18.2.mountain_lion.bottle.tar.gz
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD gettext library and some software gets confused if both are in the library path.

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/gettext/lib
    CPPFLAGS: -I/usr/local/opt/gettext/include

==> Summary
????  /usr/local/Cellar/gettext/0.18.2: 366 files, 11M
==> Installing php54-mcrypt dependency: libpng
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libpng-1.5.13.mountainlion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libpng-1.5.13.mountainlion.bottle.tar.gz
????  /usr/local/Cellar/libpng/1.5.13: 14 files, 1.0M
==> Installing php54-mcrypt dependency: zlib
==> Downloading http://zlib.net/zlib-1.2.7.tar.gz
######################################################################## 100.0%
==> Patching
patching file configure
==> ./configure --prefix=/usr/local/Cellar/zlib/1.2.7
==> 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/zlib/lib
    CPPFLAGS: -I/usr/local/opt/zlib/include

==> Summary
????  /usr/local/Cellar/zlib/1.2.7: 9 files, 384K, built in 15 seconds
==> Installing php54-mcrypt dependency: php54
==> Downloading http://www.php.net/get/php-5.4.11.tar.bz2/from/this/mirror
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file Makefile.global
patch unexpectedly ends in middle of line
==> ./configure --prefix=/usr/local/Cellar/php54/5.4.11 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.4 --with-config-file-path=/usr/local/etc/php/5.4 --with-config-file-scan-dir=/usr/local/etc/php/5.4/conf.d --with-iconv-dir=/usr --enable-dba --with-ndbm=/usr --enable-exif --enable-soap --enable-w
==> make
==> make install
==> /usr/local/Cellar/php54/5.4.11/bin/pear config-set php_ini /usr/local/etc/php/5.4/php.ini
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/Cellar/php54/5.4.11/libexec/apache2/libphp5.so

The php.ini file can be found in:
    /usr/local/etc/php/5.4/php.ini

✩✩✩✩ PEAR ✩✩✩✩

If PEAR complains about permissions, 'fix' the default PEAR permissions and config:
    chmod -R ug+w /usr/local/Cellar/php54/5.4.11/lib/php
    pear config-set php_ini /usr/local/etc/php/5.4/php.ini

✩✩✩✩ Extensions ✩✩✩✩

If you are having issues with custom extension compiling, ensure that this php is
in your PATH:
    PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"

PHP54 Extensions will always be compiled against this PHP. Please install them
using --without-homebrew-php to enable compiling against system PHP.
==> Summary
????  /usr/local/Cellar/php54/5.4.11: 485 files, 37M, built in 7.2 minutes
==> Installing php54-mcrypt
==> Downloading http://www.php.net/get/php-5.4.11.tar.bz2/from/this/mirror
######################################################################## 100.0%
==> /usr/local/Cellar/php54/5.4.11/bin/phpize
==> ./configure --prefix=/usr/local/Cellar/php54-mcrypt/5.4.11 --with-php-config=/usr/local/Cellar/php54/5.4.11/bin/php-config --with-mcrypt=/usr/local/Cellar
==> make
==> Caveats
To finish installing mcrypt for PHP 5.4:
  * /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini was created,
    do not forget to remove it upon extension removal.
  * Restart your webserver.
  * Write a PHP page that calls "phpinfo();"
  * Load it in a browser and look for the info on the mcrypt module.
  * If you see it, you have been successful!
==> Summary
????  /usr/local/Cellar/php54-mcrypt/5.4.11: 3 files, 56K, built in 111 seconds

sudo apachectl restart 重新启动apache 后,我重新加载了phpinfo,仍然没有mcrypt。

由于 php54-mcrypt 安装在 php 的 Homebrew 安装中,我继续使用 brew uninstall php54-mcrypt 将其卸载,然后使用 brew install php54-mcrypt --without-homebrew-php 重新安装。

重启apache,加载phpinfo,还是没有mcrypt。

我该如何解决这个问题。我很乐意让 homebrew 为我安装 php、crypt 和 phpmyadmin,但我目前的设置似乎无法解决这个问题,这是基于 http://mac.tutsplus.com/tutorials/server/upgrading-the-native-php-installation-on-os-x-mountain-lion/ 中的建议。

谢谢。

【问题讨论】:

【参考方案1】:

好吧,经过多次尝试和错误,我解决了这个问题。

我首先必须再次卸载 php54-mcrypt 以删除 --without-homebrew-php 标志并重新安装它以支持 homebrew 安装的 php 版本。

$ brew uninstall php54-mcrypt
Uninstalling /usr/local/Cellar/php54-mcrypt/5.4.11...
$ brew install php54-mcrypt
...
==> Summary
?  /usr/local/Cellar/php54-mcrypt/5.4.11: 3 files, 56K, built in 33 seconds

然后,我编辑了我的 httpd.conf 文件并更改了 php 的位置。我刚刚注释掉了系统 PHP,并在通过 Homebrew 安装的 PHP 的 LoadModule 指令中添加了一个新行。

#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/Cellar/php54/5.4.11/libexec/apache2/libphp5.so

然后我通过 Homebrew 安装了 phpmyadmin

brew install phpmyadmin

然后我在 httpd.conf 的底部添加了以下内容

Alias /phpmyadmin /usr/local/share/phpmyadmin
    <Directory /usr/local/share/phpmyadmin/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

我在位于/usr/local/etc/php/5.4/php.ini 的自制安装的php.ini 中进行了需要进行的任何更改,并修改了位于/usr/local/share/phpmyadmin/config.inc.php 的phpmyadmin 的配置文件。

然后我使用sudo apachectl restart重新启动了apache

一切顺利!

【讨论】:

@EricLeroy:您可能需要从上面的 php5_module 链接中删除“usr”。当我这样做时,它对我有用。 (如果问题是 PHP 版本)如果是 mcrypt,我必须使用“brew uninstall mcrypt”然后“brew install php55-mcrypt”。 (对于 PHP5.5)你最终会做对的。 在搞砸了 mcrypt 很长时间后,我发现 brew uninstall mcrypt 是缺失的部分。 我认为你必须使用这个路径来包含php模块:LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so 季节是它没有严格的php版本依赖。

以上是关于在 Mountain Lion 上使用 Homebrew 安装 mcrypt 支持 php54 的问题的主要内容,如果未能解决你的问题,请参考以下文章

在 Mountain Lion 上安装 Rmagick 时出错

错误:MongoDB:未知版本:mountain_lion

从安装程序在 Mountain Lion 上安装 Qt

在 Mountain Lion 上运行 4.3 版的 iOS 应用程序

在 Mac OS 10.6 (Snow Leopard)、10.7 (Lion)、10.8 (Mountain Lion) 上激活 PHP 和 MySQL 的最简单方法?

在 Mountain Lion 上卸载 Xcode 3.2 的问题