php Homebrew 安装的 PHP7 不适用于 macOS 上的 Apache
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39456022/
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
PHP7 installed by Homebrew doesn't work with Apache on macOS
提问by Arthur
I am trying to upgrade to php7 which I installed via homebrew.
我正在尝试升级到我通过自制软件安装的 php7。
In CLI php -v returns
在 CLI 中 php -v 返回
PHP 7.0.10 (cli) (built: Aug 21 2016 19:14:33) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
But for localhost, firefox pops up a problem loading page, and I can't view a localhost/phpinfo.php; if I swap the module lines out back to php5 it works fine.
但是对于localhost,firefox弹出加载页面有问题,无法查看localhost/phpinfo.php;如果我将模块行换回 php5,它就可以正常工作。
Here's a pastebin http://pastebin.com/950yC7wAof my apache2/httpd.conf, I have no idea how to go about fixing this.
这是我的 apache2/httpd.conf的 pastebin http://pastebin.com/950yC7wA,我不知道如何解决这个问题。
- osx version El Capitan 10.11
- osx 版本 El Capitan 10.11
回答by kenorb
Make sure that:
确保:
You've followed the instructions from
brew info [email protected]
:==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html
You restarted Apache via
sudo apachectl restart
.
您已按照以下说明操作
brew info [email protected]
:==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html
您通过
sudo apachectl restart
.
For step by step tutorial, see: Setup Apache, MySQL and PHP using Homebrew on macOS Sierra.
有关分步教程,请参阅:在 macOS Sierra 上使用 Homebrew 设置 Apache、MySQL 和 PHP。
Troubleshooting
故障排除
When something doesn't work, check the logs in real-time via:
tail -f /usr/local/var/log/apache2/*error*
Then start/restart the server.
Note: When finished, hit Control-Cto quit
tail
.
当某些事情不起作用时,请通过以下方式实时检查日志:
tail -f /usr/local/var/log/apache2/*error*
然后启动/重启服务器。
注意:完成后,点击Control-C退出
tail
。
回答by Jason McCreary
While Homebrewis an excellent tool, it is unnecessary at times.
虽然Homebrew是一个很好的工具,但有时它是不必要的。
I mention in my posts on Installing Apache, PHP, and MySQL on Mac OS X, OS X comes with Apache and PHP pre-installed. As such, you simply have to configure and enable them.
我在关于在 Mac OS X上安装 Apache、PHP 和 MySQL 的帖子中提到,OS X 预装了 Apache 和 PHP。因此,您只需配置和启用它们。
Unfortunately, as of Mac OS 10.11 (El Capitan), the PHP version is still 5.5. I imagine this will change with 10.12 (Sierra) since PHP 5.5 is EOL. However, it may only be PHP 5.6.
不幸的是,从 Mac OS 10.11 ( El Capitan) 开始,PHP 版本仍然是 5.5。我想这会随着 10.12 ( Sierra) 而改变,因为 PHP 5.5 是 EOL。但是,它可能只是 PHP 5.6。
For installing PHP 7, I recommend using PHP OSX. They offer package installs for PHP versions 5.3 to 7.1 (latest). It's available for Mac OS 10.6+ (Snow Leopard).
对于安装 PHP 7,我建议使用PHP OSX。他们为 PHP 版本 5.3 到 7.1(最新)提供软件包安装。它适用于 Mac OS 10.6+ ( Snow Leopard)。
Since it is a package install, it works out of the box with the default Apache install. You'll only need to update your PATH
and modify their PHP ini file. Both of which are outlined in their FAQ.
因为它是一个包安装,所以它可以使用默认的 Apache 安装开箱即用。您只需要更新PATH
和修改他们的 PHP ini 文件。两者都在他们的常见问题解答中进行了概述。
If you want a more step by step tutorial, check out my recent post on Updating PHP on Mac OS X.
如果您想要更多的分步教程,请查看我最近关于在 Mac OS X上更新 PHP 的帖子。
回答by Flo Schild
If you are using Apache on OS X Sierra, php7 does not come with the apache module by default anymore.
如果您在 OS X Sierra 上使用 Apache,默认情况下 php7 不再附带 apache 模块。
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-apache option. See brew options php70 for more details.
随着 macOS Sierra 的发布,Apache 模块现在不是默认构建的。如果你想在你的系统上构建它,你必须使用 --with-apache 选项安装 php。有关更多详细信息,请参阅 brew 选项 php70。
Try reinstalling with the flag:
尝试使用标志重新安装:
brew reinstall php70 --with-apache
回答by dmac
I had the same problem and it went away when I commented out this line in /etc/apache2/httpd.conf
我遇到了同样的问题,当我在中注释掉这一行时它就消失了 /etc/apache2/httpd.conf
LoadModule php5_module libexec/apache2/libphp5.so
回答by Ben Cummins
Not a direct solution to your problem, but I've had countless issues with php on OS X. Most recently was trying to get OCI libraries working after upgrading to El Capitan.
不是您问题的直接解决方案,但我在 OS X 上遇到了无数的 php 问题。最近,我试图在升级到 El Capitan 后让 OCI 库正常工作。
I've given up trying to use it now and began using docker for my development. I find it as a far better solution and you can even set up multiple environments on the same code base which is really useful for testing different versions.
我现在已经放弃尝试使用它并开始使用 docker 进行我的开发。我发现它是一个更好的解决方案,您甚至可以在同一代码库上设置多个环境,这对于测试不同版本非常有用。
Docker is really easy to set up on OS X, and has a huge range of prebuilt containers available in the repository, you just install and set the mount point to your source directory and use the port it gives you to access.
在 OS X 上安装 Docker 真的很容易,并且在存储库中有大量可用的预构建容器,您只需安装并将挂载点设置到源目录并使用它提供的端口即可访问。
回答by HPierce
Running $ apachectl -t
will show any issues with your current configuration. When I ran it I got this:
运行$ apachectl -t
将显示您当前配置的任何问题。当我运行它时,我得到了这个:
httpd: Syntax error on line 171 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/opt/php70/libexec/apache2/libphp7.so into server: dlopen(/usr/local/opt/php70/libexec/apache2/libphp7.so, 10): Symbol not found: _ldap_control_find\n Referenced from: /usr/local/opt/php70/libexec/apache2/libphp7.so\n Expected in: /System/Library/Frameworks/LDAP.framework/Versions/A/LDAP\n in /usr/local/opt/php70/libexec/apache2/libphp7.so
httpd:/private/etc/apache2/httpd.conf 第 171 行的语法错误:无法将 /usr/local/opt/php70/libexec/apache2/libphp7.so 加载到服务器中:dlopen(/usr/local/opt/php70 /libexec/apache2/libphp7.so, 10): 找不到符号:_ldap_control_find\n 引用自:/usr/local/opt/php70/libexec/apache2/libphp7.so\n 预期在:/System/Library/Frameworks/ LDAP.framework/Versions/A/LDAP\n 在 /usr/local/opt/php70/libexec/apache2/libphp7.so
I can confirm this workaround posted on github, installing the package without LDAP support will prevent this error:
我可以确认发布在 github 上的此解决方法,安装没有 LDAP 支持的包将防止出现此错误:
brew reinstall php70 --without-ldap
回答by Vincent Moulene
I discover today a new path to load the differents php libraries in the httpd.conf file (/usr/local/etc/httpd/httpd.conf) :
我今天发现了一个新路径来加载 httpd.conf 文件(/usr/local/etc/httpd/httpd.conf)中的不同 php 库:
### OLD VERSION (NOT WORKING NOW) ###
#LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
#LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
#LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
#LoadModule php7_module /usr/local/opt/php72/libexec/apache2/libphp7.so
### NEW VERSION ###
#LoadModule php5_module /usr/local/opt/php56/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php70/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/php71/lib/httpd/modules/libphp7.so
LoadModule php7_module /usr/local/opt/php72/lib/httpd/modules/libphp7.so
回答by Naresh Dhiman
For the folks who may experience this issue, make sure you are able to restart apache using "apachectl restart". In my case, I had to first stop all processes of httpd using command "httpd stop" and then start apache using "apachectl start".
对于可能遇到此问题的人,请确保您能够使用“apachectl restart”重新启动 apache。就我而言,我必须首先使用命令“httpd stop”停止 httpd 的所有进程,然后使用“apachectl start”启动 apache。
回答by Wordica
I know it's very old topic but when You update PHP You also need to update Apache confing - for example:
我知道这是一个非常古老的话题,但是当您更新 PHP 时,您还需要更新 Apache confing - 例如:
LoadModule php5_module libexec/apache2/libphp5.so
change to:
改成:
LoadModule php7_module libexec/apache2/libphp7.so