简体   繁体   English

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

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

Trying to use PHP 8.1 on localhost with Mac OS High Sierra (10.13.6) .尝试在Mac OS High Sierra (10.13.6)localhost上使用PHP 8.1 Note that I also want to keep PHP 7.4, because I still need it for older projects.请注意,我还想保留 PHP 7.4,因为旧项目仍然需要它。

It doesn't work and error logs shows nothing.它不起作用,错误日志什么也没有显示。

What I did so far到目前为止我做了什么

  • Installed PHP 8.1 using brew brew install php@8.1使用 brew brew install php@8.1安装 PHP 8.1
  • Edited and sourced .zshrc with the path使用路径编辑和获取.zshrc
export PATH="/usr/local/opt/php@8.1/bin:$PATH"
export PATH="/usr/local/opt/php@8.1/sbin:$PATH"
  • Edited httpd.conf , added the following line LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so and commented other php modules编辑httpd.conf ,添加以下行LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so并注释其他 php 模块
  • Edited httpd-vhosts.conf with the following conf:使用以下 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>
  • edited /etc/hosts/ , added the domain: 127.0.0.1 my-project.local编辑/etc/hosts/ ,添加域: 127.0.0.1 my-project.local
  • restarted apache sudo apachectl restart重新启动 apache sudo apachectl restart

Result结果

The index.php file is read, but PHP is not working.读取index.php文件,但 PHP 不起作用。

I've put <?php phpinfo(); ?>我把<?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. <?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. When reaching http://my-project.local with Chrome I see the PHP as plain text.当使用 Chrome 到达http://my-project.local时,我将 PHP 视为纯文本。

Notes笔记

  • When switching back to PHP 7.4, everything works fine切换回 PHP 7.4 时,一切正常
  • Tried to add the following code to httpd.conf尝试将以下代码添加到httpd.conf
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

but it doesn't help, actually in this case index.php is not read and I got the error The connection has been reset but nothing is shown in error logs, either access logs.但它并没有帮助,实际上在这种情况下index.php没有被读取,我得到了错误The connection has been reset ,但错误日志中没有显示任何内容,无论是访问日志。

I don't understand what's going on, everything seems good to me, if somebody could help me?我不明白发生了什么,一切对我来说似乎都很好,如果有人可以帮助我吗?

Thanks谢谢

Found the solution, I had to add index.php to DirectoryIndex which had only index.html找到解决方案,我必须将index.php添加到只有index.htmlDirectoryIndex

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

Now everything works fine现在一切正常

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

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