Redis on Shared Hosting: Setup Guide
This guide walks you through using Redis with typical web hosting, covering shared, VPS, and dedicated plans. You’ll learn how to check if Redis is available, install or enable it, configure your application to connect, and handle common issues—so you can start caching data and speeding up your site.
What You’ll Need
- A web hosting account (shared, VPS, or dedicated) with SSH or a control panel like cPanel, Plesk, or DirectAdmin.
- Access to your hosting’s documentation or support (to know what’s available).
- Basic knowledge of your application’s configuration files (e.g., wp-config.php for WordPress, .env for Laravel).
- If your app uses a framework, know its Redis configuration method (e.g., Laravel’s config/database.php, Django’s CACHES setting).
Step-by-Step
- Check if Redis is already installed. Log into your hosting control panel and look for Redis in the software list, or run
redis-cli pingin SSH. If you getPONG, it’s installed. If not, proceed to step 2. - Enable Redis through your control panel. In cPanel, look for “Redis” under the “Software” or “Services” section. In Plesk, go to “Extensions” and search for Redis. If you see it, enable it. Some hosts auto-start Redis for you; others require you to start it manually.
- If not available, install Redis manually (VPS/dedicated). SSH into your server and run the package manager commands: on Ubuntu/Debian:
sudo apt update && sudo apt install redis-server. On CentOS/RHEL:sudo yum install redis. Then start the service:sudo systemctl start redisand enable it on boot:sudo systemctl enable redis. - For shared hosting without SSH, contact support. Many shared hosts offer Redis as a paid add-on or via a “Redis” icon in the control panel. If it’s not there, ask support to install it or enable it for your account. Some hosts provide a separate Redis server address (hostname and port) that you’ll use in your app.
- Find your Redis connection details. Typically, Redis runs on
localhost(127.0.0.1) with port6379. If your host gives you a remote host, note that. Also note if a password is required (often in a file likeredis.confor provided by the host). - Configure your application to use Redis. This varies by app. For WordPress, install a caching plugin like Redis Object Cache, then go to its settings and enter the host, port, and password. For Laravel, edit
config/database.phpand set theredisconnection details, then setCACHE_DRIVER=redisin your.envfile. For Django, add a cache configuration insettings.pyusing thedjango-redislibrary. - Test the connection. Use a simple command-line test:
redis-cli -h host -p port -a password ping(omit-aif no password). If you getPONG, it works. Alternatively, check your app’s status page or run a simple script that sets and gets a key. - Restart your web server or application. After changing configuration, restart Apache/Nginx or your PHP-FPM service to pick up the changes. In cPanel, you can use “Restart PHP” or “Restart Services”. On VPS, use
sudo systemctl restart apache2(or nginx). - Monitor Redis usage. Use
redis-cli INFOto see memory usage, connected clients, and hits/misses. Your control panel may also show Redis stats. This helps you adjust cache expiration times and memory limits.
Common Mistakes
- Assuming Redis is on localhost. On some managed hosts, Redis runs on a separate server or a non-default port. Always check your hosting documentation.
- Forgetting the password. Many hosts require a password. If you omit it, you’ll get an authentication error.
- Using the wrong port. Default is 6379, but some hosts use a different port to avoid conflicts.
- Not updating the application cache driver. Just installing Redis isn’t enough; you must tell your app to use it. Forgetting to set the cache driver to Redis means your app still uses file or database caching.
- Ignoring firewall rules. If you’re on a VPS and Redis is remote, ensure your firewall allows incoming connections on the Redis port from your web server’s IP.
Tips
- Use a Redis plugin/library. For WordPress, use the Redis Object Cache plugin. For Laravel, use the built-in Redis support. These handle connection details and caching logic for you.
- Set appropriate expiration times. Don’t cache data forever. Use TTL (time-to-live) for dynamic content. For example, cache a list of recent posts for 5 minutes, not a day.
- Monitor memory usage. Redis stores data in RAM. If you have limited memory, set maxmemory and a policy like
allkeys-lruto evict old keys. - Use Redis for sessions too. Many apps can store PHP sessions in Redis, which helps with load balancing across multiple servers.
- Keep Redis updated. If you manage it yourself, run
sudo apt upgrade redis-serverregularly to get security fixes.
Troubleshooting
Connection refused: Check if Redis is running: redis-cli ping. If not, start it: sudo systemctl start redis. If it’s running but you can’t connect, check the port and host. On some hosts, Redis listens only on 127.0.0.1, so connecting from an external IP fails.
Authentication error: You need a password. Look for requirepass in redis.conf or ask your host. Add the password to your app’s configuration.
Out of memory: Redis will start evicting keys or refuse writes. Check maxmemory in redis.conf and set a policy. Also consider reducing cache TTLs.
Slow performance: If Redis is slow, check for large keys or many keys. Use redis-cli --bigkeys to find them. Also ensure you’re using persistent connections in your app (e.g., persistent option in Laravel).
Changes not taking effect: After changing config, restart Redis and your web server. Also clear your application’s cache (e.g., php artisan cache:clear).
Frequently Asked Questions
Can I use Redis on shared hosting?
Yes, many shared hosts now offer Redis as an add-on. Check your control panel or contact support. If not available, consider upgrading to a VPS.
How do I know if my host has Redis?
Look for Redis in cPanel’s “Software” section, or run redis-cli ping in SSH. If you don’t have SSH, ask support.
What is the default Redis port?
The default is 6379, but your host may use a different one. Always check your hosting documentation.
Do I need to install a PHP extension for Redis?
Yes, your PHP needs the redis extension. Many hosts have it pre-installed. If not, you may need to enable it in your control panel or install it (VPS).
Is Redis faster than MySQL for caching?
Generally yes, because Redis stores data in memory, while MySQL is disk-based. For frequent read/write operations, Redis is much faster.
Can I use Redis for sessions?
Yes, you can store PHP sessions in Redis, which is useful for scaling across multiple servers. Configure session.save_handler = redis in php.ini.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.