2021.3.9更新

lnmp环境开启IMAP模块,如果已经安装好了lnmp,但是没有启用imap模块,其实是不需要重新编译php,直接编译安装imap模块就可以了。

1、进入lnmp源码目录(使用lnmp一键安装包,注意lnmp的版本,一般在当前用户主目录可以找到)

ubuntu@VM:~$ cd lnmp1.6/src

2、解压php源码(注意自己安装的PHP版本,解压对应的压缩包)

ubuntu@VM:~/lnmp1.6/src$ tar -xjvf php-7.3.5.tar.bz2 > /dev/null

3、编译安装IMAP模块

ubuntu@VM:~/lnmp1.6/src$ cd php-7.3.5/ext/imap
ubuntu@VM:~/lnmp1.6/src/php-7.3.5/ext/imap$ /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731

ubuntu@VM:~/lnmp1.6/src/php-7.3.5/ext/imap$ ./configure --with-php-config=/usr/local/php/bin/php-config --with-kerberos --with-imap-ssl

ubuntu@VM:~/lnmp1.6/src/php-7.3.5/ext/imap$ sudo make && sudo make install
Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/

4、修改php.ini,在最后一行加上 extension=imap.so

ubuntu@VM:~/lnmp1.6/src/php-7.3.5/ext/imap$ sudo vim /usr/local/php/etc/php.ini

5、重启php-fpm

ubuntu@VM:~/lnmp1.6/src/php-7.3.5/ext/imap$ sudo lnmp php-fpm restart
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Gracefully shutting down php-fpm . done
Starting php-fpm  done

通过phpinfo查看imap是否开启。

======================================
2019.6.11分割线

写了一个小功能,自动读取邮件,部署到服务器上发现执行报错IMAP extension must be enabled,然后才注意到lnmp一键安装包默认是不开启imap模块的。

好吧,所以如果要使用imap模块的话,需要自己把相应的php编译参数加上,我用的是lnmp1.6 php7.3.5,要修改include/php.sh文件的778行

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization ${with_curl} --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd ${with_openssl} --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --without-libzip --enable-soap --with-gettext ${with_fileinfo} --enable-opcache --with-xsl ${PHP_Modules_Options}

在编译配置参数的最后加上 --with-imap --with-imap-ssl --with-kerberos

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization ${with_curl} --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --enable-ftp --with-gd ${with_openssl} --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --without-libzip --enable-soap --with-gettext ${with_fileinfo} --enable-opcache --with-xsl ${PHP_Modules_Options} --with-imap --with-imap-ssl --with-kerberos

根据自己php版本,在对应的位置加上相应编译参数,然后再安装lnmp,就是开启imap模块的了。

当然,可能已经安装好了lnmp,但是没有启用imap模块,那就要重新编译php了,发现lnmp没有提供单独编译php的指令,自己写了一个单独编译php的小脚本,适用lnmp1.6 php7.3.5,其他版本根据需要自行修改脚本

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

cur_dir=$(pwd)
LNMP_Ver='1.6'
Stack="lnmp"
Php_Ver="php-7.3.5"

. lnmp.conf
. include/main.sh
. include/init.sh
. include/php.sh

clear
echo "+-----------------------------------------------------------------------+"
echo "|                           Re-build PHP for LNMP                       |"
echo "+-----------------------------------------------------------------------+"

Press_Install
cd ${cur_dir}/src
Download_Files ${Download_Mirror}/web/php/${Php_Ver}.tar.bz2 ${Php_Ver}.tar.bz2
Check_PHP_Option
Install_PHP_73

lnmp restart

切换到lnmp1.6一键安装包目录

把以上代码写到文件rebuild_php.sh
添加可执行权限 chmod +x rebuild_php.sh
执行脚本重新编译php sudo ./rebuild_php.sh

重新编译前,不要忘了把php启用imap的编译参数--with-imap --with-imap-ssl --with-kerberos加上。

标签: lnmp, php, imap

添加新评论