How to make PCRE2 support for Apache 2.4

I want to share my experience translating Apache 2.4 to PCRE2, since even PHP 7 has long supported the PCRE2 library, and the open source Apache Software Foundation is still not there.

Of course, I’m probably ahead of the release of Apache with PCRE2 support now, since I use the sources from the Apache geo, which tells us about PCRE2 support is already possible in the next release, but for those who already want PCRE2 support in Apache 2.4, and who don’t want to wait release sharing one of the ways.



The article assumes that you collect all the necessary software from the source, a list of software and versions at the time of writing:



PCRE2-10.33

APR 1.7.0

APR-util 1.6.1

Apache httpd 2.4.41



Step One: Build and Compile PCRE2



We’ll omit the moment of downloading the source from the sources since it’s too obvious, so you unpacked the archive, go to the source folder PCRE2, and execute the following command to support UTF:



./configure --prefix=/etc/webserver/pcre2-1033 --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode
      
      





In the prefix, specify your path if you do not want to use the standard location for installing the library:



 --prefix=/// 
      
      





Otherwise, collect without a prefix.



The remaining commands indicate the inclusion of supporting 8-bit, 16-bit and 32-bit code blocks PCRE, in this embodiment, the assembly was performed with them.



And of course, we compile this case using sequential execution of commands:



 make make install
      
      





If all the rules and compilation went smoothly, go to the next step.



Step two: connect the PCRE2 library to the APR



Since Apache compiles the sources using the APR, we need to connect the library in the APR itself, otherwise there may be errors about unknown functions in the Apache sources, because we will use the new PCRE2 functions.



We’ll omit the moment of downloading the source from the sources as it’s too obvious, so you unpacked the archive and configured the APR:



 ./configure --prefix=/etc/webserver/apr-170
      
      





Naturally, indicate your path in the prefix if you do not want to use the standard location for installing the library, or do not specify:



 --prefix=/// 
      
      





After completing the configuration, go to the directory: /etc/webserver/srcsrv/apr-1.7.0/build



Well, or: / your / path / to the library / build



Find the apr_rules.mk file in this directory, and add at the end of the line where:



 EXTRA_LIBS=-lrt -lcrypt -lpthread -ldl
      
      





Library connection:



 -lpcre2-8 -L///  pcre2/lib
      
      





Save, go to the root directory of the APR sources: / your / path / to the library.



Compile our modified APR:



 make make install
      
      





If all the rules and compilation went smoothly, go to the next step.



Step Three: Build APR-util for Apache from Source



You downloaded this library from the source’s office, go to the root folder of the unpacked archive with APR-util, and enter the following commands sequentially:



 ./configure --prefix=/etc/webserver/apr-util-161 --with-apr=///  apr make make install
      
      





Naturally, indicate your path in the prefix if you do not want to use the standard location for installing the library, or do not specify:



 --prefix=/// 
      
      





Also here we connect our APR:



 --with-apr=///  apr
      
      





Step Four: Download Sources from Apache Git to Support PCRE2



Important: Download the source from the latest version of the gita.



We need to download two sources such as ap_regex.h and util_pcre.c, the links below:

ap_regex.h

util_pcre.c



Now go to your Apache httpd source directory, and build Apache with the following commands:



 ./configure --prefix=/etc/webserver/apache-2441 --with-apr=///  apr --with-apr-util=///  apr-util --with-pcre=///  pcre2/bin/pcre2-config
      
      





Naturally, indicate your path in the prefix if you do not want to use the standard location for installing the library, or do not specify:



 --prefix=/// Apache httpd
      
      





Also, specify additional commands for building Apache at your discretion, I mean the commands to enable disabling modules and libraries.



Next, go to your Apache httpd source directory, I have this:



 /etc/webserver/srcsrv/httpd-2.4.41
      
      





You naturally go to your directory, replace in the directory:



 /etc/webserver/srcsrv/httpd-2.4.41/include
      
      





The file ap_regex.h, which we downloaded from the Apache git.



Also go to the directory:



 /etc/webserver/srcsrv/httpd-2.4.41/server
      
      





Replace the util_pcre.c file with the Apache we downloaded from



Now it remains to add the PCRE2 connection in Apache itself, you need to find the ap_config_auto.h file, it is located in the directory:



 /etc/webserver/srcsrv/httpd-2.4.41/include
      
      





At the very beginning of this file, insert the following lines:



 /* Load PCRE2 */ #define HAVE_PCRE2 1
      
      





Well, now we are ready for the true moment of compiling Apache httpd with PCRE2 support.

We go to our Apache httpd source directory, compile this case using sequential execution of commands:



 make make install
      
      





Now, if everything went well and without errors, then you will have assembled and compiled Apache httpd with PCRE2 support, which means positive changes in Apache modules using PCRE regular expressions, one of which is Module rewrite.



In conclusion, this method makes it possible to use PCRE2 before the release from the Apache Software Foundation, I hope that a version with PCRE2 support will be released soon.



Also during testing of standard .htaccess, there were no errors, if anyone has errors write in the comments.



PS



I was a little bothered by the situation of using two different versions of PCRE for my stack, and I decided to fix it.



All Articles