Redis and Pasword in NCP Config
So I have a Redis server up and running in my stack - and wanted to implement it within NCP. Got the NCP config set up and it was working, until i rebooted NCP just for S&G. NCP hashed the password in the config file, causing Redis to not do it's thing within NCP, which then caused an internal server error and I couldn't access my NCP!
The fix? A silly script to run each time the LXC restarts and update the password in the NCP config file, duh! Here is what I did
Create the Script
I am keeping the script in this directory: /usr/local/bin/
nano /usr/local/bin/ncp-fix-redis.sh
#!/bin/bash
CONFIG_FILE="/var/www/nextcloud/config/config.php"
REDIS_PASS="YourRedisPassword"
if [ -f "$CONFIG_FILE" ]; then
echo "🔧 Fixing Redis password in $CONFIG_FILE..."
sed -i "s/'password' => '.*'/'password' => '$REDIS_PASS'/g" "$CONFIG_FILE"
echo "✅ Redis password updated."
else
echo "❌ $CONFIG_FILE not found!"
fi
chmod +x /usr/local/bin/ncp-fix-redis.sh
Create The Systemd Service
nano /etc/systemd/system/ncp-redis-fix.service
[Unit]
Description=Fix Redis password in Nextcloud config after boot
After=network.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c "sleep 30 && /usr/local/bin/ncp-fix-redis.sh"
[Install]
WantedBy=multi-user.target
Enable The Service
systemctl daemon-reexec
systemctl daemon-reload
systemctl enable ncp-redis-fix
Test Without Reboot
Edit your NCP config by changing the password for Redis to something wrong, then:
systemctl start ncp-redis-fix
You should see something like this:
🔧 Fixing Redis password in /var/www/nextcloud/config/config.php...
✅ Redis password updated.