Getting Apache 2.4.9 + PHP 5.5.14 Going on OS X 10.10 Yosemite
This morning I thought I'd just check on the status of Apache + PHP + Postgres on OS X 10.10 as it was likely that in the update from 10.9, Apple had changed things, and sure enough, they have. But it wasn't all them - Apache has some changes in it as well, so to be fair, getting this all to run is a little more complex than you might imagine, but it's still not all that hard.
Getting PostgreSQL 9.3
As with the previous post I'm using Homebrew and that's made the entire operation a lot smoother. There's no 32-bit/64-bit issue as Homebrew does both, and it builds in on your box, so again, a lovely customized solution with a simple command:
$ brew install postgresql
It even has a nice, simple informational blurb about how to start/stop and upgrade. Very nice. But now that it's on the box, and ready to roll, let's add in the PostgreSQL support to the PHP 5.5.14 that's installed with Mac OS X 10.10.
Activating UserDir in Apache 2.4.9
The first thing I noticed is that 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 166 needs to be uncommented to read:
LoadModule userdir_module libexec/apache2/mod_userdir.so
and then similarly on line 493 uncomment the line to read:
Include /private/etc/apache2/extra/httpd-userdir.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 AllowOverride None Order allow,deny Allow from all 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 OS X 10.10. This is line 169 in the file - /etc/apache2/httpd.conf and you need to uncomment it to read:
LoadModule php5_module libexec/apache2/libphp5.so
and then add a new file called /etc/apache2/other/php5.conf and have it contain:
<IfModule php5_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.
Building in PostgreSQL 9.3 extra for PHP 5.5.14
At this point we need to get the source code for the exact version of PHP that Apple ships. This is pretty easy by getting the PHP 5.5.14 source from a mirror and unpacking it into a directory. We then just run the following commands:
$ cd php-5.5.14/ext/pgsql/ $ phpize $ ./configure $ make
at the end of this process, you'll have a file: php-5.5.14/ext/pgsql/modules/pgsql.so and that needs to be placed in the right directory and referenced in the php.ini file.
For Mac OS X 10.10.1, this is accomplished with:
$ sudo cp modules/pgsql.so /usr/lib/php/extensions/no-debug-non-zts-20121212/
and then edit the /etc/php.ini file to include this new extension by adding the line:
extension=pgsql.so
Thankfully, the extension_dir is already set in OS X 10.10.1, and we no longer have to set that.
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:
All is working once again!