How to install mod_perl 2.0.9 in Apache 2.4 on OS X Yosemite?
Asked Answered
C

4

11

With the release of OS X 10.10 Yosemite, Apple upgraded its Apache server to version 2.4.

At release time, mod_perl 2.0.8 was incompatible with Apache 2.4, and mod_perl 2.0.9 had not yet been officially released (more info).

So, Apache was included without mod_perl.

I work locally on a web site using perl and need to install mod_perl.

I'm an experienced programmer, but I have never done anything like this before and have only my main machine to work on. I don't mind spending some time to figure this out, but I can't afford to bork my local server.

How does one install mod_perl on OS X Yosemite?

Sub-questions:

  • which version should I install?
  • do I download it to the install location or elsewhere?
  • where do I install it?
  • are there other dependencies that need to be installed beforehand?
  • do I have to re-create the apache install or is the mod_perl installation self-contained?

I'm experienced in bash and very comfortable using Terminal.

Cryolite answered 21/10, 2014 at 9:48 Comment(1)
I'm wondering this myself. I tried yesterday to compile it from source (github.com/apache/mod_perl/tree/trunk) The git repo didn't have some dependencies so I grabbed those from the 2.0 source (apache.org/dist/perl/mod_perl-2.0-current.tar.gz). I was able to run perl Makefile.PL and make but make test failed and I was unable to run make install. no mod_perl.so file was created (which is required for the make test step. I gave up for now, perhaps you'll have better luck.Manpower
M
12

mod_perl 2.0.8 (latest stable) won't cut it--it's unaware of the deprecation of MPM_NAME in apache 2.4.x Download the latest dev via svn:

svn checkout https://svn.apache.org/repos/asf/perl/modperl/trunk/ mod_perl-2.0

The Changes file lists this version as 2.0.9-dev

Xcode 6.01 won't cut it--it's apache headers will make mod_perl think you're running apache 2.2.26; get Xcode 6.1 (released Oct 20).

Makefile.PL will still have trouble finding ap_release.h (to get your apache version). It's here:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apache2/ap_release.h

Makefile.PL will look by default in /usr/include/apache2. It will also look for apr headers in /usr/include/apr-1 because the Yosemite-included /usr/bin/apr-1-config will tell it that's where they are (they're actually in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apr-1 )

/usr/bin/apr-1-config --includedir
/usr/include/apr-1

I tried setting env vars MP_AP_PREFIX and MP_APR_CONFIG appropriately, but those values seemed to be ignored. So I made things easier on myself:

$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apache2 /usr/include/apache2

$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apr-1 /usr/include/apr-1

(thanks to Sean Coyne) Per Jason A. Crome's blog post "llvm/clang on OS X defaults to C99, but mod_perl expects the 89 "standard"

$ perl Makefile.PL MP_CCOPTS=-std=gnu89; make ; sudo make install

The LoadModule line for mod_perl has been removed from Yosemite's /etc/apache2/httpd.conf file.
Add

LoadModule perl_module libexec/apache2/mod_perl.so

to the module section of /etc/apache2/httpd.conf

