2

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(); ?> + 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

Simon Mo
  • 503
  • 2
  • 4
  • 14
  • Please explain `The index.php file is read, but PHP is not working` - you get errors (assuming error reporting is _on_), get PHP code back as plain text, etc? – Justinas Aug 04 '22 at 07:58
  • Hi, I've put `` + some random HTML on my `index.php`, when opening `http://my-project.local` I only see the HTML, phpinfo is not showing, not even as plain text, just blank. Just tried to add error reporting with `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);` and still the same result : nothing but HTML is shown, but no PHP as plain text or error – Simon Mo Aug 04 '22 at 08:11
  • edit: in Chrome I actually see the PHP as plain text. On Firefox it's hidden. Will edit my post accordingly – Simon Mo Aug 04 '22 at 11:43

1 Answers1

0

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

Simon Mo
  • 503
  • 2
  • 4
  • 14