Rizhiy Rizhiy - 20 days ago 7
PHP Question

PHP module is shown in phpinfo(), but not php -m

I'm currently working on a website. I used the host's control panel to activate several php modules. Now when I try to use them it returns


Fatal error: Class '...' not found


I checked
phpinfo()
and the classes appear there, but when I do
php -m
, they are missing. The server uses Nginx.

What can be the problem and how can I fix it?

Answer

Your PHP web installation and your PHP cli installation can be two completely seperate things, and hence they usually have their own ini configuration files.

As per your comment, this is the output you get from your CLI phpinfo:

Loaded Configuration File: (none) 
Scan for additional .ini files in: /usr/opt/php56/etc/php 
Additional .ini files parsed: (none)

As you can see there's no "Loaded Configuration File". As per this post you can specify what ini file to load when running cli scripts.

Since your regular web installation says:

Loaded Configuration File   /home/a2869511/etc/php.ini

Then you can automatically have your CLI program execute with the same ini file:

php --with-config-file-path=/home/a2869511/etc/php.ini script.php

That said, I would recommend that you take a copy of the ini file and place it where your cli application is looking for ini files, which is in /usr/opt/php56/etc/php ("Scan for additional .ini files in").

So the short solution would be to do the following copy:

cp /home/a2869511/etc/php.ini /usr/opt/php56/etc/php/php.ini