ubuntu 14.04
用nginx跑php時找不到json_encode()函數報錯:
Call to undefined function json_encode ...
但使用apache2跑則正常
檢查:
# dpkg --get-selections | grep php5-json
有安裝php5-json
# apt-get install php5-json
Reading package lists... Done
Building dependency tree
Reading state information... Done
php5-json is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
已安裝,所以沒新東西被裝
但是
# php5-fpm -m | grep json
(無結果)
root@ubuntu:/etc/php5/fpm/conf.d# ls -l
total 0
lrwxrwxrwx 1 root root 32 Jul 3 11:11 05-opcache.ini -> ../../mods-available/opcache.ini
lrwxrwxrwx 1 root root 28 Jul 3 11:11 10-pdo.ini -> ../../mods-available/pdo.ini
lrwxrwxrwx 1 root root 29 Jul 3 11:11 20-curl.ini -> ../../mods-available/curl.ini
lrwxrwxrwx 1 root root 27 Jul 3 11:11 20-gd.ini -> ../../mods-available/gd.ini
lrwxrwxrwx 1 root root 31 Jul 3 11:11 20-mcrypt.ini -> ../../mods-available/mcrypt.ini
lrwxrwxrwx 1 root root 31 Jul 3 11:11 20-mysqli.ini -> ../../mods-available/mysqli.ini
lrwxrwxrwx 1 root root 30 Jul 3 11:11 20-mysql.ini -> ../../mods-available/mysql.ini
lrwxrwxrwx 1 root root 34 Jul 3 11:11 20-pdo_mysql.ini -> ../../mods-available/pdo_mysql.ini
lrwxrwxrwx 1 root root 33 Jul 3 11:11 20-readline.ini -> ../../mods-available/readline.ini
原來json.ini不在php5-fpm的設定裡面
把php5-fpm的conf.d備份,然後重建
root@ubuntu:/etc/php5/fpm# mv conf.d/ conf-old.d
root@ubuntu:/etc/php5/fpm# ln -s /etc/php5/mods-available /etc/php5/fpm/conf.d
然後重啟
# service php5-fpm restart // 注意:重啟nginx是無效的,要重啟動php5-fpm
檢查:
# php5-fpm -m | grep json
json
最後打開網頁,json_encode()可以正常使用
沒有留言:
張貼留言