Install Redis server and phpredis extension into Synology NAS running DSM 6 without bootstrapping

Synology and Redis

In this post I will go through installation of Redis server and phpredis (extension for using Redis server with php) into Synology NAS running DSM 6 release candidate (without bootstrapping). Redis is an open source, advanced in-memory key-value store. It is often referred to as a data structure server since the keys can contain strings, hashes, lists, sets and sorted sets. Redis server can be used for example cache and transactional file locking (Owncloud platform).

This is not the only way to install these modules, but this is ONE way that I can confirm to work (at least for me).

Few assumptions made for this guide:

  • Synocommunity is enabled into Synology as package source, and PHP has been already installed to Synology NAS (php-cli enabled)
  • NANO is installed from Synocommunity so you can edit text files through SSH
  • This guide is made with Synology NAS and DSM 6 RC (release candidate)
  • Synology NAS has SSH enabled and user knows how to utilize SSH terminal connection
  • I have tested the setup with 2 Synology NAS devices:
    • 1) DS214   (32-bit)   
    • 2) RS815+ (64bit)
    • And this process is confirmed to work for both NAS devices. However there are different steps required, depending if target NAS device is 32bit or 64bit. This guide has the required steps for both included now – so follow instructions carefully.
  • I cannot guarantee that ALL other Synology NAS devices are working – but please post results below in case you have tried and tell your model so people will know.
  • And finally – you try this with your own responsibility, I have no guarantees for the results or that this will work for any other than my Synology NAS devices.  🙂

 

About the installation

The installation has 2 phases. In the first phase we install Redis server and make sure it is running correcly. In the second phase we install phpredis php extension, that will enable Redis server utilization through PHP, and we also confirm that it is running correctly. Finally we make the necessary changes to Owncloud configuration in order to support Redis cache and transactional file locking in Synology NAS running DSM 6 release candidate.

Installation steps – Phase 1 (installation of Redis server)

1)  First we need to install Redis server from Synocommunity. Go to Synology Package center and install it from there. If you can’t find it, enable Synocommunity as package source and then you will find it.

2)  After installation Start Redis server from Package Center – and IF it starts correctly  you get status ‘running’ :

Redis_started

If you got the Redis server running in package center – you can go directly to step 4 where we really confirm it is running. Otherwise proceed to next step where we troubleshoot the possible START issue in DSM 6.

3)  I did not get the Redis server running in package center after install. In order to get it working, I needed to modify the Redis start script – ‘start daemon ()‘ section.

Select Code
1
2
3
4
5
6
login as: admin
admin's password: xxxxxxxxxx
admin:~$ sudo -su root
Password: xxxxxxxxxxx
sh-4.3# cd /
sh-4.3# nano var/packages/redis/scripts/start-stop-status

Please modify the start script accordingly:

Select Code
1
2
3
4
5
start_daemon ()
{
setuid redis
exec /usr/local/redis/bin/redis-server /usr/local/redis/var/redis.conf
}

And this the how it looks in NANO:

Redis start fix for DSM 6

After this modification, the Synology package center Redis START-STOP are working for me without issues.

4)   Let’s make sure Redis server is running and working as expected:

Check that processes are running, and check Redis PING-PONG test:

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
login as: admin
admin's password: xxxxxxxxxx
admin:~$ sudo -su root
Password: xxxxxxxxxxx
sh-4.3# cd /
sh-4.3# ps aux | grep redis-server
root    3029   0.0  0.1   4628   784 pts/6    S+   00:48   0:00 grep redis-server
root    17453  0.1  0.2  20100  1384 ?        Ssl  Mar07  18:25 /usr/local/redis/bin/redis-server *:6379

sh-4.3# /usr/local/redis/bin/redis-cli ping
PONG
sh-4.3#

And here is the terminal outputs:

redis server check

If you have the Redis processes running ang Redis will respond to your PING with a PONG, you have setup Redis server correctly. Next we install the PHP extension for Redis.

Installation steps – Phase 2 (installation of phpredis extension)

In order in install phpredis extension – we need to install couple new packages into our Synology. These packages are not available from Synology package center, and I don’t want to start bootstrapping with ipkg –> I chose the approach to utilize ‘Debian chroot’ package from Synocommunity.

Debian is a free operating system (OS) that comes with over 29000 packages, precompiled software bundled up in a nice format for easy installation on your DiskStation. Debian Chroot allows you to benefit from the Debian OS inside your DiskStation, alongside DSM. And as this is used only for one-time install purposes, you can actually remove the Debian chroot from Synology package center afterwards – if wanted.

1)  As a first step – install Debian chroot package from Synocommunity in Synology Package Center (no need to start the package in package center).

Debian chroot install

Once installed – login through SSH, sudo to Root and run through following commands in terminal:

Select Code
1
2
3
4
5
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot

/usr/bin/apt-get update
/usr/bin/apt-get install php5-dev
/usr/bin/apt-get install php5-redis

The first command will start Debian chroot and bring you to the Debian terminal – and the next three commands will update packages and install php5-dev and php5-redis modules.

Now at this point we should test that the phpredis -module is working with the Debian chroot environment, so please still stay in the Debian chroot terminal and give following command there:

Select Code
1
2
3
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"

OK

If you go the response ‘OK’ – that means PHP can trigger the Redis in Debian chroot environment. However – we need to do few more things in order to make this work with Synology default PHP / webserver as well.

Please exit from the Debian chroot terminal (exit), back to Synology DSM ssh terminal, still being ‘sudo root’.

Below we have 32bit and 64bit versions, please choose your section based on target NAS you would be deploying this.


32bit -target

 

Step 1 – Find Debian chroot installed ‘redis.so’ module:

Select Code
1
2
find / -name 'redis.so' 2>/dev/null
/volume1/@appstore/debian-chroot/var/chroottarget/usr/lib/php5/20131226/redis.so

Terminal output:

find redis.so

 

Step 2 – Check compiled file redis.so settings – should be 32bit for 32bit target. You should do this in Debian chroot terminal:

Select Code
1
2
3
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot

file /usr/lib/php5/20131226/redis.so

Output should be something like this:

32bit check elf

Step 3 – Exit from Debian chroot terminal and take the file location from the first query and copy the required ‘redis.so’ module to following 2 locations and chmod permissions accordingly:

Select Code
1
2
3
4
5
cp /volume1/@appstore/debian-chroot/var/chroottarget/usr/lib/php5/20131226/redis.so /usr/local/lib/php56/modules/redis.so
chmod 755 /usr/local/lib/php56/modules/redis.so

cp /volume1/@appstore/debian-chroot/var/chroottarget/usr/lib/php5/20131226/redis.so /usr/lib/php/modules/redis.so
chmod 755 /usr/lib/php/modules/redis.so

 


64bit -target

For 64bit systems you need to download the phpredis and compile it manually for 64bit target. You are doing these in Debian chroot terminal.

Step 1 – Install zip and gcc-multilib, load phpredis.zip from GIT and compile it to 64bit target.

Select Code
1
2
3
4
5
6
7
8
sudo /var/packages/debian-chroot/scripts/start-stop-status chroot

/usr/bin/apt-get install zip unzip
/usr/bin/apt-get install gcc-multilib

/usr/bin/wget --no-check-certificate  https://github.com/phpredis/phpredis/archive/master.zip -O /tmp/phpredis_master.zip

/usr/bin/unzip -o /tmp/phpredis_master.zip && mv /tmp/phpredis-* /tmp/phpredis && cd /tmp/phpredis && phpize && ./configure CC='gcc -m64' CXX='g++ -m64' && make && make install

Now you should have generated 64bit redis.so file in the folder ‘/tmp/phpredis/modules/’

Step 2 – You can check the file settings for the generated redis.so, should be 64bit now:

Check64 bit ELF

Step 3 – Exit from Debian chroot terminal, find out redis.so file location in Debian chroot folder structure, and copy the required ‘redis.so’ module to following 2 locations and chmod permissions accordingly:

Select Code
1
2
3
4
5
6
7
find / -name 'redis.so'

cp /volume1/@appstore/debian-chroot/var/chroottarget/tmp/phpredis/modules/redis.so /usr/local/lib/php56/modules/redis.so
chmod 755 /usr/local/lib/php56/modules/redis.so

cp /volume1/@appstore/debian-chroot/var/chroottarget/tmp/phpredis/modules/redis.so /usr/lib/php/modules/redis.so
chmod 755 /usr/lib/php/modules/redis.so

 


Continue with general steps valid for 32 and 64 bit target systems.

 

Step 4 – Ensure phpredis for Apache/Web is started when Synology PHP is started:

Select Code
1
sudo bash -c "echo extension=redis.so > /usr/local/etc/php56/conf.d/redis.ini"

