I want to share my experience of migrating Apache 2.4 to PCRE2, since even PHP 7 has long supported the PCRE2 library, and the open source Apache Software Foundation still does not.
Of course, I'm probably ahead of the Apache release with PCRE2 support right now, since I'm using the Apache git sources, which tells us 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 I share one of the ways.
The article assumes that you collect all the necessary software from the sources, the list of software and versions at the time of writing the article:
PCRE2-10.33
April 1.7.0
APR-util 1.6.1
Apache httpd 2.4.41
Step One: Building and Compiling PCRE2
Let's omit the moment of downloading sources from official sources, since it's too obvious, so you unpacked the archive, go to the PCRE2 sources folder, 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
Specify your path in the prefix if you do not want to use the standard location for installing the library:
--prefix=/Π²Π°Ρ/ΠΏΡΡΡ/Π΄ΠΎ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ
Otherwise, you collect without a prefix.
The remaining commands indicate the inclusion of supporting 8-bit, 16-bit and 32-bit PCRE code blocks, in this embodiment, the assembly was performed with them.
And of course, we compile this case using the sequential execution of commands:
make
make install
If everything is fine and the compilation went without errors, go to the next step.
Step Two: Include the PCRE2 Library in APR
Since Apache compiles sources using APR, we need to include the library in the APR itself, otherwise errors about unknown functions in the Apache sources are possible, because we will use the new PCRE2 functions.
Let's omit the moment of downloading sources from official sources, since this is too obvious, so you unpacked the archive and completed the APR configuration:
./configure --prefix=/etc/webserver/apr-170
Naturally, specify 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 file apr_rules.mk in this directory, and add to the end of the line where:
EXTRA_LIBS=-lrt -lcrypt -lpthread -ldl
Library connection:
-lpcre2-8 -L/Π²Π°Ρ/ΠΏΡΡΡ/Π΄ΠΎ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ pcre2/lib
We save and go to the root directory of the APR sources: /your/path/to the library.
Compiling our modified APR:
make
make install
If everything is fine and the compilation went without errors, go to the next step.
Step three: building APR-util for Apache from source
You downloaded this library from the source, go to the root folder of the unpacked archive with APR-util, and enter the following commands in sequence:
./configure --prefix=/etc/webserver/apr-util-161 --with-apr=/Π²Π°Ρ/ΠΏΡΡΡ/Π΄ΠΎ Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊΠΈ apr
make
make install
Naturally, specify 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 the Apache Git Sources for PCRE2 Support
Important: We download the sources from the latest version of the git.
We need to download two sources such as ap_regex.h and util_pcre.c, links below:
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, specify 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
You also specify additional commands for building Apache at your discretion, I mean the commands for enabling modules and libraries.
Next, go to your Apache httpd source directory, I have this:
/etc/webserver/srcsrv/httpd-2.4.41
You naturally change to your directory, replace in the directory:
/etc/webserver/srcsrv/httpd-2.4.41/include
The ap_regex.h file, downloaded by us from the Apache git.
We also go to the directory:
/etc/webserver/srcsrv/httpd-2.4.41/server
We replace the util_pcre.c file with the one we downloaded from the Apache git
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
Insert the following lines at the very beginning of this file:
/* Load PCRE2 */
#define HAVE_PCRE2 1
Well, now we are ready for the real point of compiling Apache httpd with PCRE2 support.
We go to our Apache httpd source directory, compile this case using the sequential execution of commands:
make
make install
Now, if everything went well and without errors, then you will have compiled and compiled Apache httpd with PCRE2 support, which means positive changes in Apache modules using PCRE regular expressions, one of these 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 the testing of standard .htaccess, there were no errors, if anyone has errors, write in the comments.
PS
The situation of using two different versions of PCRE for my stack bothered me a little, and I decided to fix it.
Source: habr.com