为什么 PHP 模块没有加载到 PHP 中?

为什么 PHP 模块没有加载到 PHP 中?

展示我的案例如何调试 PHP 模块未加载到 PHP 中的问题。

我使用 OpenSUSE v42.2 Linux 操作系统,带有 Apache 网络服务器、PHP v7.1 和 Mysql。

因为它没有提供我需要的 PHP v7.1,所以我从源代码构建了 PHP v7.1。使用 PHP-FPM。

我将其安装到

/opt/php-7.1/

php.ini 位于:

/opt/php-7.1/lib/php.ini

我发现 opcache 安装到

/opt/php-7.1/lib64/extensions/no-debug-non-zts-20160303/opcache.so

我编辑了 php.ini 并添加了以下行:

zend_extension=/opt/php-7.1/lib64/extensions/no-debug-non-zts-20160303/opcache.so

已重新启动:

systemctl restart php-7.1-fpm.service
systemctl restart apache2.service

但我仍然得到以下结果:

php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]

[Zend Modules] 中缺少 opcache。

但是在配置中有'--enable-opcache':

php -i | grep -i opcache

配置命令 => './configure' '--prefix=/opt/php-7.1' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-intl' '--enable-calendar' '--with-curl' '--with-mcrypt' '--with-gd' '--with-pgsql' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-zlib' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-pcntl' '--enable-mbregex' '--enable-exif' '--enable-bcmath' '--with-mhash' '--enable-zip' '--with-pcre-regex' '--with-pdo-mysql' '--with-mysqli' '--with-mysql-sock=/var/run/mysql/mysql.sock' '--with-xpm-dir=/usr' '--with-webp-dir=/usr' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=wwwrun' '--with-fpm-group=www' '--with-libdir=lib64' '--enable-ftp' '--使用-imap' '--使用-imap-ssl' '--使用-kerberos' '--使用-gettext' '--使用-xmlrpc' '--使用-xsl' '--启用-opcache' '--启用-fpm'

我也尝试指定为:

zend_extension=opcache

但我得到了相同的结果,opcache 仍然丢失。

如何修复以启用 opcache?

答案1

就我而言,受影响的模块是opcachePHP 模块。

解决方案:

我注意到,在 phpinfo 中,“display_errors”本地值为 OFF,主值为 ON。因为主值来自 php.ini,并且有/opt/php-7.1/lib/php.inidisplay_errors = Off”,这意味着此 php.ini 未加载。

还发现,“ Loaded Configuration File”字段值为空,所以也说明php.ini没有加载。

但是 php.ini 位于(并且应该从此处加载)/opt/php-7.1/lib/php.ini:。

此外我注意到,在 phpinfo 中“ Configuration File (php.ini) Path”被设置为:“ /opt/php-7.1/lib64”,所以这意味着 php.ini 应该位于/opt/php-7.1/lib64/目录中。

步骤1修复:

copy php.ini 
from 
/opt/php-7.1/lib/php.ini
to
/opt/php-7.1/lib64/php.ini

在命令行中:

cp -p /opt/php-7.1/lib/php.ini /opt/php-7.1/lib64/php.ini

还注意到,php 是使用'--with-libdir=lib64'参数进行编译的。

这可能意味着应该在这个目录下找到“opcache.so”文件。

目前“opcache.so”位于目录:“ /opt/php-7.1/lib64/extensions/no-debug-non-zts-20160303/”。我认为将“opcache.so”放置到“ /opt/php-7.1/lib64/extensions/”就足够了。这成为了最终的修复。

步骤2 修复:

copy opcache.a & opcache.so
from 
/opt/php-7.1/lib64/extensions/no-debug-non-zts-20160303/
to
/opt/php-7.1/lib64/extensions/

在命令行中:

cp -p /opt/php-7.1/lib64/extensions/no-debug-non-zts-20160303/opcache.* /opt/php-7.1/lib64/extensions/

步骤3 修复:

重新启动 Apache 和 PHP-FPM(可选,如果使用):

service apache2 restart
service php-7.1-fpm restart

完成这 3 个修复步骤后,PHP opcache module is loaded successfully

结果:

php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imap
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

相关内容