简体   繁体   中英

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) . Note that I also want to keep PHP 7.4, because I still need it for older projects.

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
  • Edited and sourced .zshrc with the path
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
  • Edited httpd-vhosts.conf with the following 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
  • restarted apache sudo apachectl restart

Result

The index.php file is read, but PHP is not working.

I've put <?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. When reaching http://my-project.local with Chrome I see the PHP as plain text.

Notes

  • When switching back to PHP 7.4, everything works fine
  • Tried to add the following code to 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.

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

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

Now everything works fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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