Doublecheck that path ‘/usr/local/etc/php56/conf.d/’ really now has ‘redis.ini’ file with content ‘extension=redis.so ‘.

Step 5 – Ensure that PHP CLI has also ‘redis.so’ php extension included, so that you can do testing in CLI.

First find out where exactly PHP CLI php.ini file is located, query is done in terminal – so you get PHP CLI result:

PHP CLI path

Then use NANO to edit PHP CLI php.ini and make sure that you have there the ‘extension=redis.so’ included:

Enable Redis for CLI PHP

So it should be clear to everyone that Apache PHP and CLI PHP have different php.ini files, and you can find the paths with above command for CLI and phpinfo() for the Apache PHP.

Step 6 – Restart your Synology NAS, or Restart your Web station, or change some PHP settings in Synology admin interface PHP settings section (ensures that PHP is re-started and new extensions loaded before proceeding to next step). 

Step 6a – Now after the PHP module re-start you actually might also be able to find REDIS module also in your webstation and PHP settings in your Synology. Here you could now enable the REDIS module, at least it should not do any harm (although enabling it should not be mandatory in this configuration).

enable_redis

And few users have also indicated that this was needed for REDIS to work. I personally disagree with that comment, as I personally don’t have it enabled here in any of my Owncloud installations.

Step 7 – Doublecheck your Apache PHP config accessing phpinfo() through web page, hopefully you will now find redis module loaded and enabled.

phpinfo redis enabled

Step 8 – Check loaded PHP modules in terminal (uses CLI php.ini):

Check php modules loaded

Step 9 – Test phpredis in action in Synology Terminal:

Select Code
1
2
3
4
sh-4.3# php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"

OK
sh-4.3#

And same example in SSH terminal:

check_phpredis_synology_

If you receive OK response – you can be pretty confident that you have now Redis-server and Redis PHP extension correctly installed and in use in your setup.

NOTE: If you do DSM update to your Synology – after update you need to check if the phpredis module is still loaded into Apache PHP or PHP CLI. Most probably it is not. If that is the case – you need to redo following steps:

  1. Re-copy the redis.so files to respective directories and assign permissions.
  2. Add ‘extension = redis.so’ to your PHP CLI -ini file.
  3. Re-start you PHP (restart webstation or change some php setting in your DSM UI)

This will enable phpredis again. It seems that Synology wants to overwrite few things on upgrades.   🙂

(Note: It is a good practice to take copies of such core files to somewhere outside system folders, that are manually installed into Synology Linux system folders – like in this case where we utilize Debian chroot installation procedure. As Synology has the tendency to overwrite and clear such files/folders on DSM upgrades, that are not delivered with the standard Synology OS. It makes the process for enabling these again a lot easier. You could actually even create the .sh scripts for copy/paste and permissions work – that would make it super easy.)

Final Step – Owncloud config

(NOTE: Please complete your Owncloud installation/setup fully, and test that it is working. Only then start modifying the config.php.)

Now you have successfully enabled Redis-server and Redis php extension in your Synology NAS – you can further enable Redis cache and Transactional File Locking for your Owncloud installation.

Please ensure that following lines can be found from your config.php file – in your Owncloud root config-folder, these will enable the usage of REDIS server through Owncloud for file locking purposes:

Select Code
1
2
3
4
5
6
'filelocking.enabled' => 'true',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
),

(Note: no duplicate ‘memcache.local’ or ‘memcache.locking’ rows should exist in your config.php. So use either REDIS or APCu for your local cache. Read more about this from Owncloud documentation.)

This is the config.php row, if you want/decide to use REDIS for local cache.

Select Code
1
'memcache.local' => '\\OC\\Memcache\\Redis'

Or alternatively, if you instead want to use APCu for your local cache, this is what you should have then in your config.php:

Select Code
1
'memcache.local' => '\\OC\\Memcache\\APCu',

Note: Highly recommended to read Owncloud documentation of different config.php parameters and cache configuration. And then decide and use the configuration that is valid for you.

All Done!

(If there is something wrong still in your CACHE config, you will get white blank page when trying to open Owncloud login page. If that happens, please check all the steps and checks made to ensure that everything is running properly.)

Also see my previous blog post about installing Owncloud 9 into Synology NAS.

Thanks – and please leave me a confirmation message below if this post helped you!!!!

(14.08.2016 – updated [apt-get] commands in chroot to use absolute paths, this will resolve the locale issue while executing commands in chroot)

