This morning I thought I'd perform the ritual of getting the old web development tools that I've used in the past going again - this time on macOS 10.15 Catalina. Now I haven't used PHP in ages, but I've still got code and databases for Postgres to use that - so it makes sense to get this all working again, and it's always fun to see how things work out.
Getting Postgres 11.1
Loads of coverage here about Postgres, and it's just so simple to get the latest version from Homebrew:
$ brew install postgresql
I've even posted how to upgrade from major version differences, so it's easy to get the latest Postgres running on your box, and the tools are just superb.
Activating UserDir in Apache 2.4.41
As in the previous updates, the UserDir extension is not enabled by default, so we need to get that going right away. This enables the code to be run from the development directories, and that's a big time-saver. First, we need to enable the UserDir module in Apache, and then make a specific config file for the user in question. Start by editing /etc/apache2/httpd.conf and line 183 needs to be uncommented to read:
LoadModule userdir_module libexec/apache2/mod_userdir.so
and then similarly on line 520 uncomment the line to read:
Include /private/etc/apache2/extra/httpd-userdir.conf
Next, make sure that the file we just included is set up right for including the user directories. Edit /etc/apache2/extra/httpd-userdir.conf and line 16 needs to be
uncommented to read:
Include /private/etc/apache2/users/*.conf
At this point, you need to make sure you have at least one file in the /etc/apache2/users/ directory for each user, like: drbob.conf:
<Directory "/Users/drbob/Sites/">
Options FollowSymLinks Indexes MultiViews ExecCGI
Require all granted
</Directory>
where the last line - Require all granted is new as of Apache 2.4, and without it you will get errors like:
[Thu Dec 18 10:41:32.385093 2014] [authz_core:error] [pid 55994]
[client fe80::7a31:c1ff:fed2:ca2c:58108] AH01630: client denied by server
configuration: /Users/drbob/Sites/info.php
Activating PHP in Apache
The mext thing to do is to activate PHP in the supplied Apache 2 with macOS 10.15. This is line 186 in the file - /etc/apache2/httpd.conf and you need to uncomment it to read:
LoadModule php7_module libexec/apache2/libphp7.so
and then verify a file called /etc/apache2/other/php7.conf exists and contains:
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
which does all the other PHP configuration in a separate file to make upgrades easy.
Finishing Up
At this point, a simple restart of apache:
$ sudo apachectl restart
and everything should be in order. Hit a URL that's a static file with the contents:
<?php
phpinfo();
?>
and you should see all the details about the PHP install - including the PostgreSQL section with the version of Postgres indicated:
What's really great is that Apple has included lots of support in the default PHP install:
- PHP 7.3.8
- Postgres 9.3.7
- MySQL 5.0.12
- SQLite3 3.28.0
so there's no reason to do anything more to get the kind of support that I used to get. And I get the other databases for free. This is great news! I then run my little test page to make sure the database connection is working:
and everything is working exactly as expected!