{"id":150,"date":"2024-05-21T13:44:16","date_gmt":"2024-05-21T12:44:16","guid":{"rendered":"https:\/\/thevadasan.com\/?p=150"},"modified":"2024-05-12T03:51:01","modified_gmt":"2024-05-12T02:51:01","slug":"redis-on-wordpress-in-docker","status":"publish","type":"post","link":"https:\/\/thevadasan.com\/?p=150","title":{"rendered":"Redis on WordPress in docker"},"content":{"rendered":"\n<p>Enhancing the performance of your WordPress site can significantly improve user experience and SEO rankings. One effective way to achieve this is by integrating Redis, an open-source in-memory data structure store, used as a database, cache, and message broker. If you&#8217;re running WordPress in a Docker container managed via Portainer, installing the Redis extension can be a bit tricky. This guide will walk you through the process step-by-step, ensuring you have a smoother and more performant WordPress setup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Access the Portainer Web Interface<\/h3>\n\n\n\n<p>First, you need to log into Portainer. Open your preferred web browser and navigate to your Portainer URL, which might look something like <code>http:\/\/localhost:9000<\/code>. Enter your credentials to access the dashboard.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Locate the WordPress Container<\/h3>\n\n\n\n<p>In the Portainer dashboard, proceed to the &#8220;Containers&#8221; section. Here, you&#8217;ll find your WordPress container listed among others. It\u2019s important to correctly identify your WordPress container to make the appropriate changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Open an Interactive Shell<\/h3>\n\n\n\n<p>After locating your WordPress container in the list, click on it to open its details page. From here, navigate to the &#8220;Console&#8221; tab and click on it. You\u2019ll see an option to &#8220;Connect&#8221;; clicking this button will open an interactive shell inside the WordPress container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Install the Redis Extension<\/h3>\n\n\n\n<p>Within the container\u2019s shell, execute the following commands to install the Redis extension:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">apt-get update\napt-get install -y libzstd-dev zlib1g-dev\npecl install redis\ndocker-php-ext-enable redis<\/code><\/pre>\n\n\n\n<p>These commands update the package lists, install dependencies necessary for Redis, and enable the Redis extension in your WordPress setup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Verify the Redis Extension<\/h3>\n\n\n\n<p>To verify that Redis is properly installed, still inside the container&#8217;s shell, type the following to create a PHP file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">echo \"&lt;?php phpinfo(); ?&gt;\" &gt; \/var\/www\/html\/phpinfo.php<\/code><\/pre>\n\n\n\n<p>Then exit the container\u2019s shell with the <code>exit<\/code> command. Access the newly created <code>phpinfo.php<\/code> via your web browser at an address like <code>http:\/\/localhost\/phpinfo.php<\/code>. This page should display the Redis section if the extension is installed and enabled correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"777\" src=\"https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am-1024x777.png\" alt=\"\" class=\"wp-image-153\" srcset=\"https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am-1024x777.png 1024w, https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am-300x228.png 300w, https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am-768x583.png 768w, https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am-600x455.png 600w, https:\/\/thevadasan.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-12-at-12.30.12-am.png 1393w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Configure Redis Connection in WordPress<\/h3>\n\n\n\n<p>To utilize Redis, modify your WordPress plugin or theme code to connect to the Redis server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$redis = new Redis();\n$redis-&gt;connect('redis', 6379);<\/code><\/pre>\n\n\n\n<p>In the above code, replace <code>'redis'<\/code> with the hostname of your Redis container and <code>6379<\/code> with the port Redis is listening on (if you have a different setup).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Restart the WordPress Container (Optional)<\/h3>\n\n\n\n<p>If you\u2019ve made any changes to the code that require a restart, go back to the WordPress container details page in Portainer and hit the &#8220;Restart&#8221; button. This ensures all your new settings take effect properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>By following these steps, you can successfully install and enable the Redis extension for your WordPress container running via Portainer. This integration not only enhances the performance of your WordPress site by speeding up database interactions but also helps in scaling your application efficiently. Remember, the exact steps might vary slightly depending on your specific Portainer and Docker configuration, so adapt the instructions as necessary.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enhancing Your WordPress Performance with Redis on Portainer<\/p>\n","protected":false},"author":1,"featured_media":151,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,17,18],"tags":[39,40],"_links":{"self":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/150"}],"collection":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":2,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":155,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions\/155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/media\/151"}],"wp:attachment":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}