5

I'm trying to execute a php script via command line on my synology NAS. Via web browser it's working fine. However, via CLI I'm getting an error although I loaded the extensions in /etc/php/php.ini.

Fatal error: Uncaught PDOException: could not find driver in /volume1/web/blabla.php:16

Any ideas?

guntbert
  • 536
  • 6
  • 19
blackswan
  • 204
  • 3
  • 16
  • Well the bla bla bit might be useful so would you mind. And some actual code as well – RiggsFolly Jun 30 '17 at 14:47
  • And **who upvoted** a vague, badly asked question like this. ___Please read the tooltip you get when you hover over the upvote button___ ..... It doesn't, it isn't and it isn't – RiggsFolly Jun 30 '17 at 14:50
  • Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) – RiggsFolly Jun 30 '17 at 14:52
  • 3
    Nothing to do with the code so why should I post actual code? – blackswan Jun 30 '17 at 20:07
  • Do you realise that there are normally 2 `php.ini` files. One for use with Apache and one exclusively for the PHP CLI. Run `php --ini` and see where you PHP CLI ini file actually lives – RiggsFolly Jun 30 '17 at 20:10
  • You're my god! Changing the extension dir path to "/volume1/@appstore/PHP7.0/usr/local/lib/php70/modules" and adding the extension in the correct PHP.ini helped to enable PDO support in CLI. Thank you very much! – blackswan Jul 01 '17 at 05:12

5 Answers5

7

Synology uses two different php intallations. One for the internal issues (like administrator panel) and the other from the package you've installed for the web server.

you can observe the differences running from command line:

php --ini
php56 --ini
php7 --ini

(depending of the php package installed)

use php56 or php7 to run your script


Update

Please use the following for more recent versions of PHP (assuming both are installed)

php72 --ini
php74 --ini
Rich S
  • 3,248
  • 3
  • 28
  • 49
Gonzalo Cao
  • 2,286
  • 1
  • 24
  • 20
  • With PHP7.4 WebStation loads extension from `/usr/syno/etc/packages/WebStation/php_profile/...somelongnumber.../conf.d/user_settings.ini` and CLI loads from `/usr/local/etc/php74/cli/conf.d/extension.ini`. Adding extensions to the last one did it for me. – Michel Feb 27 '21 at 10:08
2

I was in the same boat–trying to get PHP 7.0 to work on the command-line of my Synology DiskStation DS218+.

I typed php70 --ini and I found out that PHP was using an INI file located at /usr/local/etc/php70/php.ini.

I went to the directory

cd /usr/local/etc/php70/

Made a backup of the .ini file just incase.

sudo cp php.ini php.ini.bak

Opened vi.

sudo vi php.ini

Hit i to enter Insert mode. I changed from this:

extension_dir = "/usr/local/lib/php70/modules"

to this:

extension_dir = "/volume1/@appstore/PHP7.0/usr/local/lib/php70/modules"

I also added this line:

extension = pdo_mysql.so

I then hit Esc, followed by : then wq and . This leaves insert mode, writes the .ini to disk, and quits.

That's it! After that, I was able to run command-line scripts by invoking php70 followed by the script name.

DavidH
  • 1,420
  • 1
  • 14
  • 25
  • 1
    Synology PHP auto-update seems to overwrite the php.ini. So you might be better off disabling it. Maybe someone has an idea how to solve that issue. – blackswan May 04 '18 at 15:49
1

Just make sure to use the correct PHP version and PHP.ini. You can find the location of your php.ini by typing "php --ini". You can also do that on the executables php56/php70. They all have separate php.ini files. Additionaly make sure to load the correct extension directory in the applicable php.ini file.

blackswan
  • 204
  • 3
  • 16
0

for me (DSM 6.1.6-15266 Update 1) the following helped:

Add the following lines to /usr/local/etc/php70/php.ini

extension = pdo_mysql.so
extension = openssl.so

I struggled very long to get the correct values, finally I found them by comparing to the config files of the php56 instance.

olidem
  • 1,961
  • 2
  • 20
  • 45
-1

Did you try: php56 path/to/script.php or php70 path/to/script.php ? If I'm not wrong, /etc/php/php.ini is for DSM engine... For symfony, I use php56 bin/console command. php or php70 doesn't work for me (DSM 6.1.3 on DS415+) Hope it helps !

LeFauve
  • 33
  • 7