You can add brew php module to MacOS Monterey apache. Follow all the steps properly.
After installing homebrew php (brew install php / brew install [email protected]) and adding the following lines in /etc/apache2/httpd.conf
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
IMPORTANT: You need to test the apache2 config by running the following command. If you don't run this you will never understand why it is not working.
sudo apachectl configtest
If you get an error that no code signing authority like below
[so:error] [pid 69894] AH06665: No code signing authority for module at /.../libphp[7].so specified in LoadModule directive.
You need to follow the tutorial here or https://blog.phusion.nl/2020/12/22/future_of_macos_apache_modules/ to create your local CA file & Certificate and use the below command to sign the libphp.so file. Note: replace Ravi with your certificate name
codesign -s "Ravi" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
# codesign -s "Ravi" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
Now go back to /etc/apache2/httpd.conf and add "Ravi" (your certificate name) at the end of the LoadModule line like this
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so "Ravi"
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so "Ravi"
After doing it run
sudo apachectl configtest
and you should see at the end (ignore notice line)
Syntax OK
phpinfo()
call in the default/Library/WebServer/Documents
). I would pay special attention to anything in theincludes
, such as vhosts.conf, and any .htaccess files that might be getting in the way. Adding those may help the question.