2

I run this command to debug why php cli not working:

php -n MYPHPFILE.php 

And get this:

Fatal error: Class 'PDO' not found in example-file.php on line 59

I have checked PDO extension and its already correct installed. Im running nginx, php5 fpm server.

Any idea what is wrong?

5
  • Are you using namespaces in your app? Commented Feb 10, 2016 at 12:03
  • Are you sure that cli version is the same of apache version? Commented Feb 10, 2016 at 12:03
  • How can i check versions? Im using nginx with php5-fpm. And im running a Magento website Commented Feb 10, 2016 at 12:07
  • Why are you using the -n parameter? Commented Feb 10, 2016 at 12:39
  • How do you know that the PDO lib is installed properly? try running 'php -i | grep PDO ' from the command line Commented Feb 10, 2016 at 12:57

1 Answer 1

4

The -n switch means (quoted from php --help):

No php.ini file will be used

When PHP is built, it is usually configured with the option --with-config-file-scan-dir=target. This causes PHP to scan target upon startup for additional ini files, target might be something like /etc/php.d. This is usually the mechanism by which individual extensions are loaded.

The help text omits to mention that -n also stops target being scanned, what it will soon say is:

No configuration (ini) files will be used

This results in the configuration line that loads PDO (extension=pdo.so) not being used, either because it is in php.ini or because it is in another ini file inside the scan directory.

Remove the -n switch.

Sign up to request clarification or add additional context in comments.

1 Comment

I had to add the -c flag to tell the cli from where to load the php.ini : php -c /my_project/php.ini then it worked !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.