Tuesday, July 10, 2018

macOS: install Apache2::Request mod_perl module

Sources:
Trying to install Apache2::Request on macOS from CPAN will cause multiple errors.
cpan Apache2::Request
First, we will need apxs (Apache Extension tool).
For this, install httpd from homebrew.
brew install httpd
Then, we will need Xcode.
So, install it from the Apple Store.

Then, Apache2::Request install will try to have access to multiple Xcode directories that do not exist.
So, create symbolic links and missing directory.
sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/ /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain

sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain/usr/local/bin/

sudo ln -s /usr/local/bin/apxs /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.13.xctoolchain/usr/local/bin/apsx

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk
Then install libapreq2 library.
  1. Download libapreq2-2.13
  2. Compile libapreq2 sources.
tar xvfz libapreq2-2.13.tar.gz
cd libapreq2-2.13
./configure
make
make install
Then install mod_perl 2.

svn checkout https://svn.apache.org/repos/asf/perl/modperl/trunk/ mod_perl-2.0
cd mod_perl-2.0
perl Makefile.PL MP_CCOPTS=-std=gnu89
make
make install
NB: mod_perl.so and mod_apreq2.so will be installed in /usr/local/lib/httpd/modules.

Then update Apache configuration.
vi /usr/local/etc/httpd/httpd.conf
LoadModule perl_module lib/httpd/modules/mod_perl.so
LoadModule apreq_module lib/httpd/modules/mod_apreq2.so
...
ServerName jeroboam:8080
...
PerlSwitches -I /Users/jerome/perl5/lib/perl5
PerlModule Apache::DBI
PerlModule ModPerl::Registry
PerlRequire /Users/jerome/src/connectmv/perl/lib/startup.pl
<Location /hlr_vas/>
    SetHandler perl-script
    PerlResponseHandler MBQT::mod_perl::HlrVas
</Location>

# PerlSetEnv DBG_FLG 1
Apache restart
/usr/local/bin/apachectl restart