4

I try to install php on a mac M1 monterey, but this simple code is not interpretated :

<?php phpinfo(); ?>

I installed php with brew

brew install php
brew link php

I signed the libphp module

codesign --sign "certificate" --force --keychain ~/Library/Keychains/ /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so

Should I use the dynamic link instead ?

/opt/homebrew/opt/php/lib/httpd/modules/libphp.so

Loading the module in the apache2.conf file

LoadModule php_module /opt/homebrew/Cellar/php/8.1.2/lib/httpd/modules/libphp.so "certificate"

enable php page to be view in the apache2.conf file

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>

result of which php

/opt/homebrew/bin//php

Is the double slash normal here ?

I can access the index.php of my web directory but php is still not executed.

Thanks

krifur
  • 870
  • 4
  • 16
  • 36
  • 1
    have a look at this guide https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey/. . I know you probably already done most the steps but there is a section at end that mentions extra step for php8 – RyDog Apr 08 '22 at 14:51
  • 2
    I got frustrated with the inbuilt Apache and decided to just ditch it and go with homebrew version of Apache – RyDog Apr 08 '22 at 14:55
  • Thx RyDoy ! I missed the FilesMatch section, now it's working. Yes It s been a while I try to figure out myself as I m new to mac (coming from debian) I found it quite complicated, I will keep your word for apache in case I get into new trouble (hope not) I should give you the checkmark (maybe you can make a post with the FilesMatch section, I think it will help a lot of people) – krifur Apr 08 '22 at 15:02

2 Answers2

8

As I mentioned in the comments you probably done most the steps but this guide I found has one last step it mentions for PHP. Here is the link:

https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey/

Also I found a lot of my issues went away when I started using homebrew Apache instead.

I am glad the guide was able to help you get it working.

For anyone else who is stuck, here is the relevant section from the guide:

PHP 8 and macOS Apache

One extra step is needed for PHP 8 and macOS bundled Apache:

sudo nano /etc/apache2/httpd.conf

Add the new PHP 8 and comment out the old one.

LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

Go to the end of the file and add:

<FilesMatch .php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Restart Apache

RyDog
  • 1,169
  • 1
  • 9
  • 12
1

Sometimes php configs are added through "other" configs if you have a line as below at the end of your httpd.conf

Include /private/etc/apache2/other/*.conf

Check config files under /private/etc/apache2/other/ and make necessary changes. I had a file called +php-osx.conf in that folder I edited as following:

LoadModule php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so

<FilesMatch .php$>
    SetHandler application/x-httpd-php
</FilesMatch>


<IfModule php_module>
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps

        <IfModule dir_module>
                DirectoryIndex index.html index.php
        </IfModule>
</IfModule>
xgmexgme
  • 132
  • 7