[英]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到目前为止我做了什么
brew install php@8.1
brew install php@8.1
安装 PHP 8.1.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"
httpd.conf
, added the following line LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so
and commented other php moduleshttpd.conf
,添加以下行LoadModule php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so
并注释其他 php 模块httpd-vhosts.conf
with the following 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/
, added the domain: 127.0.0.1 my-project.local
/etc/hosts/
,添加域: 127.0.0.1 my-project.local
sudo apachectl restart
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笔记
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.html
的DirectoryIndex
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Now everything works fine现在一切正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.