This turned out to have quite a few tricky bits to it. Here’s how you can get it up-and-running on a CentOS/RHEL box.
First, install the php-devel package as you’ll need the headers and phpize tool.
# yum install php-devel php-mbstring
Second, install the mailparse extension.
# pecl install mailparse pecl/mailparse requires PHP extension "mbstring" No valid packages found install failed
Oops, that turned out not to work, even though mbstring was configured and working.
# php -i | grep mbstring mbstring mbstring extension makes use of "streamable kanji pre filter and converter", which is distributed under the GNU Lesser General Public License version 2.1. mbstring.detect_order => no value => no value mbstring.encoding_translation => Off => Off mbstring.func_overload => 0 => 0 ...
You can use the workaround via PEAR:
# pear install pecl/mailparse
If you’re getting safe_mode warnings like the following:
# pear install pecl/mailparse WARNING: running in safe mode requires that all files created be the same uid as the current script. PHP reports this script is uid: 0, and current user is: root downloading mailparse-2.1.5.tgz ... Starting to download mailparse-2.1.5.tgz (37,332 bytes) ..........done: 37,332 bytes 9 source files, building Warning: putenv(): Safe Mode warning: Cannot set environment variable 'PATH' - it's not in the allowed list in PEAR/Builder.php on line 297 PHP Warning: putenv(): Safe Mode warning: Cannot set environment variable 'PATH' - it's not in the allowed list in /usr/share/pear/PEAR/Builder.php on line 297 running: phpize sh: /phpize: No such file or directory ERROR: `phpize' failed
Disable PHP’s safe_mode in the php.ini temporarily, as PEAR will call several PHP scripts with get their settings from the general PHP.INI file. After disabling it there, the “pear install pecl/mailparse” should work.
So, you add the extension in the php-configuration (either in php.ini or in another configuration file that is included there).
extension=mailparse.so
And if you’re still struggling with the following message:
# php -i | grep mailparse PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mailparse.so' - /usr/lib64/php/modules/mailparse.so: undefined symbol: mbfl_name2no_encoding in Unknown on line 0 /etc/php.d/mailparse.ini,
It’s because you are loading the “mailparse.so” module before the mbstring module. Change the order in your php.ini file or in the /etc/php.d ini-files. Those are loaded alphabetically, meaning “mailparse.so” will be loaded before “mbstring”. If that doesn’t work, make sure the mbstring module is loaded correctly by using “php -i | grep mbstring”.
If you’ve done it all correctly, that should give you better results now.
# php -i| grep mailparse /etc/php.d/z-mailparse.ini, mailparse mailparse support => enabled mailparse.def_charset => us-ascii => us-ascii
Hooray for PECL vs PEAR troubles and alphabetically loading linked modules in the wrong order!