Apache可以在MacOS上加载PHP7模块 - 蒙特雷
我已经安装了 [email  procepted] 在我的Mac上进行啤酒。一切正常,但是当我在Safari打开Localhost时,它只是向我展示PHP代码。
我的代码:
<?php
echo "Hello world";
以及Localhost的结果: 在localhost上结果
我认为这是我的问题。我将此行添加到http.conf文件中,而Localhost中没有任何作用(Safari无法连接到服务器“ Local -Host”)。
LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
I have installed [email protected] with brew on my Mac. Everything works fine but when I open localhost in Safari, it just show me php codes.
My code :
<?php
echo "Hello world";
and the result on localhost :
result on localhost
I think this is my problem. I added this line to http.conf file and nothing worked in localhost (Safari can't connect to server "localhost").
LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我找到了解决方案。 MACOS中的Gatekeeper确保只能执行经过验证的应用程序,这是通过使用CodeSign签署应用程序来实现的。自MacOS Monterey以来,代码签名是Macos Big Sur的可选,但必须强制性。
未使用Homebrew安装的PHP模块签名,因此您需要先签署它,然后才能使用。
在我可以使用CodeSign实用程序签署PHP模块之前,我创建了代码签名和代码签名证书的证书授权。
步骤1:
如何在macos中创建代码签名证书授权
步骤2 :
如何在macos中创建MacOS中的代码签名证书
来自Apache的PHP LoadModule指令的PHP模块的位置或路径。
步骤4:使用您创建的代码签名证书名称的codeSign的符号PHP模块。
步骤5:
使用您首选的文本编辑器打开带有PHP LoadModule指令的Apache配置文件。
步骤6:
在PHP LoadModule指令中的模块路径后,添加代码签名证书名称。
然后重新启动apache。
Finally I found the solution. Gatekeeper in macOS ensures only verified applications can be executed and this is achieved by signing the application using codesign. Code signing has been optional on macOS Big Sur and prior but mandatory since macOS Monterey.
PHP module installed using homebrew is not signed, so you need to sign it first before it can be used.
I create a Certificate Authority for code signing and a code signing certificate before I can sign the PHP module using codesign utility.
Step 1 :
How to create Certificate Authority for Code Signing in macOS
Step 2 :
How to create code signing certificate in macOS
Step 3 : Locate location or path of PHP module from Apache's PHP LoadModule directive.
Step 4 : Sign PHP module using codesign with the code signing certificate name you've created.
Step 5 :
Open Apache configuration file with PHP LoadModule directive using your preferred text editor.
Step 6 :
Add code signing certificate name after module path in PHP LoadModule directive.
Then restart the apache.