1

I'm running macOS 10.15 (Catalina) and have installed the latest Apache (2.4.43) using brew, basically following these steps.

Seems to be working fine, but now I want to enable PHP 7 in Apache as well.

I have the default PHP that comes with macOS Catalina (php -v says 7.3.11) however Apache's module dir (at least the latest Apache I installed with Home Brew) does not seem to contain any php modules.

I'm quite unsure what LoadModule line I have to add in httpd.conf in order to get PHP 7 working in my Apache server. And how or where I should get a PHP 7 .so module file if necessary.

When searching around I find all sorts of different approaches, including installing custom versions of PHP but I'm somewhat reluctant of the risk of messing up my current installation.

Is there an easy, and more importantly: reliable way of enabling PHP 7 in httpd 2.4?

1

Just install php with brew (and leave Apple's PHP alone):

  1. brew install php (requires a lot of additional packets)
  2. Modify /usr/local/etc/httpd/httpd.conf at the end of the LoadModule section (~ line 182) and add

    LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
    
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
    

    Check that DirectoryIndex (~line 286) includes index.php

    DirectoryIndex index.php index.html
    
  3. Start php:

    brew services start php
    
  4. Restart apache

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .