Install Composer on Synology

Here is how to install Composer on a Synology, required among other to install various php applications available on GitHub, like the “Simple SPK Server“.

Click to Read More

To install Composer, the following extensions must be loaded into php: curl, openssl and phar.

Connect into your DSM, open the Web Station via the Main Menu and enter the PHP Settings. There, select first the “PHP version” = “PHP 5.6”, tick the Extensions: curl, openssl and phar, and click Apply. Next, do the same for the “PHP version” = “PHP 7.0”.

WebStation Composer Option

Configuring extensions for php as illustrated above is only valid for the WebStation.

Open a SSH Console via Putty, log in as an administrator and enter next the root mode.

To load extensions into php, their respective php.ini file must be updated manually (Ex.: Edit them from a SSH console using VI). Path to php.ini are:

  • php70: /usr/local/etc/php50/php.ini
  • php73: /usr/local/etc/php73/cli/php.ini

In php ini, under the section [PHP] add the following lines

extension = phar.so
extension = openssl.so
extension = zip.so

To install Composer, use following commands:

cd /usr/local/bin
curl -s http://getcomposer.org/installer | php70

This should display the following message:

All settings correct for using Composer
Downloading…

Composer (version 1.3.1) successfully installed to: /usr/local/bin/composer.phar
Use it: php composer.phar

On Synology, php is not the command to use to run Composer. Instead, one should use php56 or php70. Ex.:

php70 composer.phar –version

To make use of it more easily, you can create a script. Use the command vi

vi composer

Enter the modification mode by typing the letter “i”.

Type the following text:

#!/bin/bash
php56 /usr/local/bin/composer.phar $*

Press ‘Esc’ to quit the modification mode.

To write the changes and quit vi, type next “:wq” (without the quotes).

Make the script executable with the following command:

chmod +X composer

Try now:

composer –version

Et voilà.

NB.:

  • The following command can also be used to install ‘composer’ with the ‘php’ command: curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer
  • The following command can be used to update ‘composer’ : sudo composer self-update

Loading


Categories:

Tags:


Comments

6 responses to “Install Composer on Synology”

  1. MJ Avatar
    MJ

    Thanks!
    Just in case somebody has the same experience I had: For me this to work I had to follow
    https://forum.synology.com/enu/viewtopic.php?t=135390#p499881
    Here is what I did:

    First I followed your instructions to the letter (enabled phar, as curl and openssl were already enabled. For both php 5.6 and 7.0) first, but on the command line, gave me errors:

    root@NAS:~# cd /usr/local/bin
    root@NAS:/usr/local/bin# curl -s http://getcomposer.org/installer | php56
    Some settings on your machine make Composer unable to work properly.
    Make sure that you fix the issues listed below and run this script again:

    The phar extension is missing.
    Install it or recompile php without –disable-phar

    root@NAS:/usr/local/bin#

    So I tried instead the instructions in this post https://forum.synology.com/enu/viewtopic.php?t=135390#p499881

    and here is the result:

    root@NAS:/usr/local/bin# curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer
    All settings correct for using Composer
    Downloading…

    Composer (version 1.6.3) successfully installed to: /usr/local/bin/composer
    Use it: php /usr/local/bin/composer

    root@NAS:/usr/local/bin# composer –version
    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Composer version 1.6.3 2018-01-31 16:28:17
    root@NAS:/usr/local/bin#

    Hope this helps others that may experience the same. Cheers!

    DS3615xs, DSM 6.1DSM 6.1.5-15254 Update 1

    1. Valery Letroye Avatar

      Thx for posting this feedback!

  2. Eric H. Bowen Avatar
    Eric H. Bowen

    My Composer installation is unable to install patches. I get the output, “sh: patch: command not found”. Apparently there’s a missing CLI ‘patch’ command that Composer is looking for. Do you know where I can find it and how to install it on a Synology RackStation (current firmware)?

    1. Valery Letroye Avatar

      Alas no, I have no experience at all with installing patches.

  3. Donald Avatar
    Donald

    When I install this, I haven’t yet, but when I do, do I have to install it for every version of php I have installed on my Synology NAS? I currently have all four available versions installed, php 5.6, 7.0, 7.2, 7.3.

    Thanks in Advance! 🙂
    -Donald

    1. Valery Letroye Avatar

      No. You have to install it only once, with one version of PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *