繁体   English   中英

在带有 Vhost 的 Mac OS 10.13 上使用 PHP 8.1

[英]Using PHP 8.1 on Mac OS 10.13 with Vhost

尝试在Mac OS High Sierra (10.13.6)localhost上使用PHP 8.1 请注意,我还想保留 PHP 7.4,因为旧项目仍然需要它。

它不起作用,错误日志什么也没有显示。

到目前为止我做了什么

  • 使用 brew brew install php@8.1安装 PHP 8.1
  • 使用路径编辑和获取.zshrc
export PATH="/usr/local/opt/php@8.1/bin:$PATH"
export PATH="/usr/local/opt/php@8.1/sbin:$PATH"
  • 编辑httpd.conf ,添加以下行LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so并注释其他 php 模块
  • 使用以下 conf 编辑httpd-vhosts.conf
<VirtualHost *:80>
    ServerName my-project.local
    DocumentRoot "/Library/WebServer/Documents/my-project"
    ErrorLog "/private/var/log/apache2/my_project-error_log"
    CustomLog "/private/var/log/apache2/my_project-access_log" common
    <Directory  "/Library/WebServer/Documents/my-project/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>
  • 编辑/etc/hosts/ ,添加域: 127.0.0.1 my-project.local
  • 重新启动 apache sudo apachectl restart

结果

读取index.php文件,但 PHP 不起作用。

我把<?php phpinfo(); ?> <?php phpinfo(); ?> + some random HTML on my index.php, when opening http://my-project.local with Firefox I only see the HTML, phpinfo is not showing, not even as plain text, just blank. 当使用 Chrome 到达http://my-project.local时,我将 PHP 视为纯文本。

笔记

  • 切换回 PHP 7.4 时,一切正常
  • 尝试将以下代码添加到httpd.conf
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

但它并没有帮助,实际上在这种情况下index.php没有被读取,我得到了错误The connection has been reset ,但错误日志中没有显示任何内容,无论是访问日志。

我不明白发生了什么,一切对我来说似乎都很好,如果有人可以帮助我吗?

谢谢

找到解决方案,我必须将index.php添加到只有index.htmlDirectoryIndex

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

现在一切正常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM