大网数据广告活动
服务器运维问答

PHP CLI not loading IMAP extension

· 52CE 我爱测

When I try to run a script that uses imap in my browser, it works fine (it is loaded from a Ubuntu 14.04 server on my network with the extension installed). However, when I try to use PHP CLI on said server, it doesn't load imap …

问题原文

原帖链接 · captainGeech · CC BY-SA 3.0

When I try to run a script that uses imap in my browser, it works fine (it is loaded from a Ubuntu 14.04 server on my network with the extension installed). However, when I try to use PHP CLI on said server, it doesn't load imap.

I wrote a simple script to check loaded extensions, using get_loaded_extensions(), and it taught me 2 things:

  • PHP CLI had 50 extensions, while running it through my web browser had 51.
  • Another extension I manually declared in my apache2/php.ini (imagick.so) was being loaded in both CLI and browser

Why is this happening, and how can I have all 51 extensions loaded in both CLI and browser?

已采纳解答

原帖链接 · Daniel Lawson · CC BY-SA 3.0

There are separate configuration files for PHP when called via Apache and when called via the CLI.

For example, in Debian (at least), these are in /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini, respectively.

The fact that you manually declared imagick.so in apache2/php.ini might not mean anything - most distributions have some other way of managing PHP modules, and can often automatically enable the extension for you, so it might have already been added.

I'd suggest looking up how your linux distribution manages PHP extensions (for Debian and Ubuntu, it uses a command called php5enmod, which needs to be called via sudo), or else just manually edit /etc/php5/cli/php.ini or similar to be up to date.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。