phpmacosapachehttpd.confvhosts

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

export PATH="/usr/local/opt/php@8.1/bin:$PATH"
export PATH="/usr/local/opt/php@8.1/sbin:$PATH"
<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>

Result

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

I've put <?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

<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


Solution

  • 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