Owncloud supports several different types of “cache” mechanisms for increasing application performance and, in one particular case, expanding functionality (enabling File Locking).
The two types of caches I am going to discuss today are Redis and APCU. We will start with APCU.
If you have a stand-alone Owncloud installation and just need to optimize for better performance, then APCU is the way to go. It is very simple to get setup, with one small caveat on Ubuntu 14.04 (if you are running the latest LTS distro then this is where you live…).
The PHP5-APCU module is “out of date” relative to what owncloud will accept. So if you just install it with apt and then enable it in your owncloud config file you will get error messages in you logs at best or a more likely just a blank screen when you try to load your site.
So… here is a quick answer on how to fix this issue:
UPDATE 10/14/2015 – none of the official repo’s seems to have the PHP5-APCU package that was needed anymore. So I have uploaded the copy I had here and updated the command given below to reflect the new file location. I have a truly unlimited pipe with my hosting provider so I don’t mind. You are welcome 🙂
##Check the version
dpkg -s php5-apcu
##Uninstall the current version
apt-get remove php5-apcu
##install the correct working version
dpkg -i php5-apcu_4.0.6-1_amd64.deb
There is also another small item you need to update with your PHP configuration… Do the following:
echo 'apc.enable_cli = 1' > /etc/php5/mods-available/apcu-cli.ini
service apache2 restart
After all of the above, the last thing you need to do to get your APCu cache working is add the following line inside of your owncloud config file (this needs to be added before the last “);” at the bottom of the file):
## First backup your config
cp /var/www/owncloud/config/config.php /var/www/owncloud/config/config.php.bak
## Open up your file for modding with your preferred editor (I like vim)
## Finally, add this line somewhere in your config.
'memcache.local' => '\\OC\\Memcache\\APCu',
When you login to owncloud with an admin account and look at the configuration page, you should no longer see a warning about not having a cache configured. If so, you are good to go!
Redis Cache and File Locking
Owncloud 8+ came out with a new method of file locking that is dependent up on using a different cache called “Redis cache”.
The long and short of file-locking is that in a shared file system like Owncloud, by design, you can have multiple agents (people, systems, etc.) working on the same file. What happens if two individuals working on a shared file try to save changes at the same time? Problems… that’s what happens.
In most shared file systems, the back-end will just version the file and whoever presses “save” last will generate the version that is considered current. This at least keeps changes made by both actors but often leads to a lot of confusion. Owncloud however supports “file locking” – which means if Bob in accounting has an excel spreadsheet open and is working on it, no one else can make changes to that file.
So you have Owncloud 8+ deployed on Ubuntu 14.04, and after reading my stunning description you really want file-locking… That means you need to drop using APCu for your cache mechanism and you need to instead use Redis cache. Great…
Here’s the rub… Ubuntu 14.04 is using an older version of the PHP5-Redis module. This is the module that lets PHP make use of the Redis cache system. So if you install the PHP5-Redis module directly from the repository and try to use it with owncloud, things will break because the folks that coded Owncloud require a minimum version of the PHP5-redis module that you can’t get from the repository.
How do we work around this? Similar to what we did with the APCu module up top, we need to remove our currently installed PHP5-redis package first. (if you haven’t already installed the PHP5-redis module you can skip this step).
Okay, now, you should have installed the redis-server already. If not:
Grand, so now you should have redis-server installed, but not php5-redis module. Unlike APCu, there is no nice, neat, easy to install php module installer available. No deb package that will work.
UPDATE 09.07.2015 – Thanks to one of our kind commentators, Toni, there is an easier way to get a more updated version of the PHP extension need for interfacing with Redis Cache. My prior method of compiling is still shown here but I am also including a preferred option using PECL/PEAR PHP extension repository.
OPTION #1 for installing the PHP Redis Extension – PREFERRED – Use PECL:
pecl install redis
#### END OPTION #1 ####
OPTION #2 for installing the PHP Redis Extension – (skip this if you used Option #1 above) – Compile from Source:
So, we have to build from source. This might sound a bit scary but no worries we will get there.
wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip
Okay, if you ran all of the above commands, you should be in your root’s home folder, you should have downloaded the source code for the redis module as the phpredis.zip file. Finally, you should have unpacked that zip file in your home folder and the ls -la command should have given you a listing of all files and folders in your home root directory. You should see a new folder called something like phpredis-phpredis-XXXX… something along those lines. It might look very different depending on what is on github at the time you download. You need to go into that directory and compile the php redis module. So in my case, my directory name was phpredis-phpredis-fc673f5, so I proceeded as follows:
make && make install
That compiles it for your system.
#### END OPTION #2 ####
Now… we need to make sure the module is installed with php. I am running PHP 5.5 so for me it looked like this:
Is there already a redis.ini file in here? If so, then see what the contents of it are like this:
## The server response should show this next line, if so, you are good
If there is NO redis.ini folder in this directory, then you need to create one and put that information in there. Like so:
echo 'extension=redis.so' > /etc/php5/mods-available/redis.ini
Okay, finally you need to load the module..
service apache2 restart
As long as that command runs you should now have all of the redis components you need installed and working. If you want to double check the module version for redis, run the following:
Your version should be 2.2.7 or greater.
You may want to go ahead and manually start the Redis server in case it didn’t fire off on its own:
## Press ctrl-c to exit, the server should continue running
Okay, the last step to getting Redis up and running for Owncloud is modifying your owncloud configuration. Assuming you didn’t do anything funky with your Redis server install, then the following lines should work in your config file:
'filelocking.enabled' => 'true',
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'host' => 'localhost',
'port' => 6379,
'timeout' => 0,
'dbindex' => 0,
Now when you get into Owncloud and look in the Admin configuration page, you should scroll down and see:
Transactional File Locking is enabled.
If you are getting that message you are good to go!
If you get a blank white page when you try to visit your owncloud site, something is misconfigured or not running properly with the cache system. In which case you can revert back in your Owncloud config to use APCu (or no cache at all) until you figure it out.
Hope this is helpful for everyone trying to run Owncloud on Ubuntu 14.04 LTS!