在 OSX Mountain Lion 上为 PHP 安装 mcrypt 扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14595841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:36:21  来源:igfitidea点击:

Installing mcrypt extension for PHP on OSX Mountain Lion

phpmacosapachemcrypt

提问by user2023687

Apologies in advance for the potential n00b questions, I am trying to install the mcrypt extension for PHP on my OSX Mountain Lion machine.

提前为潜在的 n00b 问题道歉,我正在尝试在我的 OSX Mountain Lion 机器上安装 PHP 的 mcrypt 扩展。

The following steps in terminal is what I have done so far to achieve my PHP install

终端中的以下步骤是我迄今为止为实现 PHP 安装所做的工作

cd /path/to/downloaded/php-5.3.21/ext/mcrypt/
/usr/bin/phpize
./configure
cd /path/to/downloaded/php-5.3.21
./configure --with-config-file-path=/private/etc/php.ini --with-apxs2=/usr/sbin/apxs
make
sudo make install

Which seems to work well and installs PHP 5.3.21 fine. I have then done

这似乎运行良好并且可以很好地安装 PHP 5.3.21。然后我做了

sudo nano /private/etc/php.ini

And included

并包括

extension=mcrypt.so

Along with an Apache restart, phpinfo() doesn't show that the mcrypt extension is loaded.

随着 Apache 重新启动,phpinfo() 不会显示已加载 mcrypt 扩展。

I then tried to specify the extension_dir inside php.ini, again with no luck.

然后我尝试在 php.ini 中指定 extension_dir,但同样没有运气。

I have done

我已经做好了

locate mcrypt.so
/opt/local/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
/usr/local/Cellar/php53-mcrypt/5.3.18/mcrypt.so

And tried both directories as the extension_dir, with no luck.

并尝试将两个目录作为 extension_dir,但没有成功。

I have also tried the following, after much Googling

经过多次谷歌搜索后,我也尝试了以下方法

./configure --with-config-file-path=/private/etc/php.ini --with-apxs2=/usr/sbin/apxs --with-mcrypt

Which seems to work OK, but then upon "make", it returns

这似乎工作正常,但随后在“制作”时,它返回

ext/mcrypt/mcrypt.o: No such file or directory
ext/mcrypt/mcrypt_filter.o: No such file or directory

Again, no success.

再次,没有成功。

What am I doing wrong? It seems like the physical compile of mcrypt.so is not happening, or is compiling incorrectly as I would suspect there to be another mcrypt.so found under locate?

我究竟做错了什么?似乎 mcrypt.so 的物理编译没有发生,或者编译不正确,因为我怀疑在 locate 下发现了另一个 mcrypt.so?

Anyone please help? I've gone through pages upon pages of Google searches with no luck!

有人请帮忙吗?我已经浏览了一页又一页的谷歌搜索,但没有运气!

回答by David Yell

I tend to use Homebrew on Mac. It will install and configure all the stuff for you.
http://mxcl.github.com/homebrew/

我倾向于在 Mac 上使用 Homebrew。它将为您安装和配置所有东西。
http://mxcl.github.com/homebrew/

Then you should be able to install it with brew install mcrypt php53-mcryptand it'll Just Work (tm).

然后你应该能够安装它brew install mcrypt php53-mcrypt并且它会正常工作(tm)。

You can replace the 53with whatever version of PHP you're using, such as php56-mcryptor php70-mcrypt. If you're not sure, use brew search php.

您可以将 替换为53您正在使用的任何版本的 PHP,例如php56-mcryptphp70-mcrypt。如果您不确定,请使用brew search php.

Do also remember that if you are using the built in Mac PHP it's installed into /usr/binyou can see which php you are using with which phpat the terminal and it'll return the path.

还请记住,如果您使用内置的 Mac PHP,它已安装到/usr/bin您可以看到您which php在终端上使用的 php ,它会返回路径。

回答by ckm

