Enabling extensions in PHP CLI on a synology DS

This guide shows how to enable extensions in PHP CLI (command line interface).

Check your php ini location

php --ini

Change to the folder to where the php.ini is located given by the previous command which was in my case

/usr/local/etc/php70/php.ini

Use vi to edit the file

sudo vi php.ini

Change the extension dir path in php.ini to /volume1/@appstore/PHP7.0/usr/local/lib/php70/modules. Depending on your PHP version the location might differ.

Enable the extension by adding the following code line to your php.ini. Here’s an example showing how to enable PDO_mysql support.

extension = pdo_mysql.so

I had to the correct php executable. In my case it was located under

/volume1/@appstore/PHP7.0/usr/local/bin

There is no restart of any kind necessary to make this work as php.ini is initialised on every start when using PHP CLI. If you want to enable the extension on your webserver you have to to use the DSM settings for webstation to do it.

23 Comments

  1. Sece Lameme

    Hi,
    I read your post concerning enabling pdo_mysql extension, because I have serious problems with enabling PDO with php5.6. Every time I get the error that driver could not be found.
    I have a DS411 with DSM 6.x installed, running apache2.2, php5.6, mariadb10 and web station.
    I followed your guide. Found via php -m the path where php.ini is located (the location differs however from the location phpinfo() shows…).
    Changed the extensiondir_path and added pro_mysql.so.
    I don’t know how to correct the php executable.

    When I do ‘php -m’ all the loaded php modules are shown. I can see PDO among them, but no pdo_mysql.
    It’s all very confusing and frustrating.

    Is there a chance you can help me?

    Thanks,
    Sece

    • There are usually multiple php.ini. The PHP CLI uses a different one than the webservice. Did you try the command line “php –ini” to see which one PHP CLI is using? Btw. PHP package update seems to overwrite the ini file used by the CLI. I usually run CLI in a location similar to this “/volume1/@appstore/PHP7.0/usr/local/bin” as this seemed to matter aswell.

  2. Sece Lameme

    Whe I try “php -ini” I get the phpinfo() which tells me the version used: 5.6.11 That differs from the version I get from the web service : 5.6.40
    I didn’t know there are different versions.
    This is the first part of phpinfo():
    Build Date => Apr 20 2017 02:51:16
    Server API => Command Line Interface
    Virtual Directory Support => disabled
    Configuration File (php.ini) Path => /etc/php
    Loaded Configuration File => /etc/php/php.ini
    Scan this dir for additional .ini files => (none)
    Additional .ini files parsed => (none)
    PHP API => 20131106
    PHP Extension => 20131226
    Zend Extension => 220131226
    Zend Extension Build => API220131226,NTS
    PHP Extension Build => API20131226,NTS
    Debug Build => no
    Thread Safety => disabled
    Zend Signal Handling => disabled
    Zend Memory Manager => enabled
    Zend Multibyte Support => provided by mbstring
    IPv6 Support => enabled
    DTrace Support => disabled

    Registered PHP Streams => compress.zlib, php, file, glob, data, http, ftp
    Registered Stream Socket Transports => tcp, udp, unix, udg
    Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk

    In the ‘CORE’ part of this phpinfo() I see this line you mentioned in your guide:
    extension_dir => /usr/local/lib/php56/modules => /usr/local/lib/php56/modules

    When I do php –ini I get:
    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php56/modules/pdo_mysql.so’ – /usr/local/lib/php56/modules/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
    Configuration File (php.ini) Path: /etc/php
    Loaded Configuration File: /etc/php/php.ini
    Scan for additional .ini files in: (none)
    Additional .ini files parsed: (none)

    Somehow I have to change some settings, but I do not have any clue what and where to change.

  3. Sece Lameme

    I have put them in that directory myself. I’ve read somewhere on the web the suggestion to put them there. But this is wrong, I assume?
    Please can you tell me what to do?

  4. If your webserver is running check php-info() there to see which directory is used for the modules. Put the extension-dir path to that directory. I think I’m using “/volume1/@appstore/PHP7.0/usr/local/lib/php70/modules/” and double check that the PDO extension is listed there.

  5. Sece Lameme

    I will see to that tomorrow. At the moment I must leave. I hope I can come back to you tomorrow? For now, I thank you for your suggestions. I will let you know my progress.
    Gr. Sece

  6. Sece Lameme

    On this place: /volume1/@appstore/WebStation/misc/WebStation-php56/conf.d$ I found the file: ‘extension.ini’ with all the extensions I think will need, including ‘pdo_mysql.so’
    According to phpinfo() the extension_dir path is ‘/usr/local/lib/php56/modules’ So I copied the ‘extension.ini’ to this extension_dir path.
    Now what? Should I restart Apache? Or Web Station? Can I do that with the CLI? If so, which command to restart?

    • You need to copy the pdo_mysql.so to the modules. directory. And as I said before, if you call phpinfo() via web browser, you will see the PHP configuration for the webserver not CLI.

  7. Sece Lameme

    pdo_mysql.so is inside the extension.ini file.
    How do I get pdo_mysql.so out of extension.ini and place it in the modules directory?

  8. Sece Lameme

    Searching the whole system with ‘grep -ir “*.so” / ‘ or ‘grep -ir “pdo_mysql.so” /’ gives no result. It seems to me this file does not exist on my synology? Can I install this file somehow?

  9. Sece Lameme

    Finally found them. There are a bunch of SO files in this location:
    /volume1/@appstore/PHP5.6/usr/local/lib/php56/modules
    Now I have changed in all the php.ini files I could find the extension_dir path to /volume1/@appstore/PHP5.6/usr/local/lib/php56/modules.
    But…. no result.
    I cannot believe Synology has made this so complicated. IMHO it should work out of the box.

  10. Sece Lameme

    No success…
    I’m gone delete all web and php related stuff from my synology and start all over.
    Thank you for your suggestions and advise.
    Gr. Sece

Comments are closed.

Back to Top