Install Mailparse extension (or others) Tutorial

Hello guys.
The other days, i needed to install and enable mailparse pecl extension, as it is a required extension for Blesta billing software.
After some tries and help from cyberpanel support people… i have it installed and running :

This is the “how to do” :

1 - i want to install it under PHP 7.0X

2 - step by step from console as root:

yum install re2c

yum install lsphp70-devel make gcc glibc-devel zlib-devel

/usr/local/lsws/lsphp70/bin/pecl install mailparse

chmod 755 /usr/local/lsws/lsphp70/lib64/php/modules/*

3 - IMPORTANT : we need to create a “mailparse.ini” to load as module in php, but the “mbstring” extension must to be loaded BEFORE the “mailparse” extension.
In /usr/local/lsws/lsphp70/etc/php.d/ you can see all the extensions to be loaded by php, normally with a number like 00- or 20- etc. That number indicates the PRIORITY of loading.
In my case the mbstring is :
/usr/local/lsws/lsphp70/etc/php.d/20-mbstring.ini
SO, to create the mailparse ini there, i need to create it with 30- (to load it AFTER mbstring), THEN…

echo “extension=mailparse.so” > /usr/local/lsws/lsphp70/etc/php.d/30-mailparse.ini

and finally :

systemctl restart lsws

DONE!
You have the mailparse extension installed under php70X and runnning perfect

You can do this almost with all the extension you need. Always investigate about conflicts, and the correct loading priority dependencies (this was my BIG mistake and it takes too long to working propely just for it)

I hope it helps :slight_smile:
Regards
Fabian

nice !

hi, while following up this, i get:

Build process completed successfully
Installing ‘/usr/local/lsws/lsphp70/lib64/php/modules/mailparse.so’
install ok: channel://pecl.php.net/mailparse-3.0.3
configuration option “php_ini” is not set to php.ini location
You should add “extension=mailparse.so” to php.ini

do i need to do something else to install it? or it’s already installed?

Thank you man, you saved my day! works perfectly

For reference, I also have some cool oneliners to help automate that process if installing for multiple LSPHP versions for admins and power users who may come across this and is using multiple versions and want to automate the task.

Something like this would work nicely as a oneliner to batch install a pecl module for all versions.

Can adjust the lsphp to have this just installed for LSPHP 7.x versions “lsphp7*-devel”
yum install -y re2c lsphp7*-devel make gcc glibc-devel zlib-devel;

or just have it go for all versions removing the 7
yum install -y re2c lsphp*-devel make gcc glibc-devel zlib-devel;

This command would work to install the module for all detected LSPHP versions specified and also do you the courtesy of adding it to the end of all listed modules via “zzzzzzz-pecl.ini” so that step is not forgotten and you dont have to check and guess which order each version is in.

Extension=“mailparse”;for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl install ${Extension} && echo “extension=${Extension}.so” >> /usr/local/lsws/${version}/etc/php.d/zzzzzzz-pecl.ini; done

Then granted no errors during install you could restart the services.
systemctl restart lsws||service lsws restart;

You can then check for it via this command
Extension=“mailparse”;for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed ‘s/lsphp//g’) ; do echo “”; echo “LSPHP $phpver” ; /usr/local/lsws/lsphp$phpver/bin/php -m | grep -E “${Extension}”; done

Putting that all together it would look like this.
yum install -y re2c lsphp7*-devel make gcc glibc-devel zlib-devel; Extension=“mailparse”;for version in $(ls /usr/local/lsws|grep lsphp); do /usr/local/lsws/${version}/bin/pecl install ${Extension} && echo “extension=${Extension}.so” >> /usr/local/lsws/${version}/etc/php.d/zzzzzzz-pecl.ini; done; systemctl restart lsws||service lsws restart; systemctl status lsws||service lsws status;

Obviously, if you are not sure what your doing the above is probably not something I would recommend. Doing stuff one at a time may be in your best interests in that case.