I just went through this on Mountain Lion. Homebrew blocked on libiconv which it thought was missing but was actually up to date. After an hour of trying to get it to recognize libiconv, I gave up and installed it the old fashion way, which took all of five minutes...

我刚刚在 Mountain Lion 上经历了这个。Homebrew 阻止了 libiconv,它认为它丢失了,但实际上是最新的。在尝试让它识别 libiconv 一个小时后,我放弃并以旧方式安装它,这花了整整五分钟......

(download your php version)
$ wget http://www.php.net/get/php-5.3.21.tar.gz/from/a/mirror
$ tar -xvzf php-5.3.21.tar.gz
$ cd php-5.3.21/ext/mcrypt
$ phpize
$ ./configure
$ make
$ make test
$ sudo make install 

mcrypt.so is now in your PHP ext dir (/usr/lib/php/extensions/no-debug-non-zts-20090626/in my case), now you need to add to php.ini as a module

mcrypt.so 现在在你的 PHP ext 目录中(/usr/lib/php/extensions/no-debug-non-zts-20090626/在我的例子中),现在你需要添加到 php.ini 作为一个模块

$ vi /etc/php.ini
$ (insert) extension=mcrypt.so
$ sudo apachectl restart

Done - no brew necessary. HTH someone.

完成 - 无需冲泡。HTH某人。

回答by Will Palmer

Installing php-mcryptwithout the use of portor brew

安装 php-mcrypt不使用portorbrew

Note: these instructions are long because they intend to be thorough. The process is actually fairly straight-forward. If you're an optimist, you can skip down to the building the mcrypt extensionsection, but you may very well see the errors I did, telling me to install autoconfand libmcryptfirst.

注意:这些说明很长,因为它们打算彻底。这个过程实际上相当简单。如果你是一个乐观主义者,你可以跳过下到建设mcrypt扩展部分,但你很可能看到我做了错误,告诉我要安装autoconflibmcrypt第一。

I have just gone through this on a fresh install of OSX 10.9. The solution which worked for me was veryclose to that of ckm- I am including their steps as well as my own in full, for completeness. My main goal (other than "having mcrypt") was to perform the installation in a way which left the least impact on the system as a whole. That means doing things manually (no port, no brew)

