Home > Net >  Using PHP 8.1 on Mac OS 10.13 with Vhost
Using PHP 8.1 on Mac OS 10.13 with Vhost

Time:08-19

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 [email protected]
  • Edited and sourced .zshrc with the path
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
  • Edited httpd.conf, added the following line LoadModule php_module /usr/local/opt/[email protected]/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(); ?> 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

CodePudding user response:

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

  • Related