![]() |
VOOZH | about |
Redis is an open source key-value cache and storage system, also referred to as a data structure server for its advanced support for several data types, such as hashes, lists, sets, and bitmaps, amongst others. It also supports clustering, which makes it often used for highly-available and scalable environments.
In this tutorial, weβll see how to install and configure an external Redis server to be used as a session handler for a PHP application running on Ubuntu 14.04.
The session handler is responsible for storing and retrieving data saved into sessions - by default, PHP uses files for that. An external session handler can be used for creating scalable PHP environments behind a load balancer, where all application nodes will connect to a central server to share session information.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Dev/Ops passionate about open source, PHP, and Linux. Former Senior Technical Writer at DigitalOcean. Areas of expertise include LAMP Stack, Ubuntu, Debian 11, Linux, Ansible, and more.
Current fan and former Editorial Manager at DigitalOcean. Hi! Expertise in areas including Ubuntu, Docker, Rails, and more.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Can I firstly say, great how-to!
Secondly, more of a comment on the PPA. Did you know ubuntu-14.04 has redis-server bundled and can support everything you do in the tutorial with sudo apt-get install redis-server from vanilla 14.04?
I know itβs probably not the latest stable, but sometimes distro-maintained is a good thing. Unless there is a CVE the new stable release fixes, and most of the time distro-maintained will backport security patches.
Anyway, my comment is largely irrelevant, I just wondered if you knew, and wanted to say well done on the tutorial.
Does anyone have experience or data as to how this performs vs memcached or standard session handling?
β¦Will this create any conflict if i have Memcached installed?
Great how to! Easy to follow for a novice. Would love to see a how to for getting a php page to make redis set/get calls! I am not having much luck following whatβs out on the web.
Thanks, Jason
So in a server environment with a web server and a database server, where would you advise Redis to be installed for best performance?
Also in this tutorial is redis performing object-caching?
Thanks, JL
FYI:
I had used apg to generate a 72 character-long password for my Redis Server and found that tcp:// requests were failing. The password string contained several non-alphanumeric (ie special) characters.
Solved by:
Encode the string before sending to a port. I had success with:
If you are using PHP 7.0 FPM, whether you are using Nginx or Apache, if you realise the instructions above doesnβt work for you, and redis-cli doesnβt show your saved session.
you should go to the following file
/etc/php/7.0/mods-available/redis.ini
and add the following lines
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?auth=supercomplexpasswordthatyousetbefore"
save and exit, and restart php fpm
sudo service php7.0-fpm restart
Your session should now show when you type keys *
Iβm using Ubuntu 16.04
Hi,
Can anyone help me with the setup of multi master node redis setup?
How do you handle cleaning up expired sessions using this method? Will allkeys-lru maxmemory-policy work, or does an explicit expiration need to be set?
@erikaheidi Hey Erika! Thanks for this much!
I am trying to setup redis in an environment, where I need wordpress to connect securely to a VPS (Digital Ocean droplet) hosting a redis server.
I have managed this:
Webserver - > SSH RSA PK AUTH - > Redis VPS
Now I need this:
Authenticated Web Server - > Redis Instance - > Object Cache - > Session Handling - > DB store
Is that doable?
All default TCP connections are blocked on the droplet Only SSH via RSA is allowed on the droplet
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.