redis-300dpiWe previously wrote a guide on how to install Redis Server on your Ubuntu Server with PHP 5. This guide is an updated version on how to install it with PHP 7. The difference here is that we with PHP 7 needed to build the PHP module as well, because PECL install didn’t work on PHP 7 yet. And as usual – as we didn’t find any good straight forward guide, here is one that works, enjoy!

Note, in case you don’t have PHP 7 installed, you have to install it before you run this guide.

If you’d rather install it directly with a script, use this one.

  1. GET RID OF APCU & MEMCACHED if you previously run php 5.
    $~: sudo php5dismod apcu && sudo apt-get purge php5-apcu -y
    $~: rm /etc/php5/mods-available/apcu-cli.ini
    $~: sudo apt-get purge --auto-remove memcached -y && php5dismod memcached
  2. INSTALL NEEDED DEPENDENCIES TO PREPARE THE REDIS INSTALLATION
    $~: sudo apt-get update && sudo apt-get install build-essential -y
  3. INSTALL TCL TO BE ABLE TO RUN TESTS
    $~: sudo apt-get install tcl8.5 -y
  4. INSTALL REDIS SERVER
    $~: sudo wget http://download.redis.io/releases/redis-stable.tar.gz && sudo tar xzf redis-stable.tar.gz
    CHANGE NAME OF THE FOLDER, LOOKS BETTER
    $~: sudo mv redis-stable redis
  5. RUN MAKE AND TEST THE CONFIG
    $~: cd redis && sudo make && taskset -c 1 sudo make test
  6. IF THE TEST WAS FINE, PROCEED WITH INSTALLATION
    $~: sudo make install
    $~: cd utils && sudo ./install_server.sh

    Just press [ENTER] if you want to choose the default settings

    Please select the redis port for this instance: [6379] Selecting default: 6379
    
    Please select the redis config file name [/etc/redis/6379.conf] 
    Selected default - /etc/redis/6379.conf
    
    Please select the redis log file name [/var/log/redis_6379.log] 
    Selected default - /var/log/redis_6379.log
    
    Please select the data directory for this instance [/var/lib/redis/6379] 
    Selected default - /var/lib/redis/6379
    
    Please select the redis executable path [/usr/local/bin/redis-server]
    Selected config:
    Port : 6379
    Config file : /etc/redis/6379.conf
    Log file : /var/log/redis_6379.log
    Data dir : /var/lib/redis/6379
    Executable : /usr/local/bin/redis-server
    Cli Executable : /usr/local/bin/redis-cli
    
    Is this ok? Then press ENTER to go on or Ctrl-C to abort.

    Now you sucessfully installed the latest version of Redis Server. You can check the version by typing

    $~: /usr/local/bin/redis-server -v

    Now we need to install the PHP module to get it working with Nextcloud

  7. INSTALL NEEDED DEPENDENCIES
    $~: sudo apt-get install php7.0-dev -y
  8. Install Git and clone repo
    $~: sudo apt-get install git -y -q && sudo git clone -b php7 https://github.com/phpredis/phpredis.git
  9. Move phpredis to /etc
    $~: sudo mv phpredis/ /etc/ && cd /etc/phpredis
  10. Build the phpmodule with make
    $~: sudo phpize && sudo ./configure && sudo make && sudo make install
  11. Add the extension to php.ini
    $~: sudo touch /etc/php/mods-available/redis.ini
    $~: sudo echo 'extension=redis.so' > /etc/php/mods-available/redis.ini
  12. Enable the extension and restart Apache
    $~: sudo phpenmod redis && sudo service apache2 restart
  13. Remove the dir we built it from, not needed anymore
    $~: cd .. && rm -rf phpredis
  14.  TEST YOUR MODULE VERSION

    It should be 2.2.5 or greater

    $~: php --ri redis

    If it’s not enabled, try putting it in CLI instead:

    $~: sudo echo 'extension=redis.so' >> /etc/php/7.0/cli/php.ini
  15. ENABLE THE EXTENSION AND RESTART APACHE
    $~: sudo phpenmod redis && sudo service apache2 restart && php --ri redis
  16. SET THE CONFIG PARAMTERERS TO Nextcloud
    $~: sudo nano /var/www/nextcloud/config/config.php
  17. ADD THIS
    'memcache.local' => '\\OC\\Memcache\\Redis',
    'filelocking.enabled' => 'true',
    'memcache.distributed' => '\\OC\\Memcache\\Redis',
    'memcache.locking' => '\\OC\\Memcache\\Redis',
    'redis' =>
    array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0,
    'dbindex' => 0,
    ),

    That should be all. Please login to your Nextcloud and check the admin page for setup errors, or if everything looks fine.



PRO TIP

Install Redis on PHP 7. Wget this script and run it with bash.

Check out the Redis performance tips.

Make daily backups of your system, grab the Rsync backup script.