With the new transactional file locking in place, we felt it was time to get rid of APCu and replace our cache with Redis instead. APCu is kind of old, and from our understanding, it doesn’t work well with the new ownCloud locking system. Redis cache is the preffered way to go. But if you install Redis via the standard Ubuntu Repos, you will get a very outdated version – 2.2.4. The recomended version for ownCloud is at least 2.2.5, and in this guide we will install Redis Server 3.0.5, and phpmodule 2.2.7. So bye bye APCu, hello Redis!

As we didn’t find any good “how-to” on installing it in Ubuntu Server 14.04, here is a guide for you to follow, so that you can get the advantages of Redis as well. Let’s begin.

This guide is also scripted for an automated install, you can download the script here (updated to PHP 7).

Hey, check out our new guide on how to install Redis with PHP 7.

  1. Get rid of APCu & Memcached
    $~: 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
    $~: wget http://download.redis.io/releases/redis-stable.tar.gz && 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 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

    $~: redis-server -v

    Now we need to install the phpmodule to get it working with ownCloud

  7. Install needed dependencies
    $~: sudo apt-get install php-pear php5-dev
  8. Install the phpmodule for Redis with pecl
    $~: sudo pecl install -Z redis
  9. Create the redis.ini extension
    $~: sudo touch /etc/php5/mods-available/redis.ini
    $~: sudo echo 'extension=redis.so' > /etc/php5/mods-available/redis.ini
  10. Enable the module and restart apache
    $~: sudo php5enmod redis && service apache2 restart
  11. Test your module version

    It should be 2.2.7 or greater

    $~: php --ri redis
  12. Set the config paramterers to ownCloud
    $~: sudo nano /var/www/owncloud/config/config.php
  13. 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 ownCloud 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.

Update your ownCloud instance with a script instead. Easy and configurable. Download it here.

Check out the Redis performance tips.

Easier administration of your SSH keys in Linux, check it out!