在學習安裝zabbix的時候,前提需要搭建使用到LNMP框架,而在編譯php時忘記添加bcmath與sockets
擴展包,發現當初安裝時沒有--enable-bcmath、--enable-sockets,自己又不想刪除重裝php,幸好php支
持單獨添加某個extension,重要的就是要生成這個擴展對應的.so文件。
具體做法如下,要有與你已安裝的php相同版本的php源代碼安裝包。我用的是php-7.0.5.tar.gz。
[root@server ~]# tar -zxf php-7.0.5.tar.gz
[root@server ~]# cd php-7.0.5
[root@server php-7.0.5]# cd ext/
[root@server ext]# cd bcmath/
[root@server bcmath]# /usr/local/php7/bin/phpize
[root@server bcmath]# ./configure --with-php-config=/usr/local/php7/bin/php-config --enable-bcmath
[root@server bcmath]# make
[root@server bcmath]# make test
[root@server bcmath]# make install
[root@server bcmath]# cd /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012
[root@server no-debug-non-zts-20151012]# ls
bcmath.so opcache.a opcache.so
模塊編譯好了,現在添加進php
[root@server no-debug-non-zts-20151012]# cd /usr/local/php7/etc/
[root@server etc]# vi php.ini
在最後面增加兩行
extension_dir=/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/
extension=mbstring.so
重啓php及nginx,測試模塊加上了。
遇到的問題:
在編譯bcmath時要加上 --with-php-config=/usr/local/webserver/php/bin/php-config 不然會出現下面錯誤
configure: error: Cannot find php-config. Please use --with-php-config=PATH
[root@server bcmath]# ./configure --with-php-config=/usr/local/webserver/php/bin/php-config 正常。
同樣的方法進行sockets庫模塊的動態添加。
php服務源碼安裝包中沒有的ext目錄下面,如果沒有找到所需的加載模塊(例如yaf、ffmpeg),需要自己下載其源碼安裝包,解壓後的操作與上面的步驟一樣。
這個問題是在我做zabbix實驗的時候遇到的,在php動態加載模塊這方面又加深了一次。