Introduction
A PHP memory caching utility such as Redis can significantly decrease load times, speeding up PHP requests by storing compiled files for quicker retrieval.
Install Redis
Both the Redis database and PHP interfacing extension need to be installed:
# pkg_add redis pecl-redis
Add to rc.d
to run at startup and then start Redis:
# rcctl enable redis # rcctl start redis
Redis and Nextcloud Configuration
First, make the directory with appropriate ownership and permissions in the chroot where Redis will create the unix socket file:
# mkdir /var/www/redis # chown -R www:www /var/www/redis # chmod 0775 /var/www/redis
Determine the GID of the web server user by either looking at the group file
or using id
:
# cat /etc/group wheel:*:0:root <snip> www:*:67: # id -g www 67
Now add user _redis
to the www
group by either calling usermod
or using
chpass
to replace the existing GID of user _redis
with 67
:
# usermod -g www _redis # chpass _redis
Confirm user _redis
has been added to www
group:
# id -Gn _redis www
Open /etc/redis.conf
and switch communication from TCP to unix socket
connection with the following changes:
port 0 unixsocket /var/www/redis/redis.sock unixsocketperm 770 logfile "redis.log"
Ensure you point Redis to the unix socket file at its absolute path because,
unlike httpd
, it's not operating within the chroot.
Now edit Nextcloud configuration to make use of the Redis caching database by
opening /var/www/nexctloud/config/config.php
in your favourite editor and
appending the following to the bottom before the closing );
:
'memcache.local' => '\OC\Memcache\Redis', 'memcache.locking' => '\OC\Memcache\Redis', 'redis' => array( 'host' => '/redis/redis.sock', 'port' => 0, 'timeout' => 1.5, ),
Make sure you point Nextcloud to the unix socket file at its relative location within the chroot.
Deployment
Restart Redis and all associated daemons:
# rcctl restart redis php56_fpm httpd
Check that the Redis process is running:
# ps -aux |grep redis _redis 89954 0.0 0.2 13772 2204 ?? Ss 10:21PM 0:00.47 redis-server: /usr/local/sbin/redis-server 127.0.0.1:0 (redis-server)
And you can view redis.log
to check for any problems:
# cat /var/redis/redis.log 86204:C 07 Mar 22:21:12.562 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 86204:C 07 Mar 22:21:12.563 # Redis version=4.0.2, bits=32, commit=00000000, modified=0, pid=86204, just started 86204:C 07 Mar 22:21:12.564 # Configuration loaded 89954:M 07 Mar 22:21:12.601 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now. _._ _.-=__ ''-._ _.-= `. `_. ''-._ Redis 4.0.2 (00000000/0) 32 bit .-= .-=`. =`\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.=-._|'` _.-'| Port: 0 | `-._ `._ / _.-' | PID: 89954 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 89954:M 07 Mar 22:21:12.608 # Server initialized 89954:M 07 Mar 22:21:12.609 * DB loaded from disk: 0.000 seconds 89954:M 07 Mar 22:21:12.609 * The server is now ready to accept connections at /var/www/redis/redis.sock