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

二次信任 提交于 2019-11-30 12:15:52
Dan Deal

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

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
Andrew Swift

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

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)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!