lnmp 下 php 安装 ldap 扩展

lnmp 下 php 安装 ldap 扩展

  • 使用一键 lnmp 安装的 web 环境缺少 LDAP 模块,需要手动编译安装该模块

1.查看PHP编译参数

1.1.phpinfo() 函数

  • 浏览器访问 phpinfo() 函数,提供参数时可查看特定配置

1.2.php -i 查看 PHP 配置信息

  • Linux 下执行
php -i|grep configure

--------------------------
root@Uzuiyouijie:~# php -i|grep configure
Configure Command =>  './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=/usr/local/freetype' '--with-jpeg' '--with-png' '--with-zlib' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--enable-intl' '--enable-ftp' '--enable-gd' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--with-zip' '--without-libzip' '--enable-soap' '--with-gettext' '--enable-opcache' '--with-xsl' '--with-pear'

1.3.php -m 查看 PHP 开启的扩展模块

  • Linux、Windows中都可以用
php -m

1.4.php --ini 查看加载的配置文件信息

php --ini

2.安装 PHP 扩展模块

  • LNMP 安装完成会清理源码包所以需要重新解压编译 PHP 模块

2.1.编译安装 ldap 模块

cd /opt/tools/lnmp1.8-full/src
tar -xf php-7.4.19.tar.bz2
cd php-7.4.19/ext/ldap

/usr/local/php/bin/phpize
----------------------
root@zuiyoujie:/opt/tools/lnmp1.8-full/src/php-7.4.19/ext/ldap# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
----------------------

# 编译 ldap 模块
./configure --with-php-config=/usr/local/php/bin/php-config  --with-ldap

# 出现以下信息表示编译成功
------------------
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
------------------

# 安装编译的模块
make && make install

# 检查 ldap 模块是否安装成功
ll /usr/local/php/lib/php/extensions/

2.2.修改 PHP 配置并重启服务

  • 增加 ldap 模块配置
# 查看 PHP 配置信息
root@zuiyoujie:/opt/tools/lnmp1.8-full/src/php-7.4.19/ext/ldap# php --ini 
Configuration File (php.ini) Path: /usr/local/php/etc
Loaded Configuration File:         /usr/local/php/etc/php.ini
Scan for additional .ini files in: /usr/local/php/conf.d
Additional .ini files parsed:      (none)

vim /usr/local/php/etc/php.ini
-----------------
extension=ldap
-----------------
  • 重启 PHP 服务,使 ldap 模块生效
service php-fpm restart

# 或者
/etc/init.d/php-fpm restart

3.报错处理

3.1.编译报错处理: configure error: Cannot find header file 'ldap.h'

# ubuntu18 安装 ldap 相关文件,生成 ldap.h
apt-cache search ldap | grep ldap
apt-get install libldap2-dev

# 查找 ldap.h 文件
whereis ldap
ls -lh /usr/include/ldap*
root@zuiyoujie:/opt/tools/lnmp1.8-full/src/php-7.4.19/ext/ldap# ls -lh /usr/include/ldap*
-rw-r--r-- 1 root root 9.3K Feb 18 22:22 /usr/include/ldap_cdefs.h
-rw-r--r-- 1 root root 1.8K Feb 18 22:22 /usr/include/ldap_features.h
-rw-r--r-- 1 root root  64K Feb 18 22:22 /usr/include/ldap.h
-rw-r--r-- 1 root root 9.3K Feb 18 22:22 /usr/include/ldap_schema.h
-rw-r--r-- 1 root root 3.4K Feb 18 22:22 /usr/include/ldap_utf8.h

# 重新编译安装-需要指定 ldap 相关文件位置
./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap=/usr/include
make && make install

# 检查 PHP 模块安装结果
ls -lh /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
------------------------
root@zuiyoujie:/opt/tools/lnmp1.8-full/src/php-7.4.19/ext/ldap# ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
total 9260
drwxr-xr-x 2 root root    4096 Jun  1 21:23 ./
drwxr-xr-x 3 root root    4096 Jun  1 21:08 ../
-rwxr-xr-x 1 root root  298272 Jun  1 21:23 ldap.so*
-rwxr-xr-x 1 root root 6267766 Jun  1 21:08 opcache.a*
-rwxr-xr-x 1 root root 2902072 Jun  1 21:08 opcache.so*

# 修改 PHP 配置文件 重启 PHP 服务

10.参考地址

https://blog.csdn.net/caiyiii/article/details/19047187
https://www.itbiancheng.com/article/5138.html
https://my.oschina.net/nYtgEmMGe/blog/496859
posted @ 2021-06-02 14:40  天生帅才  阅读(480)  评论(0编辑  收藏  举报
// 百度统计