Add PHP to Apache on MacOS 12

Nadine Fisch
2 min readFeb 16, 2023

--

After PHP has been removed from Apache on macOS 12, you have to manually install, sign, and include it.

#PHP was deprecated in macOS 11 and removed from macOS 12

First of all you need to install PHP. It can be installed with Homebrew. Homebrew is a free/open source package manager that simplifies the installation of software on macOS and Linux operating systems.

To install Homebrew, please paste the line below in your terminal.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

To install the current php version, please paste the line below in your terminal

brew install php

Start PHP

brew services start php

To enable PHP in Apache add the following to httpd.conf

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

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

If PHP is not signed yet, you will get an error after loading your webpage. Please paste the line below in your terminal, to get a specific error message.

apachectl -t -D DUMP_VHOSTS 

Code signing absent error

 [so:error] [pid 26035] AH06665: No code signing authority for module at /opt/homebrew/opt/php/lib/httpd/modules/libphp.so specified in LoadModule directive.
httpd: Syntax error on line 182 of /private/etc/apache2/httpd.conf: Code signing absent - not loading module at: /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

How to sign homebrew PHP module in macOS

First you have to create Certificate Authority for codesignin and afterwards code signing signature with Key Chain Acces.

Afterwards you have to sign PHP with the new generated keychain.

codesign --sign "your-authority-name" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

in the file httpd.conf you append the Authorityname of the generated certificate to the line of loading the PHP Module.

LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so "your-authority-name"

Restart you apache server

sudo apachectl -k restart

--

--