preg_replace compilation failed (Amazon EC2, WordPress)
We have an Amazon EC2 AMI (Linux) hosting the latest WordPress installation (3.4.1) at this point in time. All the configuration was running fine till an upgrade that introduced a PHP warning:
« Warning: preg_replace(): Compilation failed: unknown option bit(s) set at offset 0 »
The first time I noticed it, I didn’t pay that much attention since the WordPress administration was still working besides the warning but some other functionality like the shortcodes was not.
The problem arose when we needed the GD library to generate png and jpg images on the fly which, is used in a WordPress theme. By doing a simple install of the library (php-gd.x86_64, for our system) several dependencies were upgraded to newer versions (php, php-cli, php-common, php-mysql, php-pdo). The install finished normally without any warnings to be worried about.
After a while digging in Google, I found this post which was having a similar problem and most importantly it hinted that the problem was the PCRE library (libpcre), which was being loaded differently (different versions) in the apache and commandline modes. Running the php code below in command line and a web page would show that:
The same post mentioned that a libpcre upgrade would fix the problem. Thus, I went for the upgrade from version 7.8-3.1.8 to version 8.21-5.3 in our Amazon Linux instance running the following commands:
sudo yum search libpcre # Find the library sudo yum install pcre.x86_64 # Install the right library.
If you’re running a different linux system other than the Amazon Linux AMI or CentOS you might refer to your docs. For example in Ubuntu the package manager is apt-get.
This should never have happened if the dependencies were checked correctly during the GD library install. Maybe the libpcre version was not considered as needing an upgrade. Anyhow, I hope this helps others to save some time fixing this problem.
If you have any comments or further information on this issue, I’d appreciate if you let me know.
I heard a couple of guys talking about this in the New York subway so I looked it up online and found your page. Thanks. I thought I was right and you confirmed my thoughts. Thanks for the work you’ve put into this. I’d love to save this and share with my friends.
Happy to hear from somebody that found it useful.
Very nice article and straight to the point. I am not sure if this is actually the best place to ask but do you people have any thoughts on where to hire some professional writers? Thx 🙂
Thanks! It depends the domain of expertise, you can find some decent writers in most freelancing sites.
I absolutely love your blog and find a lot of your post’s to be precisely what I’m looking for. Would you offer guest writers to write content for yourself? I wouldn’t mind composing a post or elaborating on a lot of the subjects you write regarding here. Again, awesome blog!
Thanks! We’d love to have guest writers so you can give us a ping to info[at]syscrunch.com for further discussion!
I had the same problem and VERY much trouble finding out what was causing it.. thank you so much for this blog post it saved my day! 🙂