我刚刚在全新安装的 OSX 10.9 上经历了这个过程。对我有用的解决方案与ckm的解决方案非常接近- 为了完整起见,我完整地包括了他们的步骤以及我自己的步骤。我的主要目标(除了“拥有mcrypt”)是以对整个系统影响最小的方式执行安装。这意味着手动做事(不port,不brew

To do things manually, you will first need a couple of dependencies: one for building PHP modules, and another for mcryptspecifically. These are autoconfand libmcrypt, either of which you might have already, but neither of which you will have on a fresh install of OSX 10.9.

要手动执行操作,您首先需要几个依赖项:一个用于构建 PHP 模块,另一个用于mcrypt专门的。这些是autoconflibmcrypt,您可能已经拥有其中任何一个,但在全新安装的 OSX 10.9 中您将不会拥有这两个。

autoconf

自动配置

Autoconf (for lack of a better description) is used to tell not-quite-disparate, but still very different, systems how to compile things. It allows you to use the same set of basic commands to build modules on Linux as you would on OSX, for example, despite their different file-system hierarchies, etc. I used the method described by Ares on StackOverflow, which I will reproduce here for completeness. This one is very straight-forward:

Autoconf(由于缺乏更好的描述)用于告诉系统如何编译东西,但这些系统并不完全不同,但仍然非常不同。它允许您使用与在 OSX 上相同的一组基本命令在 Linux 上构建模块,例如,尽管它们的文件系统层次结构不同等。我使用了 Ares 在 StackOverflow 上描述的方法,我将在此处重现为了完整性。这是非常直接的:

$ mkdir -p ~/mcrypt/dependencies/autoconf
$ cd ~/mcrypt/dependencies/autoconf
$ curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
$ tar xzf autoconf-latest.tar.gz
$ cd autoconf-*/
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

Next, verify the installation by running:

接下来,通过运行来验证安装:

$ which autoconf

which should return /usr/local/bin/autoconf

哪个应该返回 /usr/local/bin/autoconf

libmcrypt

libmcrypt

Next, you will need libmcrypt, used to provide the guts of the mcryptextension (the extension itself being a provision of a PHP interface into this library). The method I used was based on the one described here, but I have attempted to simplify things as best I can:

接下来,您将需要libmcrypt, 用于提供mcrypt扩展的内容(扩展本身是向该库提供 PHP 接口)。我使用的方法基于此处描述的方法,但我已尽力简化事情:

First, download the libmcryptsource, available from SourceForge, and available as of the time of this writing, specifically, at:

首先,libmcryptSourceForge下载源代码,在撰写本文时可用,具体位于:

http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download

http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download

You'll need to jump through the standard SourceForge hoops to get at the real download link, but once you have it, you can pass it in to something like this:

您需要跳过标准的 SourceForge 圈以获得真正的下载链接,但是一旦拥有它,您就可以将其传递给如下内容:

$ mkdir -p ~/mcrypt/dependencies/libmcrypt
$ cd ~/mcrypt/dependencies/libmcrypt
$ curl -L -o libmcrypt.tar.bz2 '<SourceForge direct link URL>'
$ tar xjf libmcrypt.tar.bz2
$ cd libmcrypt-*/
$ ./configure
$ make
$ sudo make install

The only way I know of to verify that this has worked is via the ./configurestep for the mcryptextension itself (below)

我知道验证这是否有效的唯一方法是通过扩展本身的./configure步骤mcrypt(如下)

building the mcrypt extension

构建 mcrypt 扩展

This is our actual goal. Hopefully the brief stint into dependency hell is over now.

这是我们的实际目标。希望进入依赖地狱的短暂停留现在已经结束。

First, we're going to need to get the source code for the mcryptextension. This is most-readily available buried within the source code for all of PHP. So: determine what version of the PHP source code you need.

首先,我们需要获取mcrypt扩展的源代码。这是隐藏在所有 PHP 源代码中的最容易获得的。所以:确定你需要什么版本的 PHP 源代码。

$ php --version # to get your PHP version

now, if you're lucky, your current version will be available for download from the main mirrors. If it is, you can type something like:

现在,如果幸运的话,您当前的版本将可以从主镜像下载。如果是,您可以键入以下内容:

$ mkdir -p ~/mcrypt/php
$ cd ~/mcrypt/php
$ curl -L -o php-5.4.17.tar.bz2 http://www.php.net/get/php-5.4.17.tar.bz2/from/a/mirror

Unfortunately, my current version (5.4.17, in this case) was not available, so I needed to use the alternative/historical links at http://downloads.php.net/stas/(also an official PHP download site). For these, you can use something like:

不幸的是,我当前的版本(在本例中为 5.4.17)不可用,因此我需要使用http://downloads.php.net/stas/(也是官方 PHP 下载站点)上的替代/历史链接。对于这些,您可以使用以下内容:

$ mkdir -p ~/mcrypt/php
$ cd ~/mcrypt/php
$ curl -LO http://downloads.php.net/stas/php-5.4.17.tar.bz2

Again, based on your current version.

同样,基于您当前的版本。

Once you have it, (and all the dependencies, from above), you can get to the main process of actually building/installing the module.

一旦你有了它(以及上面的所有依赖项),你就可以进入实际构建/安装模块的主要过程。

$ cd ~/mcrypt/php
$ tar xjf php-*.tar.bz2
$ cd php-*/ext/mcrypt
$ phpize
$ ./configure # this is the step which fails without the above dependencies
$ make
$ make test
$ sudo make install

In theory, mcrypt.sois now in your PHP extension directory. Next, we need to tell PHP about it.

理论上,mcrypt.so现在在你的 PHP 扩展目录中。接下来,我们需要告诉 PHP。

configuring the mcrypt extension

配置 mcrypt 扩展

Your php.inifile needs to be told to load mcrypt. By default in OSX 10.9, it actually has mcrypt-specific configuration information, but it doesn't actually activate mcryptunless you tell it to.

php.ini需要告诉您的文件加载mcrypt. 默认情况下,在 OSX 10.9 中,它实际上具有mcrypt特定的配置信息,但mcrypt除非您告诉它,否则它实际上不会激活。

The php.inifile does not, by default, exist. Instead, the file /private/etc/php.ini.defaultlists the default configuration, and can be used as a good template for creating the "true" php.ini, if it does not already exist.

php.ini默认情况下,该文件不存在。相反,该文件/private/etc/php.ini.default列出了默认配置,并且可以用作创建 "true" 的好模板php.ini,如果它不存在的话。

To determine whether php.inialready exists, run:

要确定是否php.ini已经存在,请运行:

$ ls /private/etc/php.ini

If there is a result, it already exists, and you should skip the next command.

如果有结果,它已经存在,你应该跳过下一个命令。

To create the php.inifile, run:

要创建php.ini文件,请运行:

$ sudo cp /private/etc/php.ini.default /private/etc/php.ini

Next, you need to add the line:

接下来,您需要添加以下行:

extension=mcrypt.so

Somewhere in the file. I would recommend searching the file for ;extension=, and adding it immediately prior to the first occurrence.

文件中的某处。我建议在文件中搜索;extension=,并在第一次出现之前立即添加它。

Once this is done, the installation and configuration is complete. You can verify that this has worked by running:

完成此操作后,安装和配置就完成了。您可以通过运行来验证这是否有效:

php -m | grep mcrypt

Which should output "mcrypt", and nothing else.

哪个应该输出“ mcrypt”,没有别的。

If your use of PHP relies on Apache's httpd, you will need to restart it before you will notice the changes on the web. You can do so via:

如果您使用 PHP 依赖于 Apache 的httpd,则需要重新启动它,然后才能注意到 Web 上的更改。您可以通过:

$ sudo apachectl restart

And you're done.

你已经完成了。

回答by cwd

Why You're Getting This Error

为什么会出现此错误

PHP complains if one of the files like mcrypt.sois included using the syntax extension="mcrypt.so"but the file is not in the extension_dirpath ( use <?php phpinfo(); ?>or php -ito check that).

PHP 会抱怨是否mcrypt.so使用语法包含了其中一个文件,extension="mcrypt.so"但该文件不在extension_dir路径中(使用<?php phpinfo(); ?>php -i检查该文件)。

It will also tell you which php.iniconfig file is being loaded so you will know where the settings are coming from. Most likely it will be something like /usr/local/etc/php/5.4/php.iniif you are using the homebrew version.

它还会告诉您php.ini正在加载哪个配置文件,以便您知道设置的来源。最有可能的是,/usr/local/etc/php/5.4/php.ini如果您使用的是自制软件版本。

Take note of the part under it that says something like "Scan this dir for additional .ini files" because what that means is it gives you a place to put your own file, like tweaks.inithat is loaded after the main configuration file so that you can make changes and keep up with them easily. Also remember that all the files in this directory get loaded in alphabetical order, so if you have one called adjustments.inithat contains mcryptdirectives, and there is a mcrypt.ini, most likely your settings will be overridden.

记下它下面的部分,上面写着“扫描此目录以获取其他 .ini 文件”,因为这意味着它为您提供了一个放置您自己的文件的地方,就像tweaks.ini在主配置文件之后加载一样,这样您就可以进行更改并轻松跟上。还要记住,这个目录中的所有文件都是按字母顺序加载的,所以如果你有一个adjustments.ini包含mcrypt指令的调用,并且有一个mcrypt.ini,很可能你的设置将被覆盖。

One alternative to specifying extension="mcrypt.so"is to specify the full path to the mcrypt.sofile. The other option is to edit the extension_dirsetting.

指定的一种替代方法extension="mcrypt.so"是指定mcrypt.so文件的完整路径。另一个选项是编辑extension_dir设置。

What worked for me

什么对我有用

On Mavericks I didn't have to do either. I did a fresh install of homebrewand then added the josegonzalez tap using:

在小牛队我也不必这样做。我进行了全新安装,homebrew然后使用以下方法添加了 josegonzalez 水龙头:

brew tap josegonzalez/homebrew-php

(My other laptop was running Mountain Lion and was also using homebrew in this setup.)

(我的另一台笔记本电脑正在运行 Mountain Lion,并且在此设置中也使用自制软件。)

After you've tapped that awesome repoyou can install phpand mcryptusing something like:

在你点击了那个很棒的 repo 之后,你可以安装phpmcrypt使用类似的东西:

brew install php54 php54-mcrypt

What if this doesn't work (and why should I use homebrew anyway?)

如果这不起作用怎么办(我为什么要使用自制软件?)

I would highly advise trying this route before downloading and building it from source. It's not hard to build from source - but I don't want to have to maintain that. It's one of the reasons to use homebrewin the first place - it's a package manager (with a HUGE community).

我强烈建议在从源代码下载和构建它之前尝试这条路线。从源代码构建并不难 - 但我不想维护它。这是homebrew首先使用的原因之一——它是一个包管理器(有一个巨大的社区)。

There is a lot of development on the homebrewproject and - if you have problems I'd suggest checking out their issues page

homebrew项目有很多发展,如果您有问题,我建议您查看他们的问题页面

So yes you can build it from source and that might seem like a good option right now if you just want mcrypt to work but you may hate yourself for doing this later...

所以是的,你可以从源代码构建它,如果你只是想让 mcrypt 工作,那么现在这似乎是一个不错的选择,但你可能会讨厌自己以后这样做......

If you don't want to be using php54there is also the php53branch. They have some instructions at the repo about how to use both of them / switch between them.

如果您不想使用,php54还有php53分支。他们在 repo 中有一些关于如何使用它们/在它们之间切换的说明。

If you're new to homebrew you should know that you check out what else is available using brew search php54, which gives something like:

如果您是自制软件的新手,您应该知道您使用 来查看其他可用的brew search php54东西,它给出了类似的内容:

php54                php54-lzf          php54-snappy        
php54-amqp           php54-mailparse    php54-solr          
php54-apc            php54-mcrypt       php54-ssh2          
php54-apcu           php54-memcache     php54-stats         
php54-boxwood        php54-memcached    php54-svm           
php54-chdb           php54-midgard2     php54-tidy          
php54-couchbase      php54-mongo        php54-timezonedb    
php54-dbase          php54-msgpack      php54-tokyotyrant   
php54-ev             php54-mysqlnd_ms   php54-twig          
php54-gearman        php54-oauth        php54-uploadprogress
php54-geoip          php54-opcache      php54-uuid          
php54-gmagick        php54-parsekit     php54-varnish       
php54-graphdat       php54-pcntl        php54-wbxml         
php54-http           php54-pdflib       php54-xcache        
php54-igbinary       php54-phalcon      php54-xdebug        
php54-imagick        php54-proctitle    php54-xhgui         
php54-inclued        php54-pspell       php54-xhp           
php54-intl           php54-pthreads     php54-xhprof        
php54-ioncubeloader  php54-raphf        php54-xmldiff       
php54-jsmin          php54-redis        php54-yac           
php54-judy           php54-riak         php54-yaf           
php54-leveldb        php54-runkit       php54-yaml          
php54-libevent       php54-scrypt       php54-yaz           
php54-libvirt

TLDR

TLDR

  • You should use homebrewto install mcryptif at all possible
  • If you're getting errors it's probably because your configuration file(s) are messed up. Check the extension_dirpath and figure out where the mcrypt.sofile is and see if there is a discrepancy (or specify the full path)
  • 如果可能,您应该使用homebrew来安装mcrypt
  • 如果您遇到错误,那可能是因为您的配置文件搞砸了。检查extension_dir路径并找出mcrypt.so文件所在的位置并查看是否存在差异(或指定完整路径)

回答by Sinan Eldem

For me, on Yosemite

对我来说,在优胜美地

$ brew install mcrypt php56-mcrypt

restart computer

重启电脑

did the trick.

成功了。

回答by Turtletrail

Solution with brew worked only after the following: in your php.ini

使用 brew 的解决方案仅在以下情况下起作用:在您的 php.ini 中

nano /private/etc/php.ini

add this line:

添加这一行:

extension="/usr/local/Cellar/php53-mcrypt/5.3.26/mcrypt.so"

Warning! Set the correct PHP version.

警告!设置正确的 PHP 版本。

回答by sinewave

I would recommend installing everything via homebrew if you have the option. I went in circles for a while, but installing php 5.x via brew and then the neccessary modules worked a treat. I was working with php 5.4 and used this to get going initially:

如果可以的话,我建议您通过自制软件安装所有内容。我转了一圈,但是通过 brew 安装 php 5.x 然后必要的模块工作了。我正在使用 php 5.4 并使用它来开始:

https://github.com/josegonzalez/homebrew-php

https://github.com/josegonzalez/homebrew-php

and then installed the additional modules with:

然后安装附加模块:

brew install php54-redis
brew install php54-xdebug
brew install php54-mcrypt

...

...

回答by Davide Vernizzi

Another possibility for those who want to keep OS X as clean as possible, is to use vagrant [1] to define a php development environment. Vagrant can use VirtualBox [2] in headless mode (~3% of CPU on my 13-inch, Mid 2009 MacBook Pro) to run a virtual machine with the webserver and php and all.

对于那些希望尽可能保持 OS X 干净的人来说,另一种可能性是使用 vagrant [1] 来定义一个 php 开发环境。Vagrant 可以在无头模式下使用 VirtualBox [2](在我的 13 英寸,2009 年中的 MacBook Pro 上大约占 CPU 的 3%)来运行带有网络服务器和 php 的虚拟机。

To easily create the vagrant environment you can use this great tool https://puphpet.com/

要轻松创建流浪环境,您可以使用这个很棒的工具https://puphpet.com/

  1. http://www.vagrantup.com/
  2. https://www.virtualbox.org/
  1. http://www.vagrantup.com/
  2. https://www.virtualbox.org/

回答by Lucas Blaschi Gameiro

I'd create a shell script to install mcrypt module for PHP 5.3 without homebrew.

我会创建一个 shell 脚本来为 PHP 5.3 安装 mcrypt 模块,而无需自制软件。

The scripts install php autoconf if needed and compile module for your php version.

如果需要,脚本会安装 php autoconf 并为您的 php 版本编译模块。

The link is here: https://gist.github.com/lucasgameiro/8730619

链接在这里:https: //gist.github.com/lucasgameiro/8730619

Thanks

谢谢

回答by star18bit

Nothing worked and finally got it working using resource @Hereand Here; Just remember for OSX Mavericks (10.9) should use PHP 5.4.17 or Stable PHP 5.4.22 source to compile mcrypt. Php Source 5.4.22 here

没有工作,终于得到了它的工作使用资源@这里这里; 请记住,对于 OSX Mavericks (10.9) 应该使用 PHP 5.4.17 或稳定的 PHP 5.4.22 源来编译 mcrypt。PHP 源 5.4.22 在这里