Auto-hébergement Logiciel Synology

How to fix PHP 7 bash error to update Nextcloud on Synology?

PHP 7 is mandatory since Nextcloud 14

If you tried to update Nextcloud to Synology from the console, you probably had to run into an error when you needed to run PHP.

Synology made it the hard way for the users : the « php » bash function has been replaced by « php56 » (dunno why…).

If you read this carefully, your reflexe will be to use php70 instead of php, when executing php 7 command…or not! with sudo -u http php70… for example you’ll get an error. And update Nextcloud since version 14 is impossible with php 5.6.

What we need here is to create a script we can call every time we need to exectute a php 7 command (still in bash) and pass the error

Prerequisites

Let’s assume that you have installed the PHP 5.6 and PHP 7 packages, and therefore a php 5.6 profile and a php 7 profile.

To start, we will have to locate the php 7 profile we will use: log in SSH to your server, and go to /var/packages/WebStation/etc/php_profile

You should have 2 folders with very complex names (a7557633-8e25-4a6a-83cd-7dc6fb38e783 for example). Edit the fpm.conf file.

Now you can see the syslog.ident = php70-fpm line which indicate you are on the right profile (The php 5.6 profile has obviously syslog.ident = php56-fpm). Write down the character string corresponding to the name of the profile, then proceed to script creation:

Script creation

Replace the-profile-name by… the character string you noted before, then save the file giving the name script_php70.sh for example, and drop it to your server.

You can also do it into the console

Now you can replace php in all your commands by ./script_70.sh.

For example to update Nextcloud  :

Create an alias

To avoid remembering the script path whenever you need it, let’s create an alias:

In the file /etc.defaults/.bashrc_profile, let’s add the line:

I chose php-7 for my alias (but you can chose everything you want). You can now relog to your server in SSH, and use php-7 to run your php7 commands.

We finally have all the elements to serenely begin the update of Nextcloud: I will detail all this in a future article! 🙂

Thanks Andreas from Viking Studios for the tip!


4 Commentaires
  1. I knew about that workaround and i used this since nextcloud 14.
    (
    For german speaking people, there is a tutorial for it on
    http://blog.viking-studios.net/synology-php-7-cli-fehlerfrei-nextcloud-und-php-7/
    )
    But now on nextcloud 15 I’ve got a warning that I should install the imagick php module.
    Do you have an idea how to do this

    • raphael 5 mois ago
      Répondre

      Hey,
      I have the same warning, and I’ve just started to look around how to solve this! I will add this when founded !

  2. Felix 5 mois ago
    Répondre

    Hey,

    thanks for your manual. I did all the steps and executing php-7 also works. I can run
    php-7 occ
    in my nextcloud folder, but then I get the error message, that the user is worng:
    Console has to be executed with the user that owns the file config/config.php
    Current user: root
    Owner of config.php: http
    Try adding ‘sudo -u http ‘ to the beginning of the command (without the single quotes)

    So when I execute
    sudo -u http php-7 occ
    I get the error:
    sudo: php-7: command not found

    Why isn’t the shell recognizing the php-7 when there is sudo in front?

    Best regards
    Felix

    • raphael 5 mois ago
      Répondre

      Hey Felix,
      Indeed you have to change the permissions of the script to use it (and use it with the right user, not in sudo) : you can solve this with a ‘chown http the-file.sh’ !

Leave a Comment

Votre adresse ne sera pas publiée.

Vous pourriez aussi aimer