鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ linux中如何通過php.ini添加擴展?

linux中如何通過php.ini添加擴展?

在編譯安裝的時候,我只通過了以下命令來安裝,然后我想像windows中那樣修改 php.ini 就開啟了擴展

./configure \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-soap \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd

$ make && make install

拷貝下載的php-7.2.6文件中的擴展文件

cp -r /opt/downloads/php-7.2.6/ext /usr/local/lib/

然后去修改完 php.ini 文件,開啟了以下擴展

extension_dir = "/usr/local/lib/etc"
extension=bz2
extension=curl
;extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
extension=odbc
extension=openssl
extension=pdo_firebird
extension=pdo_mysql
extension=pdo_oci
extension=pdo_odbc;
extension=pdo_pgsql;
extension=pdo_sqlite
extension=pgsql
;extension=shmop

運行報錯 php-fpm -t

[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'bz2' (tried: /usr/local/lib/ext/bz2 (/usr/local/lib/ext/bz2: cannot read file data: Is a directory), /usr/local/lib/ext/bz2.so (/usr/local/lib/ext/bz2.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'bz2' (tried: /usr/local/lib/ext/bz2 (/usr/local/lib/ext/bz2: cannot read file data: Is a directory), /usr/local/lib/ext/bz2.so (/usr/local/lib/ext/bz2.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'curl' (tried: /usr/local/lib/ext/curl (/usr/local/lib/ext/curl: cannot read file data: Is a directory), /usr/local/lib/ext/curl.so (/usr/local/lib/ext/curl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'curl' (tried: /usr/local/lib/ext/curl (/usr/local/lib/ext/curl: cannot read file data: Is a directory), /usr/local/lib/ext/curl.so (/usr/local/lib/ext/curl.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'gd2' (tried: /usr/local/lib/ext/gd2 (/usr/local/lib/ext/gd2: cannot open shared object file: No such file or directory), /usr/local/lib/ext/gd2.so (/usr/local/lib/ext/gd2.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'gd2' (tried: /usr/local/lib/ext/gd2 (/usr/local/lib/ext/gd2: cannot open shared object file: No such file or directory), /usr/local/lib/ext/gd2.so (/usr/local/lib/ext/gd2.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'gettext' (tried: /usr/local/lib/ext/gettext (/usr/local/lib/ext/gettext: cannot read file data: Is a directory), /usr/local/lib/ext/gettext.so (/usr/local/lib/ext/gettext.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'gettext' (tried: /usr/local/lib/ext/gettext (/usr/local/lib/ext/gettext: cannot read file data: Is a directory), /usr/local/lib/ext/gettext.so (/usr/local/lib/ext/gettext.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring' (tried: /usr/local/lib/ext/mbstring (/usr/local/lib/ext/mbstring: cannot read file data: Is a directory), /usr/local/lib/ext/mbstring.so (/usr/local/lib/ext/mbstring.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'mbstring' (tried: /usr/local/lib/ext/mbstring (/usr/local/lib/ext/mbstring: cannot read file data: Is a directory), /usr/local/lib/ext/mbstring.so (/usr/local/lib/ext/mbstring.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/local/lib/ext/mysqli (/usr/local/lib/ext/mysqli: cannot read file data: Is a directory), /usr/local/lib/ext/mysqli.so (/usr/local/lib/ext/mysqli.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/local/lib/ext/mysqli (/usr/local/lib/ext/mysqli: cannot read file data: Is a directory), /usr/local/lib/ext/mysqli.so (/usr/local/lib/ext/mysqli.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'odbc' (tried: /usr/local/lib/ext/odbc (/usr/local/lib/ext/odbc: cannot read file data: Is a directory), /usr/local/lib/ext/odbc.so (/usr/local/lib/ext/odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'odbc' (tried: /usr/local/lib/ext/odbc (/usr/local/lib/ext/odbc: cannot read file data: Is a directory), /usr/local/lib/ext/odbc.so (/usr/local/lib/ext/odbc.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'openssl' (tried: /usr/local/lib/ext/openssl (/usr/local/lib/ext/openssl: cannot read file data: Is a directory), /usr/local/lib/ext/openssl.so (/usr/local/lib/ext/openssl.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'openssl' (tried: /usr/local/lib/ext/openssl (/usr/local/lib/ext/openssl: cannot read file data: Is a directory), /usr/local/lib/ext/openssl.so (/usr/local/lib/ext/openssl.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_firebird' (tried: /usr/local/lib/ext/pdo_firebird (/usr/local/lib/ext/pdo_firebird: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_firebird.so (/usr/local/lib/ext/pdo_firebird.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_firebird' (tried: /usr/local/lib/ext/pdo_firebird (/usr/local/lib/ext/pdo_firebird: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_firebird.so (/usr/local/lib/ext/pdo_firebird.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/local/lib/ext/pdo_mysql (/usr/local/lib/ext/pdo_mysql: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_mysql.so (/usr/local/lib/ext/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/local/lib/ext/pdo_mysql (/usr/local/lib/ext/pdo_mysql: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_mysql.so (/usr/local/lib/ext/pdo_mysql.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_oci' (tried: /usr/local/lib/ext/pdo_oci (/usr/local/lib/ext/pdo_oci: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_oci.so (/usr/local/lib/ext/pdo_oci.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_oci' (tried: /usr/local/lib/ext/pdo_oci (/usr/local/lib/ext/pdo_oci: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_oci.so (/usr/local/lib/ext/pdo_oci.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/ext/pdo_odbc (/usr/local/lib/ext/pdo_odbc: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_odbc.so (/usr/local/lib/ext/pdo_odbc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_odbc' (tried: /usr/local/lib/ext/pdo_odbc (/usr/local/lib/ext/pdo_odbc: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_odbc.so (/usr/local/lib/ext/pdo_odbc.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/local/lib/ext/pdo_pgsql (/usr/local/lib/ext/pdo_pgsql: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_pgsql.so (/usr/local/lib/ext/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_pgsql' (tried: /usr/local/lib/ext/pdo_pgsql (/usr/local/lib/ext/pdo_pgsql: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_pgsql.so (/usr/local/lib/ext/pdo_pgsql.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/local/lib/ext/pdo_sqlite (/usr/local/lib/ext/pdo_sqlite: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_sqlite.so (/usr/local/lib/ext/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pdo_sqlite' (tried: /usr/local/lib/ext/pdo_sqlite (/usr/local/lib/ext/pdo_sqlite: cannot read file data: Is a directory), /usr/local/lib/ext/pdo_sqlite.so (/usr/local/lib/ext/pdo_sqlite.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/local/lib/ext/pgsql (/usr/local/lib/ext/pgsql: cannot read file data: Is a directory), /usr/local/lib/ext/pgsql.so (/usr/local/lib/ext/pgsql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'pgsql' (tried: /usr/local/lib/ext/pgsql (/usr/local/lib/ext/pgsql: cannot read file data: Is a directory), /usr/local/lib/ext/pgsql.so (/usr/local/lib/ext/pgsql.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'soap' (tried: /usr/local/lib/ext/soap (/usr/local/lib/ext/soap: cannot read file data: Is a directory), /usr/local/lib/ext/soap.so (/usr/local/lib/ext/soap.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'soap' (tried: /usr/local/lib/ext/soap (/usr/local/lib/ext/soap: cannot read file data: Is a directory), /usr/local/lib/ext/soap.so (/usr/local/lib/ext/soap.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'sockets' (tried: /usr/local/lib/ext/sockets (/usr/local/lib/ext/sockets: cannot read file data: Is a directory), /usr/local/lib/ext/sockets.so (/usr/local/lib/ext/sockets.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'sockets' (tried: /usr/local/lib/ext/sockets (/usr/local/lib/ext/sockets: cannot read file data: Is a directory), /usr/local/lib/ext/sockets.so (/usr/local/lib/ext/sockets.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlite3' (tried: /usr/local/lib/ext/sqlite3 (/usr/local/lib/ext/sqlite3: cannot read file data: Is a directory), /usr/local/lib/ext/sqlite3.so (/usr/local/lib/ext/sqlite3.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'sqlite3' (tried: /usr/local/lib/ext/sqlite3 (/usr/local/lib/ext/sqlite3: cannot read file data: Is a directory), /usr/local/lib/ext/sqlite3.so (/usr/local/lib/ext/sqlite3.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'xmlrpc' (tried: /usr/local/lib/ext/xmlrpc (/usr/local/lib/ext/xmlrpc: cannot read file data: Is a directory), /usr/local/lib/ext/xmlrpc.so (/usr/local/lib/ext/xmlrpc.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'xmlrpc' (tried: /usr/local/lib/ext/xmlrpc (/usr/local/lib/ext/xmlrpc: cannot read file data: Is a directory), /usr/local/lib/ext/xmlrpc.so (/usr/local/lib/ext/xmlrpc.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line <b>0</b><br />
[25-May-2018 08:24:59] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
回答
編輯回答
安淺陌

1、你在Windows可以這樣操作的前提是你的系統(tǒng)里面已經(jīng)安裝了相關(guān)的php擴展庫,所以你能夠通過修改php.ini的方式來開啟或關(guān)閉這些php擴展庫
2、你現(xiàn)在在Linux里面并沒有安裝上述的php擴展庫,從報錯Unable to load dynamic library里面可以得知
3、在Linux里面安裝擴展的方法,不是修改php.ini后會自動安裝的,如果你用的是Ubuntu,那么就使用 apt install php-common,apt install php-pdo,apt install php-mbstring,逐個添加上述PHP擴展庫

2017年2月21日 02:21