Setting the Apache 2.4 PATH environment variable in a brew services started httpd process

Written by James McDonald

December 15, 2016

Note the following perl script

#!/usr/bin/env perl -wT
print "Content-type: text/html\n\n";
foreach $key (sort keys(%ENV)) {
  print "$key = $ENV{$key}<p>";

As you can see the hash bang is #!/usr/bin/env perl  this is supposed to be more portable because it will find the first instance of perl in your path so if you put /usr/local/bin first in the PATH you get your Homebrew installed Perl

The problem is the above script wouldn’t find the Homebrew Perl because my Homebrew Apache 2.4 PATH was PATH = /usr/bin:/bin:/usr/sbin:/sbin

This wouldn’t be a problem except I had installed JSON, Config::Simple and other Perl modules in the Homebrew Perl under /usr/local and when I ran the CGI script that used these against the above default PATH they were erroing out with and @INC error because of not finding the Perl modules under the system Perl in /usr/bin/perl

It took me a while of Googling to find out how to configure the plist file to pass a new environment in but here it is. I hope it saves someone 2 hours.

So firstly shut your httpd24 down

brew services stop httpd24

edit your homebrew.mxcl.httpd24.plist file  and add the EnvironmentVariables key and the following <dict> to it

vim /usr/local/Cellar/httpd24/2.4.23_2/homebrew.mxcl.httpd24.plist

restart your httpd

brew services stop httpd24

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
  <!-- add this -->
  <!-- end add -->



Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…