Installing PHP Mailparse

From Cerb Wiki
Jump to: navigation, search

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

On Unix-based Servers

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

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]

For RHEL 5

RHEL 5 Only supports 5.1.6 you will need to upgrade your php to 5.2+. The older instructions are no longer valid as of 4.3.0.

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

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

RHEL6/CentOS6

Installing mailparse on RHEL6 based distributions is easy if you enable the EPEL repository.

su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm'
su -c 'yum install php-pecl-mailparse'

From source code

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

Contributed by: BlueC (Cerb4 Forums)

Ubuntu (Debian) LAMP-based install

Installing Mailparse under debian / ubunutu

Contributed by: alamb (Cerb4 Forums)

You will need to install the following packages

 sudo apt-get install php5-gd php5-imap php-pear php5-dev make php5-mcrypt

Now you can install mailparse

 sudo pecl install mailparse

Next edit your php.ini file and add mailparse.so

 sudo nano /etc/php5/apache2/conf.d/mailparse.ini

or

 sudo nano /etc/php5/conf.d/mailparse.ini

This will create a new file. Add the line

 extension=mailparse.so

Mac OS X (XAMPP)

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

On Windows-based Servers (XAMPP)

If you're using XAMPP, or a similar distribution, you probably already have the mailparse extension available. Note that XAMPP 1.71 is the latest version to ship with mailparse.

If you do not have php_mailparse.dll, you can download it from:

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

On Windows-based Servers (IIS)

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

(Contributed by TravisT)

Additional Notes

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

CentOS issues

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

Contributed by: brwatters

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

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

External Links