How to execute PHP CLI script with extension on synology
Asked Answered
R

5

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?

Ritornello answered 30/6, 2017 at 14:46 Comment(6)
Well the bla bla bit might be useful so would you mind. And some actual code as wellMelanoid
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'tMelanoid
Please read What topics can I ask about and How to ask a good question and the perfect question and how to create a Minimal, Complete and Verifiable ExampleMelanoid
Nothing to do with the code so why should I post actual code?Ritornello
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 livesMelanoid
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!Ritornello
R
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.

Ritornello answered 20/10, 2017 at 10:46 Comment(0)
F
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
Fragmentation answered 21/11, 2017 at 11:58 Comment(1)
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.Fitly
H
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.

Heilbronn answered 3/5, 2018 at 13:39 Comment(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.Ritornello
R
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.

Ritornello answered 20/10, 2017 at 10:46 Comment(0)
P
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.

Pulpy answered 18/5, 2018 at 5:27 Comment(0)
A
-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 !

Adkins answered 13/10, 2017 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.