Installing PHP Mailparse

From Cerberus Helpdesk Wiki

Jump to: navigation, search

If your PHP5 environment doesn't already have the 'mailparse' extension installed then you'll need to add it

Contents

[edit] On Unix-based Servers

[edit] Using PECL

Generally, installation can be accomplished with a simple command at the server console:

pecl install mailparse

This should retrieve, compile and install the extension. You'll usually need to enable the mailparse extension in your php.ini file by hand. This is accomplished in various ways for different OS/distributions.

In most cases you can simply add the following line to your php.ini:

extension=mailparse.so

[edit] FreeBSD Issue

You may need to edit the pecl script (usually /usr/local/bin/pecl) and remove the ā€˜-n’ from the command line arguments.[1]

[edit] For RHEL 5

wget http://dag.wieers.com/rpm/packages/php-pecl-mailparse/php-pecl-mailparse-2.1.1-1.el5.rf.i386.rpm
rpm -i php-pecl-mailparse-2.1.1-1.el5.rf.i386.rpm
service httpd reload

If your installed version of PHP does not match the system installed version, then these steps can fail with the following error in your PHP log:

PHP Warning:  PHP Startup: mailparse: Unable to initialize module
Module compiled with module API=[date1], debug=0, thread-safety=0
PHP    compiled with module API=[date2, debug=0, thread-safety=0
These options need to match
in Unknown on line 0

To fix this you will need to first remove the RPM version of MailParse then compile MailParse automatically with pecl. Since mbstring is likely installed as an RPM, rather than through pecl, it won't recognize it as being already installed. As a result of this you must use the '-n' (no dependencies) flag when installing with pecl.

rpm -e php-pecl-mailparse
pecl install -n mailparse

If you are using SeLinux to protect your system, you will need to change selinux security context of the mailparse.so. PHP will be able to load the extension, but SeLinux will prevent php from using it.

to check the security context: getfattr -n security.selinux /path/to/your/mailparse.so
if you don't get something like this security.selinux="system_u:object_r:textrel_shlib_t:s0\000", your must change it.
to change the security context: sudo setfattr -n security.selinux -v "system_u:object_r:textrel_shlib_t:s0\000" /path/to/your/mailparse.so

[edit] From source code

http://www.cerb4.com/forums/showthread.php?t=40

Contributed by: BlueC (Cerb4 Forums)

[edit] Ubuntu (Debian) LAMP-based install

http://www.cerb4.com/forums/showthread.php?t=244

Contributed by: alamb (Cerb4 Forums)

[edit] Mac OS X (XAMPP)

sudo /Applications/XAMPP/xamppfiles/bin/pear install pecl/mailparse

[edit] On Windows-based Servers (XAMPP)

If you're using XAMPP, or a similar distribution, you probably already have the mailparse extension available.

If you do not have php_mailparse.dll, you can download it from: http://downloads.php.net/pierre/

;extension=php_mailparse.dll
  • Save your php.ini file
  • Restart Apache

[edit] On Windows-based Servers (IIS)

http://www.cerb4.com/forums/showthread.php?t=154

(Contributed by TravisT)

[edit] Additional Notes

[edit] mbstring before mailparse

Also don't forget to load the mbstring extension before you load mailparse.

For example, in the php.ini place in this order:

extension=php_mbstring.dll
extension=php_mailparse.dll

Or you will get an error.

Contributed by: Mustafa

[edit] CentOS issues

http://www.cerb4.com/forums/showthread.php?t=25&highlight=centos

Contributed by: brwatters

[edit] Configure Error

If you get the "checking whether the C compiler works... configure: error: cannot run C compiled programs." error, check the mount permissions on your /tmp directory. You may need to remount /tmp as executable.

# mount | grep /tmp
/dev/sda3 on /tmp type ext3 (rw)
/tmp on /var/tmp type none (rw,noexec,nosuid,bind)

# mount -o remount,exec,suid /tmp

do your compiling, then

# mount -o remount,noexec,nosuid /tmp

Contributed by Alex in Community Town Hall

[edit] mailpars2em

If you cannot install the Mailparse extension, a member on the forums has written PHP emulation called "mailpars2em" which uses the freely available PEAR package "Mail/mimeDecode" instead of Mailparse. No compilation is required, but since it is not compiled C code, it runs more slowly than Mailparse. You can download mailpars2em, under an "experimental, use at your own risk" agreement. For more information, see this forum thread.

Contributed by Kitchin in Forums

[edit] External Links

Personal tools