Feedback

Juha Ketola

Juha Ketola

Author is a passionate IT enthusiast and early adopter. Packed with years of experience leading Enterprise level IT development teams within the biggest companies of Technology industry. Watches closely start-ups and new disruptive innovations in order to stay on the cutting edge. Embraces hands-on IT development and IoT.
Juha Ketola
Link to open Linkedin Profile

61 Responses to Install Redis server and phpredis extension into Synology NAS running DSM 6 without bootstrapping

  1. Sergey says:

    Install to Synology DS412+, DSM 6.0.2-8451 Update 2.

  2. Joshuah Albert Navarro says:

    Hello, for my DS416j DSM 6 I had to leave:
    su ${USER} -c “$(REDIS} ${CFG_FILE}” plus your code below that for Redis service to run.

  3. Joshuah Albert Navarro says:

    I have gotten so far as Step 8. I cannot confirm redis module loaded. Any help with this???

    • Juha KetolaJuha Ketola says:

      Hi,

      You cannot see redis loaded in the listing after running the php command? Or you cannot get the php module listing?

    • Juha KetolaJuha Ketola says:

      On the other hand, if step 7 and step 9 are working for you, you can actually skip the step 8. You will know that CLI-PHP is loaded if the PHP command will work in step 9.

  4. Joshuah Albert Navarro says:

    Okay. So a dash is surely not an equal sign. Retraced steps and found extension – redis instead of =sign.

    • Juha KetolaJuha Ketola says:

      Hey Joshuah!

      Yes, I can confirm that as well…. Dash is surely not equal sign. 🙂
      So you got it working?

      • Joshuah A Navarro says:

        Mr . Ketola,
        I can confirm that your instructions work perfectly on the Synology NAS DS416J.

        Thank you very much. Now off to install my Owncloud 9.

      • Juha KetolaJuha Ketola says:

        Great to hear – thanks for confirming.
        And enjoy your private cloud!

        Take care!

  5. Joshuah Albert Navarro says:

    One further question on the config.php file.
    I noticed that there is a ‘memcache.local’ => ‘\OC\Memcache\APCu’ setting.

    Leave that one alone???

    • Juha KetolaJuha Ketola says:

      Hi,

      You should have only one ‘memcache.local’ in your config.php.
      So please remove the APCu row, and have only the REDIS row.

      Otherwise you might get the white blank page problem. which is indication of cache problem.

      /Juha

    • Juha KetolaJuha Ketola says:

      Or you could just keep APCu as the local cache, and REDIS for file locking and distributed cache.
      It is basically up to you and your preferences. I have not made comparison in this if one is better over the other.

      Please let me know what you ended up with.
      Thanks.

  6. Victorien says:

    Good evening,

    Sorry for my English I use google translation.

    I installed the 64-bit away thinking that I had but a 64-bit result has PLUSIEUR command was not working I decided to check it and actually I turn on 32-bit, is it possible to return backward and have a redis.so original file?

    Thank you

    • Juha KetolaJuha Ketola says:

      Hi Victorien!

      If you need the 32bit redis.so, and you followed my guide – you should already have it in your chroot directories. Please search for the file in your system.

      Select Code
      1
      
      find / -name 'redis.so' 2>/dev/null

      If you did not find it, please see my guide above for installing it into the 32bit chroot environment.

      • Victorien says:

        Hello,

        When I type the command

        Select Code
        1
        
        file /usr/lib/php5/20131226/redis.so

        ELF 64-bit tells me that’s why that initially I deduced that it was a 64-bit and when I get to type the command

        I have this error

        [quote]mv: cannot stat ‘/tmp/phpredis-*’: No such file or directory[/quote]

      • Victorien says:

        This command

        Select Code
        1
        
        /usr/bin/unzip -o /tmp/phpredis_master.zip && mv /tmp/phpredis-* /tmp/phpredis && cd /tmp/phpredis && phpize && ./configure CC='gcc -m64' CXX='g++ -m64' && make && make install
  7. Victorien says:

    Edit : It’s ok I managed to make all the configuration but when I make changes in config.php owncloud I have an http 500 error.

    • Juha KetolaJuha Ketola says:

      Hi Victorien,

      May I ask how you edit your config.php file?
      I hope you are not messing the file format with some regular external text editor….?

      Safest way to modify the config.php is to first make backup, and then use native linux terminal editor like nano or similar…

  8. Richard says:

    Hi Juha,

    thanks for the explanation. I followed all steps and until the final steps, all the checks have worked exactly as you described.

    But after changing the config.php and trying to load Owncloud in the browser, I get a white page with one single line on it saying: Memcache \OC\Memcache\Redis not available for local cache Is the matching PHP module installed and enabled?

    What could be the error or what could I do to track it down?

  9. Richard says:

    Accidentially I found the solution: in the Webinterface of the Diskstation, the checkbox for the Redis package needed to be set. Not it is working like a charm. Thanks a lot!

    • Juha KetolaJuha Ketola says:

      Hi Richard,

      That is interesting. It should not needed to be there, if you have manually made all the inserts to .ini files, and also added the start script for Redis.

      However, after adding the files and extensions, the extension does indeed appear also to the web interface php settings, but ticking it should not be mandatory in this case. I have it myself unticked in all of my Owncloud instances.

      But who cares, if that sorted out the issue in your case. 😀
      It’s always great to hear that things work out for ppl reading these posts! Thanks for that.

      Take care!

      • Juha KetolaJuha Ketola says:

        I might actually add to my guide that please tick the extension in php settings. It’s quick to do, and if that helps someone – great! At least it can’t do any harm.

        So thanks again for this.

    • Juha KetolaJuha Ketola says:

      I’ve added this now to the guide, just in case.
      Thanks for the input – appreciated!

  10. Victorien says:

    Hello,

    My hard drive having broken down I have to reinstall.
    I have Debian chroot installed. But when I run the command

    [Code] / usr / bin / apt-get update [/ code]

    This tells me:
    [Code] bash: / usr / bin / apt-get:

    I uninstalled and reinstalled it but it still does not work.

    PS: sorry not to have replied to the previous message but following this I would answer if I have the problem again.

    Thank you for your help.

    • Victorien says:

      Sorry
      Error is

      Select Code
      1
      
      bash: /usr/bin/apt-get: No such file or directory
    • Victorien says:

      Hello,

      I’m sorry for before messages, i’ve résolve my error with debian.

      Now, i’ve finish install of redis, edit confi.php ok, php option redis ok but Owncloud always tells me that no cache is configured. how to do ?

      • Victorien says:

        Hello,

        Again sorry, I solved the problem by adding
        ‘memcache.local’ => ‘\OC\Memcache\APCu’,

        in config.php before

        ‘memcache.locking’ => ‘\\OC\\Memcache\\Redis’,

        And now it’s OK 🙂

        Thx and good day.

      • Juha KetolaJuha Ketola says:

        Hi!

        Ok – thanks Victorien for this confirmation.

        As my post is actually more about REDIS installation than CACHE configuration, so I have not touched APCu that much. But despite of that, I have now added to the guide more clear distinction between the file locking and cache configuration in config.php. And also little bit introduced the concept of local cache, for which you can use APCu or even REDIS if wanted.

        Thanks again!

  11. Alex says:

    Dear Juha, first thank you very much for the tutorial. I have a question about my result. Basically I followed your steps and I am getting OK when phpredis and I see process running when executing php -m but I don’t have in synology in webserver option to select the checkbox to “activate” redis.
    Can I proceed with the next steps or I need to do something additionally?

    Thank you very much !!!

    • Juha KetolaJuha Ketola says:

      Hi,

      If all the other checks are working for you (phpinfo, command line check), and Redis server and PHP process is working – there is no need to be concerned if you cannot see the ‘tick’ in your Synology settings.

      It just have been that some users have had to tick that, for the process to start to work. I myself do not need that, so it is beyond my understanding why/when it will appear there, and/or why someone needs to do that. If everything is working for you, do not worry about it too much.

      Thanks.

  12. Sven says:

    Thank you very much for your guide.
    Though I have a problem. In step 4, checking if redis is running with the line:

    php -r “if (new Redis() == true){ echo \”\r\n OK \r\n\”; }”

    I don’t get a response. Nothing. Just a blank new line in terminal and I have to exit putty manually. Even the exit-command isn’t working.
    Somebody knows what could be wrong? Glad for any help

    • Juha KetolaJuha Ketola says:

      Hi Sven!

      Did you solve the issue already?
      Is the Redis module available in the web server side through phpinfo()?

      If all other steps are working, and the console confirmation is failing, it must be something specific to your configuration and maybe to you CLI-PHP setup? So maybe not related to Redis at all, can you call PHP module otherwise successfully in command line?



Leave a Reply

css.php