Manchukuo answered 21/10, 2014 at 22:27 Comment(7)
I followed these steps and it seemed to compile correctly, it did build the mod_perl.so file, but I see the following when running apachectl configtest: httpd: Syntax error on line 111 of /private/etc/apache2/httpd.conf: Cannot load libexec/apache2/mod_perl.so into server: dlopen(/usr/libexec/apache2/mod_perl.so, 10): Symbol not found: _modperl_handler_anon_add\n Referenced from: /usr/libexec/apache2/mod_perl.so\n Expected in: flat namespace\n in /usr/libexec/apache2/mod_perl.soManpower
OK, figured it out. Apparently clang defaults to the wrong standard for mod_perl, so you need to run perl Makefile.PL MP_CCOPTS=-std=gnu89 ; make ; sudo make install instead. Credit: blogs.perl.org/users/jason_a_crome/2012/04/…Manpower
Just found this myself from Jason Crome [link]blogs.perl.org/users/jason_a_crome/2012/04/…Manchukuo
@AndrewSwift Dan's answer works. He has edited it to make the change I mentioned.Manpower
It worked! Thanks so much. I will write up a simple answer with a list of the steps and a few notes, but choose this answer as correct.Cryolite
And to solve the permission problems (changing from apache2.2 to apache 2.4) you have to replace 'Order allow,deny Allow from all' by 'Require all granted' (see #21552340)Cecilla
Thanks for this. Twelve years later, Apache still hasn't fixed this problem, and mod_perl 2.x (released in 2023) has the same issue. Not sure whether to laugh or cry. Probably cry.Engels
C
6

This is a simplified version of Dan Deal's answer, with a few notes for less experienced developers.

You'll need to install Xcode 6.1 from the Mac App Store. Xcode is suite of tools developed by Apple for developing iOS and OS X software. It takes up almost 6gb but can be deleted after this installation.

Start Xcode once to agree to Apple's terms.

In Terminal, change to any temporary directory then download mod_perl 2.0.9-dev: (Caution - the 'any temporary directory' must be on your root volume and must not have any space characters in the directory name; otherwise the make scripts will fail later on)

svn checkout https://svn.apache.org/repos/asf/perl/modperl/trunk/ mod_perl-2.0

Change to the newly created mod_perl directory:

cd mod_perl-2.0

Tell the installer where to look for parts:

/usr/bin/apr-1-config --includedir /usr/include/apr-1
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apache2 /usr/include/apache2
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apr-1 /usr/include/apr-1

(ln -s makes a symbolic link, and the apr-1-config program is used to retrieve information about the apr library, and is typically used to compile and link against the library.)

(Caution - on some Yosemite installations the /usr/include directory does not exist; you may have to create it by cd /usr;mkdir include)

Make mod_perl:

perl Makefile.PL MP_CCOPTS=-std=gnu89; make ; sudo make install

Delete the temporary folder mod_perl-2.0.

Tell apache to include mod_perl in the apache httpd.conf:

sudo vi /etc/apache2/httpd.conf (or)
sudo nano /etc/apache2/httpd.conf

Add the following line at the end of the list of includes, near line 170:

LoadModule perl_module libexec/apache2/mod_perl.so

Save, quit, and restart apache:

sudo apachectl restart
Cryolite answered 24/10, 2014 at 9:1 Comment(7)
I tried to install the way you suggest it, but when running "sudo apachectl configtest" I get "httpd: Syntax error on line 171 of /private/etc/apache2/httpd.conf: Cannot load libexec/apache2/mod_perl.so into server: dlopen(/usr/libexec/apache2/mod_perl.so, 10): image not found". I downloaded the mod_perl to /Users/my.name/tmp and had to run "sudo perl Makefile.PL MP_CCOPTS=-std=gnu89; make ; sudo make install" to make the install work. Any suggestions?Infare
Does "my.name" contain a space? I can't tell from the last part of your comment if you succeeded at the end.Cryolite
No space, the result can be found here #27828224Infare
Please put a link here if you repost it to ServerFault.Cryolite
Where is Makefile.PL located? Or in which directory must I be located when I run the "sudo perl Makefile.PL ..."?Louisville
Well, I found it another directory down, and had to navigate to be there to run the perl Makefile.PL command. mod_perl.so was creaed and placed in the proper place, and I added the LoadModule statement to httpd.conf, and restarted apache, BUT none of my perl-scripts run in my browsers.Louisville
I believe I found the reason none of my perl-scripts were executing. The "httpd.conf" had a #-commented out LoadModule command: LoadModule cgi_module libexec/apache2/mod_cgi.soLouisville
P
6

Extra screwing around required in El Capitan!

In El Capitan, Apple prevents users from writing to anywhere under /usr/ except /usr/local/

Referencing Dan Deal's and Andrew Swift's answers above, and assuming you have Xcode 7 and the El Capitan (10.11) SDK installed:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/apache2 /usr/local/include/apache2
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/apr-1 /usr/local/include/apr-1

Will soft-link the Xcode headers to /usr/local/include.


Next, we need to tell Makefile.PL where to find the headers (since it assumes /usr/include by default).

sudo cp /usr/sbin/apxs /usr/local/bin

to make a copy of the APXS tool which Makefile.PL uses to locate the apache headers. Now edit it:

sudo vi /usr/local/bin/apxs        (or)
sudo nano /usr/local/bin/apxs

locate the line which says:

my $prefix         = get_vars("prefix");

and replace it with:

my $prefix         = "/usr/local";

Ensure that /usr/local/bin is in your path before /usr/sbin, so that it picks up the one you just modified:

export PATH=/usr/local/bin:$PATH

Now you can go ahead and build mod_perl:

perl Makefile.PL MP_CCOPTS=-std=gnu89; make ; sudo make install

Finally, when you edit your httpd.conf, you need to explicitly pass the full path to mod_perl.so, as it's not in the directory that apache expects to find it:

LoadModule perl_module /usr/local/libexec/apache2/mod_perl.so
Paunchy answered 19/9, 2015 at 17:46 Comment(7)
Great! I had already installed it before upgrading to El Capitan, and my previous installation continued to work after the upgrade. This will be very helpful to people who start fresh.Cryolite
Interesting — I had too, and it broke.Paunchy
I started with the first beta and kept upgrading. Did you install the final copy or a beta?Cryolite
I went straight from Yosemite to El Cap GM, so that could be the source of the difference. I assume you left SIP (“rootless”) on?Paunchy
Yes, El Cap is functioning with SIP active. I actually tried to deactivate it but I couldn't get my Mac to restart in recovery mode.Cryolite
Still not there in El Cap. Everything seems to build OK but my test perl cgi script doesn't run, just shows source code. On Yosemite I also had a line in my httpd.conf "LoadModule cgi_module libexec/apache2/mod_cgi.so" as well as the "LoadModule perl_module..." but that doesn't exist so I can't just add it. Not Perl specific as a test Python cgi also doesn't function. Anyone tell me what I'm missing?Cerumen
Not sure how I screwed up but I was was wrong in my comment, above, about cgi. Line 157 in the httpd.conf file in /etc/apache2 has "#LoadModule cgi_module..." and all you need to do is uncomment it to get cgis (perl, python or whatever) to run from your CGI-executables folder. This may be peripheral to the perl_module in the question, but would be useful as part of more general mac/unix setup instructions. Anyone suggest where I might posted it so it gets noticed/indexed?Cerumen
E
0

Thanks for all the pointers above. Here's a solution/receipe, building from source without symbolic linking to odd files within Xcode, and avoiding the 'Expected in: flat namespace' error.

(edit:) To my big surprise the httpd that Apple provides (2.4.16) is now capable of running with my mod_perl!

0 Xcode 7.3 (beta), and command line utils, OS X 10.11.3 El Capitan

1 install perl, with threads:

perlbrew install -f -Dusethreads perl-stable; 

I put perl into /usr/local/perl5/

2 get apr-1.5.2

3 get apr-util-1.5.4

4 get pcre-8.38 (./configure --prefix=/usr/local/pcre; make; make install)

5 get httpd-2.4.9

6 COPY (cp -r -p) the dirs apr-1.5.2 and apr-util-1.5.4 to httpd-2.4.9/srclib/ as 'apr' and 'apr-util' respectively, to be able to use --with-included-apr when building httpd.

7 cd httpd-2.4.9

export CC=/usr/bin/gcc

export CPP=/usr/bin/cpp

./configure --prefix=/usr/local/apache2/ --enable-mods=most --enable-auth-basic --enable-rewrite --with-included-apr --with-pcre=/usr/local/pcre 

make clean 

make 

make install

8 mod_perl-2.0.9

perl Makefile.PL MP_CCOPTS=-std=gnu89 MP_APXS=/usr/local/apache2/bin/apxs

(MP_CCOPTS=-std=gnu89 is VITAL here)

make
make install

Info on build and loaded modules:

# httpd -V
Server version: Apache/2.4.16 (Unix)
Server built:   Jul 31 2015 15:53:26
Server's Module Magic Number: 20120211:47
Server loaded:  APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FLOCK_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr"
 -D SUEXEC_BIN="/usr/bin/suexec"
 -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
 -D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"

# httpd -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 proxy_module (shared)
 proxy_connect_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_fcgi_module (shared)
 proxy_scgi_module (shared)
 proxy_wstunnel_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_express_module (shared)
 slotmem_shm_module (shared)
 lbmethod_byrequests_module (shared)
 lbmethod_bytraffic_module (shared)
 lbmethod_bybusyness_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 perl_module (shared)
Evocator answered 2/3, 2016 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.