Yosemite / El Capitan php-gd + mcrypt 安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26493762/
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
Yosemite / El Capitan php-gd + mcrypt installation
提问by Kyslik
How to install/enable php-gdand mcryptin Yosemite 10.10 - PHP 5.5.14 build?
如何在 Yosemite 10.10 - PHP 5.5.14 build 中安装/启用php-gd和mcrypt?
note that following steps install newest PHP 5.5.x
请注意以下步骤安装最新的 PHP 5.5.x
To check if you have gd and mcrypt installed use $ php -m
to display compiled in modules, continue if you are missing desired modules and please see accepted answer.
要检查您是否安装了 gd 和 mcrypt 用于$ php -m
在模块中显示编译,如果您缺少所需的模块,请继续,请参阅已接受的答案。
GD
广东
So, Apple installed GD (and you're using their build of PHP, which is fine), but did not include support for PNG.
因此,Apple 安装了 GD(并且您正在使用他们的 PHP 版本,这很好),但不包括对 PNG 的支持。
You are definitely missing "full" gd (with png support)module if: imagecreatefrompng()function is missing.
如果缺少imagecreatefrompng()函数,则您肯定缺少“完整” gd(支持 png)模块 。
"Call to undefined function imagecreatefrompng()"
"Call to undefined function imagecreatefrompng()"
Mcrypt
Mcrypt
install brew using accepted answerand omit part with gd installation (unless you need it), and use following steps:
使用接受的答案安装 brew并省略 gd 安装的部分(除非您需要它),并使用以下步骤:
- do search -
$ brew search mcrypt
- pick the version of PHP you want
- install -
$ brew install php55-mcrypt
- confirm using
$ php -m | grep mcrypt
- 做搜索——
$ brew search mcrypt
- 选择你想要的 PHP 版本
- 安装 -
$ brew install php55-mcrypt
- 确认使用
$ php -m | grep mcrypt
Want to switch between PHP versions?
想要在 PHP 版本之间切换?
Check out brew-php-switcherand follow instructions.
查看brew-php-switcher并按照说明进行操作。
回答by Jpsy
You are right, Yosemite's built-in PHP comes without PNG and FreeType support.
Update 2015/10 for El Captian:With OS X 10.11 El Capitan PNG support is back, but FreeType is still missing.
没错,Yosemite 的内置 PHP 不支持 PNG 和 FreeType。
El Captian 的 2015/10 更新:OS X 10.11 El Capitan PNG 支持又回来了,但仍然缺少 FreeType。
Solution
解决方案
Use the Homebrew package manager to painlessly build and install a complete PHP and replace it in Apache's config. The whole process only takes about ten minutes if you follow the steps below.
使用 Homebrew 包管理器轻松构建和安装完整的 PHP,并在 Apache 的配置中替换它。如果您按照以下步骤操作,整个过程只需大约十分钟。
A quick (but complete) walk through
快速(但完整)的演练
(Note 1: I use Homebrewhere, a package management system for OS X. If you are acquainted with MacPorts– another package manager – you can acchieve the same results with that system. It is also possible to use my Homebrew solution in parallel to an existing MacPorts installation on your machine.)
(Note 2: If you want to read all the details about the installation process, have a look at the Homebrew basic installationand the Homebrew PHP installationinformation. But you really won't need that if you follow these steps.)
(注 1:我在这里使用Homebrew,一个 OS X 的包管理系统。如果你熟悉MacPorts——另一个包管理器——你可以用那个系统获得相同的结果。也可以同时使用我的 Homebrew 解决方案一个现有的 MacPorts 安装在您的机器上。)
(注 2:如果您想阅读有关安装过程的所有详细信息,请查看Homebrew 基本安装和Homebrew PHP 安装信息。但如果你按照这些步骤。)
Now let's go...
现在我们走...
First install Xcode from App Store. If you already have it, check App Store again, to make sure you've got the latest version!
首先从 App Store安装Xcode。如果您已经拥有它,请再次检查 App Store,以确保您拥有最新版本!
Now you need to install the Xcode Command Line Tools. To do so, open a Terminal and enter:
现在您需要安装Xcode Command Line Tools。为此,请打开终端并输入:
xcode-select --install
The next command will install the Homebrew package manager system:
下一个命令将安装 Homebrew 包管理器系统:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The script explains what it will do and then pauses before it does it.
脚本解释了它会做什么,然后在它做之前暂停。
The next command to enter is a kind of system status test:
下一个要输入的命令是一种系统状态测试:
brew doctor
This checks the basics of the Homebrew installation.
I got a warning "You have MacPorts or Fink installed: /opt/local/bin/port ..."which I ignored successfully. ;)
这将检查 Homebrew 安装的基础知识。
我收到一条警告“您安装了 MacPorts 或 Fink:/opt/local/bin/port ...”,我成功忽略了它。;)
Now setup the homebrew/dupes tap which has dependencies we need:
现在设置 homebrew/dupes tap ,它具有我们需要的依赖项:
brew tap homebrew/dupes
Setup the homebrew/versions tap which also has dependencies we need:
设置 homebrew/versions tap,它也有我们需要的依赖项:
brew tap homebrew/versions
Then run the following command:
然后运行以下命令:
brew tap homebrew/homebrew-php
Now you are ready to finally build PHP. For a list of available configuration options you may run one of these:
现在您已准备好最终构建 PHP。有关可用配置选项的列表,您可以运行以下选项之一:
brew options php55
brew options php56
But I was fine just using the defaults.
To do so enter ONEof these two, depending on your needs:
但我只是使用默认值就可以了。
要做到这一点进入ONE这两个,这取决于你的需求:
brew install php55
brew install php56
(This takes a while, please be patient!)
(这需要一段时间,请耐心等待!)
while installing php56 (5.6.x) on Yosemite (10.10.5) there is a bug please see this issueon github. use
brew install php56 --without-ldap
instead.
在 Yosemite (10.10.5) 上安装 php56 (5.6.x) 时有一个错误,请在 github 上查看此问题。使用
brew install php56 --without-ldap
来代替。
If you get an error of type "Cannot find OpenSSL's "you have not installed the Xcode Command Line Tools as I told you in the beginning. ;) Go ahead, install them and re-run that last command.
如果您收到“无法找到 OpenSSL 的”类型的错误,则说明您没有安装 Xcode 命令行工具,正如我在开始时告诉您的那样。;) 继续,安装它们并重新运行最后一个命令。
PHP is built now and the script will end with some details about how to use it:
PHP 现已构建完成,脚本将以有关如何使用它的一些详细信息结束:
Open httpd.conf (should be located at /private/etc/apache2/httpd.conf) and enable PHP by adding ONEof these two lines, depending on which PHP version you just installed:
打开httpd.conf文件(应该位于/private/etc/apache2/httpd.conf),并通过添加使PHP ONE这两条线的,这取决于您刚安装上的PHP版本:
LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
Don't forgetto comment out any existing LoadModule php5_module...line that might be present from Yosemite's own PHP version!
不要忘记注释掉Yosemite 自己的 PHP 版本中可能存在的任何现有LoadModule php5_module...行!
Restart Apache
重启阿帕奇
sudo apachectl restart
Your new php.ini file can be found in: /usr/local/etc/php/5.5/php.ini
您可以在以下位置找到新的 php.ini 文件:/usr/local/etc/php/5.5/php.ini
Enjoy!
享受!
回答by Patrick D'appollonio
The answer from @Jpsy is good, but there's another option, from the guys from liip, here. This is a PHP package that comes pre-built for Yosemite (older versions works too) but it is just one lineof code:
@Jpsy 的回答很好,但还有另一种选择,来自 liip 的人,这里。这是一个为 Yosemite 预先构建的 PHP 包(旧版本也可以),但它只是一行代码:
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5
After that, everything is ready to work as expected. The configuration that cames with that installation is well suited for Symfony 2 development, but it should work just fine with other use cases.
之后,一切准备就绪,可以按预期工作。该安装附带的配置非常适合 Symfony 2 开发,但它应该适用于其他用例。
Finally, if you need to use the updated PHP CLI, too, but you don't want to use the PHP version that comes with the OS, then you could also add to your .bash_profile
or similar this line of code:
最后,如果您也需要使用更新的 PHP CLI,但您不想使用操作系统附带的 PHP 版本,那么您还可以添加到您的.bash_profile
或类似的这行代码中:
export PATH=/usr/local/php5/bin:$PATH
export PATH=/usr/local/php5/bin:$PATH
回答by user1618341
I don't have enough rep to make a comment, but if you're using OS X Server for Yosemite (Version 4 from the App Store) the file to edit is:
我没有足够的代表发表评论,但如果您使用 OS X Server for Yosemite(来自 App Store 的第 4 版),要编辑的文件是:
/library/server/web/config/apache2/httpd_server_app.conf
/library/server/web/config/apache2/httpd_server_app.conf
mine looks like this now and confirmed it is working after using php 5.6 from homebrew.
我的现在看起来像这样,并在使用自制软件的 php 5.6 后确认它正在工作。
#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
回答by a7d0rn
Standard Apache coming with Yosemite the file to update after
标准 Apache 随 Yosemite 一起提供要更新的文件
sudo brew install php55
is in /etc/apache2/httpd.conf
在 /etc/apache2/httpd.conf
Note that location of php.ini is also changed. The standard one coming with Yosemite is in /etc/php.ini, the one with homebrewed version is in /usr/local/etc/php/5.5/php.ini
请注意,php.ini 的位置也发生了变化。Yosemite 的标准版本在 /etc/php.ini 中,自制版本在/usr/local/etc/php/5.5/php.ini