{"id":52368,"date":"2019-11-07T00:00:00","date_gmt":"2019-11-06T21:00:00","guid":{"rendered":"https:\/\/prohoster.info\/blog\/blog_prohoster\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4"},"modified":"2020-02-18T14:00:04","modified_gmt":"2020-02-18T11:00:04","slug":"kak-sdelat-podderzhku-pcre2-dlya-apache-2-4","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4","title":{"rendered":"How to enable PCRE2 support for Apache 2.4","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>I want to share my experience of translating Apache 2.4 to PCRE2, as even PHP 7 has long supported the PCRE2 library, while the open-source Apache Software Foundation still does not.<br \/>\nOf course, I might be ahead of the Apache release with PCRE2 support, as I am using the sources from the Apache Git, which suggests that PCRE2 support may be in the next release. However, for those who want PCRE2 support in Apache 2.4 right now and do not want to wait for the release, I am sharing one of the methods.<\/p>\n<p>This article assumes that you are compiling all the necessary software from source. The list of software and versions at the time of writing this article:<\/p>\n<p><b>PCRE2-10.33<br \/>\nAPR 1.7.0<br \/>\nAPR-util 1.6.1<br \/>\nApache httpd 2.4.41<\/b><\/p>\n<h3>Step one: build and compile PCRE2<\/h3>\n<p>\nWe will skip the part about downloading the sources from official sources since it is very obvious. So, you have extracted the archive, go to the directory with the PCRE2 sources, and execute the following command for UTF support:<\/p>\n<pre><code class=\"bash\">.\/configure --prefix=\/etc\/webserver\/pcre2-1033 --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode<\/code><\/pre>\n<p>\nIn the prefix, specify your path if you do not want to use the default location for installing the library:<\/p>\n<pre><code class=\"plaintext\">--prefix=\/your\/path\/to\/library<\/code><\/pre>\n<p>\nOtherwise, compile without the prefix.<\/p>\n<p>The other commands indicate enabling support for 8-bit, 16-bit, and 32-bit code blocks in PCRE. In this case, the build was performed with them.<\/p>\n<p>And, of course, we compile this using the sequential execution of the commands:<\/p>\n<pre><code class=\"bash\">make\nmake install<\/code><\/pre>\n<p>\nIf everything is fine and the compilation went without errors, we move on to the next step.<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>Step two: integrate the PCRE2 library into APR<\/h3>\n<p>\nSince Apache compiles the sources using APR, we need to connect the library in APR itself, otherwise, there may be errors about unknown functions in the Apache sources because we will be using the new PCRE2 functions.<\/p>\n<p>We will skip the part about downloading the sources from official sources since it is very obvious. So, you have extracted the archive and executed the APR configuration:<\/p>\n<pre><code class=\"bash\">.\/configure --prefix=\/etc\/webserver\/apr-170<\/code><\/pre>\n<p>\nOf course, in the prefix, specify your path if you do not want to use the standard location for installing the library, or do not specify it:<\/p>\n<pre><code class=\"plaintext\">--prefix=\/your\/path\/to\/library<\/code><\/pre>\n<p>\nAfter configuring, go to the directory: \/etc\/webserver\/srcsrv\/apr-1.7.0\/build<\/p>\n<p>Or: \/your\/path\/to\/library\/build<\/p>\n<p>Find the file apr_rules.mk in this directory and add the following line to the end of the file:<\/p>\n<pre><code class=\"cmake\">EXTRA_LIBS=-lrt -lcrypt -lpthread -ldl<\/code><\/pre>\n<p>\nLinking the library:<\/p>\n<pre><code class=\"cmake\">-lpcre2-8 -L\/your\/path\/to\/library pcre2\/lib<\/code><\/pre>\n<p>\nWe save and go to the root directory of the APR sources: \/your\/path\/to\/library.<\/p>\n<p>We compile our modified APR:<\/p>\n<pre><code class=\"bash\">make\nmake install<\/code><\/pre>\n<p>\nIf everything is fine and the compilation went without errors, we move on to the next step.<\/p>\n<h3>Step three: build APR-util from sources for Apache<\/h3>\n<p>\nYou downloaded this library from the official source, go to the root folder of the unpacked APR-util archive, and enter the following commands sequentially:<\/p>\n<pre><code class=\"bash\">.\/configure --prefix=\/etc\/webserver\/apr-util-161 --with-apr=\/your\/path\/to\/library\/apr\nmake\nmake install<\/code><\/pre>\n<p>\nOf course, in the prefix, specify your path if you do not want to use the standard location for installing the library, or do not specify it:<\/p>\n<pre><code class=\"plaintext\">--prefix=\/your\/path\/to\/library<\/code><\/pre>\n<p>\nHere we also link our APR:<\/p>\n<pre><code class=\"plaintext\">--with-apr=\/your\/path\/to\/library\/apr<\/code><\/pre>\n<p><\/p>\n<h3>Step four: download sources from the Apache git for PCRE2 support<\/h3>\n<p>\nImportant: Download the sources from the git of the latest version.<\/p>\n<p>We need to download two source files, ap_regex.h and util_pcre.c, links below:<br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/apache\/httpd\/blob\/trunk\/include\/ap_regex.h\">ap_regex.h<\/a><\/noindex><br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/apache\/httpd\/blob\/trunk\/server\/util_pcre.c\">util_pcre.c<\/a><\/noindex><\/p>\n<p>Now go to your Apache httpd source directory, and build Apache with the following commands:<\/p>\n<pre><code class=\"bash\">.\/configure --prefix=\/etc\/webserver\/apache-2441 --with-apr=\/your\/path\/to\/library\/apr --with-apr-util=\/your\/path\/to\/library\/apr-util --with-pcre=\/your\/path\/to\/library\/pcre2\/bin\/pcre2-config<\/code><\/pre>\n<p>\nOf course, in the prefix, specify your path if you do not want to use the standard location for installing the library, or do not specify it:<\/p>\n<pre><code class=\"bash\">--prefix=\/your\/path\/to\/Apache httpd<\/code><\/pre>\n<p>\nAlso, specify any additional commands for building Apache at your discretion, such as enabling or disabling modules and libraries.<\/p>\n<p>Next, go to your Apache httpd source directory, mine is:<\/p>\n<pre><code class=\"bash\">\/etc\/webserver\/srcsrv\/httpd-2.4.41<\/code><\/pre>\n<p>\nYou will naturally go to your directory, replace in the directory:<\/p>\n<pre><code class=\"bash\">\/etc\/webserver\/srcsrv\/httpd-2.4.41\/include<\/code><\/pre>\n<p>\nThe file ap_regex.h with the one we downloaded from the Apache git.<\/p>\n<p>We also go to the directory:<\/p>\n<pre><code class=\"bash\">\/etc\/webserver\/srcsrv\/httpd-2.4.41\/server<\/code><\/pre>\n<p>\nReplace the file util_pcre.c with the one we downloaded from the Apache git.<\/p>\n<p>Now we need to add the PCRE2 connection in Apache itself, we need to find the file ap_config_auto.h, it is located in the directory:<\/p>\n<pre><code class=\"bash\">\/etc\/webserver\/srcsrv\/httpd-2.4.41\/include<\/code><\/pre>\n<p>\nAt the very beginning of this file, insert the following lines:<\/p>\n<pre><code class=\"cpp\">\/* Load PCRE2 *\/\n#define HAVE_PCRE2 1<\/code><\/pre>\n<p>\nWell, now we are ready for the actual moment of compiling Apache httpd with PCRE2 support.<br \/>\nGo to your Apache httpd source directory and compile it by sequentially executing the commands:<\/p>\n<pre><code class=\"bash\">make\nmake install<\/code><\/pre>\n<p>\nNow, if everything went well and without errors, you will have a built and compiled Apache httpd with PCRE2 support, which means positive changes in the Apache modules using PCRE regular expressions, one of which is the Module rewrite.<\/p>\n<p>In conclusion, this method allows using PCRE2 before the official release from the Apache Software Foundation; I hope a version with PCRE2 support will be released soon.<\/p>\n<p>Also, during the testing of standard .htaccess, no errors occurred; if anyone has errors, please write in the comments.<\/p>\n<h3>P.S.<\/h3>\n<p>\nI was a bit stressed about using two different versions of PCRE in my stack, and I decided to resolve this.<br \/>\n<br \/>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/474556\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 Apache 2.4 \u043d\u0430 PCRE2, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u0436\u0435 PHP 7 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 PCRE2, \u0430 open source Apache Software Foundation \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u044e \u0440\u0435\u043b\u0438\u0437 Apache \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 PCRE2, \u0442\u0430\u043a \u043a\u0430\u043a \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0441 \u0433\u0438\u0442\u0430 Apache, \u0447\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043d\u0430\u043c \u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 PCRE2 \u0443\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-52368","post","type-post","status-publish","format-standard","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 Apache 2.4 \u043d\u0430 PCRE2, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u0436\u0435 PHP 7 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 PCRE2, \u0430 open source Apache Software Foundation \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u044e \u0440\u0435\u043b\u0438\u0437.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 PCRE2 \u0434\u043b\u044f Apache 2.4 | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 Apache 2.4 \u043d\u0430 PCRE2, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u0436\u0435 PHP 7 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 PCRE2, \u0430 open source Apache Software Foundation \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u044e \u0440\u0435\u043b\u0438\u0437.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-11-06T21:00:00+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-02-18T11:00:04+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47How to Add PCRE2 Support for Apache 2.4 | ProHoster","description":"I want to share my experience of migrating Apache 2.4 to PCRE2, as even PHP 7 has long supported the PCRE2 library, while the open-source Apache Software Foundation has not. I may be getting ahead of the release.","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 PCRE2 \u0434\u043b\u044f Apache 2.4 | ProHoster","og:description":"\u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u0441\u0432\u043e\u0438\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 Apache 2.4 \u043d\u0430 PCRE2, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u0436\u0435 PHP 7 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 PCRE2, \u0430 open source Apache Software Foundation \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u0432\u0435\u0440\u043d\u043e \u043e\u043f\u0435\u0440\u0435\u0436\u0430\u044e \u0440\u0435\u043b\u0438\u0437.","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/kak-sdelat-podderzhku-pcre2-dlya-apache-2-4","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-11-06T21:00:00+00:00","article:modified_time":"2020-02-18T11:00:04+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"52368","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-24 03:23:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 20:44:44","updated":"2026-01-24 03:23:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/52368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=52368"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/52368\/revisions"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=52368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=52368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=52368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}