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 🙂
Direct Downloads:
php5-apcu_4.0.6-1_amd64
php5-redis_2.2.5-1build1_amd64
##Check the version
dpkg -s php5-apcu
##Uninstall the current version
php5dismod apcu
apt-get remove php5-apcu
##install the correct working version
cd ~
wget http://www.kiloroot.com/wp-content/uploads/2015/08/php5-apcu_4.0.6-1_amd64.deb
dpkg -i php5-apcu_4.0.6-1_amd64.deb
php5enmod apcu
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
php5enmod apcu-cli
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)
vim /var/www/owncloud/config/config.php
## 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.
sudo -i
cd ~
wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip
unzip phpredis.zip
ls -la
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:
phpize
./configure
make && make install
make test
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:
ls -la
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
extension=redis.so
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',
'redis' =>
array (
'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:
Server Status
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!
References:
https://github.com/owncloud/core/issues/14386
https://github.com/owncloud/core/issues/17562
http://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html
https://doc.owncloud.org/server/8.1/admin_manual/configuration_files/files_locking_transactional.html
https://owncloud.org/blog/making-owncloud-faster-through-caching/
I think I might have hit a nerve with this article as it hit 3.4% of my total site traffic the day after it was posted. Honestly, Owncloud probably needs to shore up some of its documentation in this area (cache/ubuntu combo) and we really need more folks in the OC community talking about Ubuntu Server and OC integration generally.
I followed the instructions but still got a blank page on load. Any ideas?
Did not restart php5-fpm. After that it works correctly.
Did you get the notice that file locking was enabled or are you just using APCu and not Redis?
You do not need to compile this module from scratch. “sudo pecl install redis” would be sufficient.
I didn’t consider using PECL. Good call. So PECL will install a newer version of the plugin then what apt-get will?
Yes it will install version 2.2.7. See here: https://pecl.php.net/package/redis
Awesome. Thank you for this tip. It just didn’t occur to me to even use PECL and that is much less work than compiling although whenever I compile something I feel a bit cooler for some reason :).
For anyone else reading this thread, before you can use PECL you might need to install a few other things:
sudo apt-get install php-pear php5-dev
That should allow you to then use PECL to install extensions for PHP which is probably the better route to go as I -think- you can also more easily update the extensions as well. I might be mis-speaking here but I believe PECL and/or PEAR are both like an app repository/package manager for PHP extensions.
I have updated the article to include the option of using PECL instead of compiling. Thank you again!
Many thanks. There is one minor typo:
‘php5enmod apcu-cli’ should read ‘php5enmod apcu-cli2’
Other than than, it worked like a charm.
I followed the commands for the APCu install. When I reached the php5enmod apcu-cli command I received the following error:
WARNING: Module apcu-cli ini file doesn’t exist under /etc/php5/mods-available
I thought since it is just a warning it may have still configured everything. After completing the steps I still receive the error on my owncloud admin page. I am a bit new to this whole process and linux in general so I apologize if I am missing something obvious. Does anyone have an idea what steps I need to do to finish this configuration? Everything else worked fine.
Funnily enough, Dave may have answered you question before I got to you and I just happened to approve both comments at the same time. I will update the article with a note. I honestly can’t remember if I had to include a “2” or not. I am fairly certain I didn’t but it has been a few weeks gone now so it can’t hurt to add a note to the article. Thanks for the heads up and Thomas, tell me if Dave’s suggestion helps.
Dave and Thomas, I see my mistake now. I must have accidentally punched a “2” into the name of the .ini file. ph5enmod works off of the file names of the .ini files. So by adding a “2” to the file name I would have also had to add a “2” to the command to enable the mod. I have updated the post to fix this by taking the “2” out of the file name.
Kind regards,
Nathan
Really nice post and easy to follow and works!
But instead:
echo ‘apc.enable_cli = 1’ > /etc/php5/mods-available/apcu-cli2.ini
Should be:
echo ‘apc.enable_cli = 1’ > /etc/php5/mods-available/apcu-cli.ini
Thanks for the good guide
Thanks, thought I caught all of them before… guess not. Good eye. I fixed the article.
Cheers,
Nathan
php5-apcu_4.0.6-1_amd64.deb no longer exists at that location for wget. Getting 404 File not found I think. 4.0.7 which is there doesn’t work. Any other places to get 4.0.6?
Thank you for pointing this out! I am sure you just saved a lot of other people some major headaches. Sure enough I did some google-fu and looked for the file and it can’t be found in any of the official repo’s anymore. Luckily I had a copy sitting on one of my servers so I uploaded it here for easy downloading with WGET and I also updated the commands given. See the update in the article above!
Cheers!
Nathan
You are a lifesaver. I spent probably 7 hours trying to get 4.0.7 to work with Owncloud yesterday and today with no success and 4.0.6 loaded right up with no problem only a few days ago. So frustrating.
Thanks for the article, it was very useful. I’ve activated the Redis cache and Transactional File Locking but for some reason, it doesn’t behave as expected: “if Bob in accounting has an excel spreadsheet open and is working on it, no one else can make changes to that file”.
It’s still the same as before: two people can open the same shared file, whoever writes last wins. Anyone else experiencing this?
Made my month man, thanks!
Thank you so much, it worked for me!
This helped a lot! Thanks!
Thanks for the guide.
I am having an issue installing apcu
there is a dependency called phpapi-2013….. I can not find anywhere 🙁
any help you can provide?
at this time I am using apcu version 4.0.10
thanks
From the apcu-version you use I asume that you are running a pre-release of 16.04 see here:
http://packages.ubuntu.com/xenial/php5-apcu
If you use an older version of ubuntu you cannot just install a newer php5-apcu package since the dependencies aren’t met.
phpapi-20131226 got shipped since 14.10.
Thank you for your answer and help
What I am understanding I need to get at least 14.10 installed, is that right?
Any easy way to move from 14.04 LTS to 14.10?
have a good one
I was (am) on 14.04 LTS when I wrote this, I do know that. I also know I ended up just using Redis caching as I wanted file-locking. That being said, I have a second server running 14.04 I can try to re-run my walkthrough on and see if I run into any issues. I remember getting APCU working was the much easier of the two items but beyond that my details are a bit sketchy so I apologize 🙂
Kind regards,
Wait for 16.04 which will be the next LTS. 14.10 has reached EOL since July’15
I am actually using 14.04 LTS on all of my servers. It has been a few weeks/months since I wrote this but I don’t remember running into a dependency issue. Looking forward to the next LTS release all the same 🙂
I am running the Redis caching, and followed what I believe to be is all of the documentation here, but I still seem to have an issue.
Please e-mail me for more info.
I don’t know if I found a solution, or just something I missed, but I needed what was on this page.
http://redis4you.com/articles.php?id=001&name=Redis+as+session+handler+in+PHP
Also, I am running 8.2.2 and I cannot see that transactional file locking is active?
I did the steps as above without any warnings/ issues. I’m running 1404LTS and OC.8.2.2. I however still get at the admin console like no cache configured niether do I see the redit file lock mentioned. Any hints?
I’m running Ubuntu 14.04 and instead of downloading apcu 4.0.6, I used 4.0.7 from the trusty-backports repo. With the trusty-backports repo enabled:
sudo apt-get install php5-apcu/trusty-backports
Everything else was the same.
Awesome tutorial. Thank you, nbeam!
Glad it has been helpful! Thanks for adding to the conversation and lending a hand to other folks needing the same info!
The owncloud ‘Server Status’ has been removed on 8.2.x and there are no positive indication on the status of redis.
That’s annoying… I will check on my setup, I just updated to a newer version a few weeks ago.
work very well with OC and Apcu 4.07 Lubuntu 1404.3. What a “frickelkram”
Frickelram?? No idea…
“Frickelkram” is Complicated in German
Ohhhh, you must have 3Gb of Memory for Redis-Cache.On my other Machine redis went away and Owncloud flicker wild.
You can limit the Redis Cache, add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and reboot
Thanks it work on ubuntu server 14.04 lts 64 bits with owncloud 9.01
Pingback: Einen eigenen Homeserver mit Debian einrichten | datdiy