{"id":15933,"date":"2019-03-13T09:22:01","date_gmt":"2019-03-13T09:22:01","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15933"},"modified":"2026-03-10T09:37:11","modified_gmt":"2026-03-10T09:37:11","slug":"how-to-install-and-setup-redis-on-ubuntu","status":"publish","type":"post","link":"\/ph\/tutorials\/how-to-install-and-setup-redis-on-ubuntu\/","title":{"rendered":"How to Install, Configure, and Secure Redis on Ubuntu"},"content":{"rendered":"<p>Redis is an in-memory database used to store data temporarily as a cache to reduce server load and improve application performance. It is also a message broker that facilitates data flow between services.<\/p><p>Setting up Redis can be tricky since it has various commands and configuration parameters. Moreover, this software provides several utilities that can be dangerous if you are not careful.<\/p><p>To help you get through this process safely, this article will explain how to install Redis on Ubuntu. We will also explain how to properly secure and maintain this software so you can use it safely on your virtual private server (VPS).<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"1024\" height=\"283\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet-1024x283.png\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2022\/11\/Linux-cheat-sheet-1536x425.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2022\/11\/Linux-cheat-sheet-300x83.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2022\/11\/Linux-cheat-sheet-150x41.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2022\/11\/Linux-cheat-sheet-768x212.png 768w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2022\/11\/Linux-cheat-sheet.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-prerequisites-for-installing-redis\">Prerequisites For Installing Redis<\/h2><p>Before installing Redis, ensure you have a VPS running Ubuntu since the steps differ for other Linux operating systems. Also, we recommend using Ubuntu 22.04<strong> <\/strong>or later since the older versions might use different commands.<\/p><p>Your VPS must meet the Redis system requirements to ensure optimal performance. Moreover, your local computer must have the <a href=\"\/ph\/tutorials\/how-to-use-putty-ssh\">PuTTY secure shell<\/a> (SSH) client installed since we will use it to connect to the server. Alternatively, Linux and MacOS users can use Terminal.<\/p><p>If you haven&rsquo;t purchased a plan, we recommend looking into <a href=\"\/ph\/vps\/redis-hosting\">Hostinger&rsquo;s Redis VPS plans<\/a>. Users can connect to our servers via SSH or through the built-in <strong>Browser terminal<\/strong> to simplify the installation process.<\/p><p>In addition, our plans have different hardware resource allocations to cater to various needs. You can easily upgrade anytime to up to<strong> KVM 8<\/strong>, which offers powerful <strong>8 vCPU<\/strong> cores and<strong> 32 GB<\/strong> of RAM.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/ph\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-install-redis-on-a-ubuntu-vps\">How To Install Redis On A Ubuntu VPS<\/h2><p>After uncovering the prerequisites, let&rsquo;s dive into the steps to install Redis on an Ubuntu VPS. Before proceeding, connect to your server using an SSH client like PuTTY or Hostinger&rsquo;s <strong>Browser terminal<\/strong>.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1583232-how-to-back-up-or-restore-a-vps-server\" target=\"_blank\" rel=\"noopener\">Back up your VPS data<\/a> before proceeding to simplify file restoration in case of errors or misconfigurations.<\/p><\/div>\n\n\n\n<\/p><h3 class=\"wp-block-heading\" id=\"h-1-install-redis-server\">1. Install Redis Server<\/h3><p>Since the SSH connection uses <strong>root <\/strong>by default, create and switch to a new superuser before installing Redis. Since this account asks for confirmation before running utilities, doing so will help to minimize the risk of accidental command executions that might cause issues.<\/p><p>To make a new user in your Ubuntu system, run the following command. Replace <strong>your-username <\/strong>with your desired account name:<\/p><pre class=\"wp-block-preformatted\">adduser your-username<\/pre><p>Enter the user&rsquo;s password and other details. Now, grant the account <strong>sudo<\/strong> privileges to run administrative commands:<\/p><pre class=\"wp-block-preformatted\">usermod -a -G sudo your-username<\/pre><p>Then, switch to the new user by entering the following:<\/p><pre class=\"wp-block-preformatted\">su your-username<\/pre><p>Enter <strong>cd<\/strong> to return to the home directory. Now, let&rsquo;s start the Redis installation by updating your system repository to ensure you receive the latest software version:<\/p><pre class=\"wp-block-preformatted\">sudo apt update<\/pre><p>After the update is completed, run the following to install Redis. Press <strong>Y<\/strong> and<strong> Enter<\/strong> if the command-line interface (CLI) asks for confirmation:<\/p><pre class=\"wp-block-preformatted\">sudo apt install redis<\/pre><p>Note there are<strong> redis-server<\/strong> and <strong>redis<\/strong> packages in the Ubuntu repository. Both will install the same software, so you can use either and have the same outcome.<\/p><p>Check the Redis command-line client version by entering the following to ensure it is configured properly:<\/p><pre class=\"wp-block-preformatted\">redis-cli --version<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f08cd5c\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"949\" height=\"48\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/terminal-returns-redis-cli-version-number.png\" alt=\"Terminal returns Redis CLI version number\" class=\"wp-image-109235\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/terminal-returns-redis-cli-version-number.png 949w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/terminal-returns-redis-cli-version-number-300x15.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/terminal-returns-redis-cli-version-number-150x8.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/terminal-returns-redis-cli-version-number-768x39.png 768w\" sizes=\"(max-width: 949px) 100vw, 949px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If the Terminal returns the version number, the caching database is installed correctly. Now, query the Redis service status to ensure it is running and active:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl status redis<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f08d945\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"962\" height=\"274\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/systemctl-shows-redis-service-status.png\" alt=\"Systemctl shows Redis service status\" class=\"wp-image-109236\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/systemctl-shows-redis-service-status.png 962w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/systemctl-shows-redis-service-status-300x85.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/systemctl-shows-redis-service-status-150x43.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/systemctl-shows-redis-service-status-768x219.png 768w\" sizes=\"(max-width: 962px) 100vw, 962px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Alternatively, Hostinger VPS users can also ask <strong>Kodee <\/strong>to confirm the Redis status after installation. Access the feature via your dashboard&rsquo;s left sidebar then type your prompt like the following example:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f08dde0\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/03\/hpanel-vps-kodee-systemctl-redis-1024x334.png\" alt=\"Kodee responds to a question about the Redis status\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you see Redis status as<strong> disabled<\/strong> or<strong> stopped<\/strong>, run the following command to start it manually:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl start redis<\/pre><p>Now, enable the Redis service to start automatically after a system reboot using this command:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl enable redis<\/pre><h3 class=\"wp-block-heading\" id=\"h-2-configure-redis\">2. Configure Redis<\/h3><p>Redis listens to all connections by default, which can present network security risks. To ensure it works properly and securely, you must bind only the necessary IP addresses.<\/p><p>If your web application and Redis are within the same server, bind the localhost&rsquo;s address of <strong>127.0.0.1<\/strong>. If you are using another system to host the application, specify its IP.<\/p><p>To change the default configuration, open the <strong>redis.conf<\/strong> file <a href=\"\/ph\/tutorials\/how-to-install-and-use-nano-text-editor\">using a text editor like nano<\/a>. Here&rsquo;s the command:<\/p><pre class=\"wp-block-preformatted\">sudo nano \/etc\/redis\/redis.conf<\/pre><p>Locate the line containing <strong>bind 127.0.0.1 ::1<\/strong>. You can quickly search the file content by pressing <strong>Ctrl + W<\/strong> and entering the queried phrase.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f08ee20\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"954\" height=\"118\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/the-ip-bind-setting-in-the-redis-configuration-file.png\" alt=\"The IP bind setting in the Redis configuration file\" class=\"wp-image-109237\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/the-ip-bind-setting-in-the-redis-configuration-file.png 954w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/the-ip-bind-setting-in-the-redis-configuration-file-300x37.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/the-ip-bind-setting-in-the-redis-configuration-file-150x19.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/the-ip-bind-setting-in-the-redis-configuration-file-768x95.png 768w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Change the network configuration based on your needs. If you need Redis to connect to multiple interfaces, list their IP addresses separated by space like the following:<\/p><pre class=\"wp-block-preformatted\">bind 127.0.0.1 185.185.185.185 185.185.185.186<\/pre><p>Ensure you removed the hash symbol (<strong>#<\/strong>) at the beginning of the line. Otherwise, the configuration won&rsquo;t apply, and Redis will remain listening to all IPs.<\/p><p><div><p class=\"important\"><strong>Important!<\/strong> Don&rsquo;t delete the localhost address in the bind settings since it&rsquo;s essential for testing.<\/p><\/div>\n\n\n\n<\/p><p>In addition to optimizing network security, safeguard the Redis client by setting up password authentication. To do so, look for the<strong> requirepass<\/strong> directive under the <strong>SECURITY <\/strong>section of the <strong>redis.conf <\/strong>file.<\/p><p>Remove the hash symbol to enable the directive and replace the default value with a strong passphrase like so:<\/p><pre class=\"wp-block-preformatted\">requirepass your-password<\/pre><p>Once finished, press<strong> Ctrl + X<\/strong>, <strong>Y<\/strong>, and <strong>Enter<\/strong> to save the settings. Then, restart the Redis service to apply the new changes using this command:<\/p><pre class=\"wp-block-preformatted\">sudo systemctl restart redis<\/pre><h3 class=\"wp-block-heading\" id=\"h-3-check-redis-functionality\">3. Check Redis Functionality<\/h3><p>After configuring Redis, check the database connection to ensure it works correctly based on your settings. To do so, enter the Redis CLl using the following:<\/p><pre class=\"wp-block-preformatted\">redis-cli<\/pre><p>Now, let&rsquo;s check whether the password authentication works using the <strong>auth<\/strong> command. Replace<strong> your-secure-password<\/strong> with the actual value specified in the Redis configuration file:<\/p><pre class=\"wp-block-preformatted\">auth your-secure-password<\/pre><p>Redis CLI should return an <strong>OK<\/strong> confirmation message, meaning you can now run commands in the database. To start, test connectivity by sending data using the <strong>ping<\/strong> command:<\/p><pre class=\"wp-block-preformatted\">ping<\/pre><p>It should return the <strong>PONG<\/strong> message. Otherwise, open the Redis configuration file and ensure you bind the localhost&rsquo;s address of <strong>127.0.0.1<\/strong>.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f08fbc9\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"928\" height=\"51\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/redis-returns-a-ping-packet-to-confirm-connectivity-1.png\" alt=\"Redis returns a ping packet to confirm connectivity\" class=\"wp-image-109241\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-ping-packet-to-confirm-connectivity-1.png 928w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-ping-packet-to-confirm-connectivity-1-300x16.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-ping-packet-to-confirm-connectivity-1-150x8.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-ping-packet-to-confirm-connectivity-1-768x42.png 768w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Next, check if Redis caching is functioning correctly by sending a test message and retrieving it. To do so, enter the following commands subsequently:<\/p><pre class=\"wp-block-preformatted\">set test \"Redis is working\"<\/pre><pre class=\"wp-block-preformatted\">get test<\/pre><p>Redis should return the message you specified in the first command, which is &ldquo;Redis is working.&rdquo;<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f0907d7\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"853\" height=\"92\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/redis-returns-a-test-value-to-confirm-functionality-1.png\" alt=\"Redis returns a test value to confirm functionality\" class=\"wp-image-109242\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-test-value-to-confirm-functionality-1.png 853w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-test-value-to-confirm-functionality-1-300x32.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-test-value-to-confirm-functionality-1-150x16.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-returns-a-test-value-to-confirm-functionality-1-768x83.png 768w\" sizes=\"(max-width: 853px) 100vw, 853px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>While this quick test should be enough to confirm that the database works properly, you can also run other <a href=\"https:\/\/redis.io\/docs\/latest\/commands\/\" target=\"_blank\" rel=\"noopener\">Redis commands<\/a> if needed. After checking the functionalities, quit the shell by entering this:<\/p><pre class=\"wp-block-preformatted\">quit<\/pre><h3 class=\"wp-block-heading\" id=\"h-4-rename-dangerous-commands\">4. Rename Dangerous Commands<\/h3><p>Several Redis commands can manipulate or permanently wipe your database entries. While you might need them for specific tasks, they can be dangerous if unauthorized users gain access to your server.<\/p><p>Since there are many potentially destructive commands, check the <a href=\"https:\/\/redis.io\/docs\/latest\/operate\/oss_and_stack\/management\/security\/acl\/#:~:text=dangerous%20%2D%20Potentially%20dangerous%20commands%20(each,%2C%20SAVE%20%2C%20REPLICAOF%20%2C%20etc.\" target=\"_blank\" rel=\"noopener\">Redis Access Control List documentation<\/a> to learn more about them. Here are some of the common ones and their functions:<\/p><ul class=\"wp-block-list\">\n<li><strong>FLUSHALL<\/strong> &ndash; deletes all keys and data in your entire Redis instance.<\/li>\n\n\n\n<li><strong>FLUSHDB<\/strong> &ndash;&nbsp; wipes data in the current database.&nbsp;<\/li>\n\n\n\n<li><strong>SHUTDOWN<\/strong> &ndash; shuts down the Redis server without saving the data.<\/li>\n\n\n\n<li><strong>DEL<\/strong> &ndash; removes one or multiple keys from your current database.<\/li>\n\n\n\n<li><strong>RENAME<\/strong> &ndash; rename a key in the currently selected database.&nbsp;<\/li>\n\n\n\n<li><strong>SAVE<\/strong> &ndash; saves a dataset to the server&rsquo;s storage while blocking other running processes.&nbsp;<\/li>\n<\/ul><p>To improve Redis security, you can either rename or disable such commands depending on your needs. Start by opening the<strong> redis.conf<\/strong> file using nano:<\/p><pre class=\"wp-block-preformatted\">sudo nano \/etc\/redis\/redis.conf<\/pre><p>Scroll down to the <strong>SECURITY<\/strong> section and add the settings for renaming commands. You can use any name, but we recommend unique, memorable, and difficult-to-guess phrases.<\/p><p>For example, we will rename the <strong>FLUSHALL<\/strong> command to <strong>IWANTTO_FLUSHALL<\/strong> and change <strong>SHUTDOWN<\/strong> into <strong>SHUTDOWN_MYDB<\/strong> by inserting the following lines:<\/p><pre class=\"wp-block-preformatted\">rename-command FLUSHALL IWANTTO_FLUSHALL&nbsp;<br><br>rename-command SHUTDOWN SHUTDOWN_MYDB<\/pre><p>Add more lines with the same syntax to modify other commands. To disable them, simply use empty quotation marks as the new name. For example, this setting will deactivate <strong>FLUSHALL<\/strong>:<\/p><pre class=\"wp-block-preformatted\">rename-command FLUSHALL \"\"<\/pre><p>Save the file and restart Redis to apply the changes. Now, let&rsquo;s check whether you have successfully renamed or deactivated the commands by running them.<\/p><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> For fresh Redis installation, it is okay to check dangerous commands directly since you haven&rsquo;t added any data. However, use a local development environment for future testing since they might cause data loss.    <\/p>\n    \n\n\n\n<\/p><p>To begin, run <strong>redis-cli<\/strong> to access the database shell. Then, enter the renamed commands using their original name. For example, we will check <strong>FLUSHALL<\/strong>:<\/p><pre class=\"wp-block-preformatted\">FLUSHALL<\/pre><p>If the renaming is successful, Redis will return an error message stating the command is unknown like so:<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f0916b8\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"842\" height=\"54\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/05\/redis-shows-a-renamed-command-as-an-error-1.png\" alt=\"Redis shows a renamed command as an error\" class=\"wp-image-109243\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-shows-a-renamed-command-as-an-error-1.png 842w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-shows-a-renamed-command-as-an-error-1-300x19.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-shows-a-renamed-command-as-an-error-1-150x10.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/05\/redis-shows-a-renamed-command-as-an-error-1-768x49.png 768w\" sizes=\"(max-width: 842px) 100vw, 842px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Now run the command using its new name. Redis should return an output or empty string, depending on the command you tested. For example, <strong>FLUSHALL<\/strong> doesn&rsquo;t give any message after it successfully runs.<\/p><h3 class=\"wp-block-heading\" id=\"h-5-maintaining-redis\">5. Maintaining Redis<\/h3><p>After installing Redis, maintain it to ensure optimal performance and security. Here are several practices to consider:<\/p><ul class=\"wp-block-list\">\n<li><strong>Regular backup<\/strong> &ndash; enable your web host&rsquo;s automatic backup feature to create a restore point for your Redis data. Also, regularly create a snapshot of your dataset using Redis&rsquo; <strong>SAVE<\/strong> command.<\/li>\n\n\n\n<li><strong>Server monitoring <\/strong>&ndash; track your Redis server&rsquo;s memory usage, CPU utilization, latency, and other performance metrics to ensure responsiveness. You can use tools like <strong>Prometheus<\/strong> or <strong>Grafana<\/strong>.&nbsp;<\/li>\n\n\n\n<li><strong>Periodical update<\/strong> &ndash; immediately install the new Redis version using the <strong>apt update &amp;&amp; apt upgrade<\/strong> command to apply the latest security and bug fixes.&nbsp;<\/li>\n\n\n\n<li><strong>Security control<\/strong> &ndash; enable password authentication for the Redis CLI, apply a <a href=\"\/ph\/tutorials\/what-is-ssl\">secure sockets layer<\/a> (SSL) certificate, and configure firewall rules to safeguard the database port.&nbsp;<\/li>\n\n\n\n<li><strong>Log files analysis <\/strong>&ndash; check <a href=\"https:\/\/www.geeksforgeeks.org\/where-are-redis-logs-stored\/\" target=\"_blank\" rel=\"noopener\">Redis event logs<\/a> periodically to quickly catch unauthorized actions or changes that might compromise the server&rsquo;s security.<\/li>\n<\/ul><p>Due to various measures, maintaining Redis can be difficult, especially for beginners. If you need help administering your server, use our <a href=\"\/ph\/blog\/vps-ai-assistant\">AI assistant, Kodee<\/a>, to simplify the tasks.<\/p><p>You can generate commands and instructions for server management using simple prompts. For example, ask, &ldquo;Generate a cronjob that runs the SAVE command in Redis every Monday morning to save the dataset.&rdquo;<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e0b8f092139\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1024\" height=\"489\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/10\/cronjob-save-command-generated-by-kodee-1024x489.png\" alt=\"Kodee returns instructions and commands to schedule a Redis task using cronjob\" class=\"wp-image-117120\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-1024x489.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-300x143.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-150x72.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-768x367.png 768w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-1536x734.png 1536w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2024\/10\/cronjob-save-command-generated-by-kodee-2048x979.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Setting up Redis on your VPS helps reduce load and latency to improve your application performance. In this article, we have explained the five steps to install and configure this tool on an Ubuntu system via SSH:<\/p><ol class=\"wp-block-list\">\n<li>Install Redis using the<strong> apt<\/strong> package manager.&nbsp;<\/li>\n\n\n\n<li>Configure Redis&rsquo; connection and password authentication.<\/li>\n\n\n\n<li>Enter the Redis shell and check its commands&rsquo; functionality.<\/li>\n\n\n\n<li>Rename or deactivate dangerous Redis commands.<\/li>\n\n\n\n<li>Maintain Redis by applying practices like regular backup and log auditing.<\/li>\n<\/ol><p>Since Redis is complex, we recommend reading its documentation for more information about its features. Meanwhile, check our other <a href=\"\/ph\/tutorials\/vps\">VPS tutorials<\/a> if you want to learn more about server management.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-install-redis-faq\">How To Install Redis FAQ<\/h2><p>In this section, we will answer several questions about installing Redis on an Ubuntu system.&nbsp;<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1715172643675\"><h3 class=\"schema-faq-question\">What Is Redis Used For?<\/h3> <p class=\"schema-faq-answer\">Redis is an in-memory cache database used to temporarily store your application&rsquo;s data. It reduces the travel distance between endpoints to reduce latency, minimize server load, and improve performance. It is also a message broker that optimizes data flow between services.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1715172651612\"><h3 class=\"schema-faq-question\">How Do I Install a Specific Version of Redis?<\/h3> <p class=\"schema-faq-answer\">You can install a specific version of Redis from the official Ubuntu repositories by running <strong>apt install redis-server=<\/strong>. Replace the number placeholder with the actual value. You can also download other releases by adding third-party repos or the Redis source code.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1715172663686\"><h3 class=\"schema-faq-question\">Can I Install Redis Using a Docker Container Instead of Directly on Ubuntu?<\/h3> <p class=\"schema-faq-answer\">Absolutely! You can install Redis using a <a href=\"\/ph\/tutorials\/what-is-docker\">Docker<\/a> container by pulling the Redis image from the Docker Hub. You can then manage Redis or enter its shell from outside the container using the <strong>docker<\/strong> command.&nbsp;<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Redis is an in-memory database used to store data temporarily as a cache to reduce server load and improve application performance. It is also a message broker that facilitates data flow between services. Setting up Redis can be tricky since it has various commands and configuration parameters. Moreover, this software provides several utilities that can [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ph\/tutorials\/how-to-install-and-setup-redis-on-ubuntu\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Install Redis on Ubuntu","rank_math_description":"Check the steps for installing Redis on Ubuntu: 1. Install Redis Server 2. Configure Redis 3. Check Redis Functionality and more.","rank_math_focus_keyword":"install redis ubuntu","footnotes":""},"categories":[22641,22639],"tags":[],"class_list":["post-15933","post","type-post","status-publish","format-standard","hentry","category-pre-installed-applications","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/installer-redis-sur-ubuntu","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/install-redis-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-and-setup-redis-on-ubuntu\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-and-setup-redis-on-ubuntu\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-and-setup-redis-on-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/comments?post=15933"}],"version-history":[{"count":25,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15933\/revisions"}],"predecessor-version":[{"id":124628,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15933\/revisions\/124628"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media?parent=15933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/categories?post=15933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/tags?post=15933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}