加载php模块时出错 [英] Error when loading a php module

查看:103
本文介绍了加载php模块时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在/etc/php/7.0/cli/php.ini中添加了curl模块:

I added the curl module in /etc/php/7.0/cli/php.ini :

extension = /usr/lib/php5/20121212/curl.so

但是当我重新启动php时,我会这样做:

but when I restart php and I do :

php -m

我收到此错误:

curl : Unable to initialize module
Module compiled with module API=20121212
PHP    compiled with module API=20141010
These options need to match


我也尝试过:


I also tried :

apt-get install php5-curl

Curl是已经使用新版本".

Curl is "already to the new version".

然后phpinfo()告诉php5正在运行:

And phpinfo() tells php5 is running :

PHP Version 5.5.9
php.ini Path :  /etc/php5/fpm 
PHP Extension : 20121212 

但是当我用:p检查服务器时

but when I check on the server with :

which php  => /usr/bin/php  (for php7)
php -v     => PHP 7.0  (with a warning before "Unable to initialize module")


如果我在上面的php.ini中(第一行的php7之一)删除了curl.so,则警告消失.


and if I remove curl.so in the php.ini above (the one of php7, at 1st line) the warning disapear.

所以我添加了:extension =/usr/lib/php5/20121212/curl.so

so I added : extension=/usr/lib/php5/20121212/curl.so

在:

/etc/php5/fpm/php.ini

然后我重新启动,但仍然看不到此模块:

then I restart, but I still can't see this module :

在这里,错误提示此模块仍然丢失:

And here the error saying this module is still missing :

推荐答案

因此,如果您尝试将模块添加到Web服务器的PHP(在您的情况下为PHP5)中,则需要将该模块添加到/etc/php5/fpm/php.ini(根据您先前提到的问题,即您声明使用NGINX + PHP-FPM).

So, if you're trying to add the module to webserver's PHP, which is in your case PHP5, you need to add that module to /etc/php5/fpm/php.ini (based on your previous question where you stated that you use NGINX+PHP-FPM).

如果要将其添加到CLI版本中-做错了,因为您正在向PHP7添加PHP5模块-无法正常工作,则需要安装php7-curl,它将自动添加本身在需要的地方.

If you want to add it to the CLI version - you're doing it wrong, cause you're adding PHP5 module to PHP7 - that won't work, you need to install php7-curl and it will auto-add itself where needed.

要详细说明.您的phpinfo()告诉您INI路径在/etc/php5/fpm中:

To elaborate somewhat more. Your phpinfo() tells you that your INI path is in /etc/php5/fpm:

PHP Version 5.5.9 
php.ini Path :  /etc/php5/fpm  
PHP Extension : 20121212

因此,要将任何扩展添加到特定的PHP的 -只需将其添加到/etc/php5/fpm/php.ini.请注意,您不能(或很少)将扩展从一个版本的PHP添加到另一个版本的PHP.

Hence, to add any extensions to that particular PHP - just add them to /etc/php5/fpm/php.ini. Note, you can not (or very rarely) add extensions from one version of PHP to another version of PHP.

我将添加OP系统上正在发生的情况的摘要,以供将来参考.

I'll add a summary of what's happening on the OP's system for future reference then.

基本上,OP会同时在系统上安装两个版本的PHP,PHP5和PHP7以及带有php-fpm扩展名的NGINX werserver.

Basically, OP has 2 versions of PHP installed on the system simultaneously, PHP5 and PHP7 with an NGINX werserver with php-fpm extension.

他的NGINX配置为使用PHP5,而CLI PHP默认为PHP7.

His NGINX is configured to use PHP5, while CLI PHP defaults to PHP7.

与OP的混淆来自以下事实:在Ubuntu系统上,从CLI调用的PHP与网络服务器使用的PHP之间存在明显的区别.

The confusion with OP comes from the fact that on an Ubuntu system there's a clear difference between the PHP that's called from the CLI and the PHP that's used by webserver.

每个版本都提供CLI工具,分别为/usr/bin/php5/usr/bin/php7,其中一个默认链接/usr/bin/php指向一个特定版本,在本例中为PHP7.

CLI tools are available per-version as /usr/bin/php5 and /usr/bin/php7, with one default link /usr/bin/php pointing to one particular version, in this case PHP7.

对于FPM模块,有两个可用的软件包php5-fpmphp7-fpm,并且分别在/etc/php5/fpm/php.ini/etc/php/7.0/php.ini中进行配置.

For the FPM module, there are 2 packages available php5-fpm and php7-fpm, with respective configs in /etc/php5/fpm/php.ini and /etc/php/7.0/php.ini.

对于CLI,还有两个可用的软件包-php5-cliphp7-cli,在/etc/php5/cli/php.ini/etc/php/7.0/cli/php.ini中具有各自的配置.

For the CLI, there are 2 packages available as well - php5-cli and php7-cli, with respective configs in /etc/php5/cli/php.ini and /etc/php/7.0/cli/php.ini.

对于curl扩展,有一个相同的故事,php5-curlphp7-curl.扩展程序将由deb安装程序自动连接到所需的INI文件.

For curl extension, there's the same story, php5-curl and php7-curl. Extensions will be auto-wired to the needed INI files by the deb installer.

有趣地安装多个版本的PHP可能会造成这种混乱. :)

Installing multiple versions of PHP for fun can create this kind of confusion. :)

这篇关于加载php模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