{"id":2230,"date":"2017-05-25T09:52:13","date_gmt":"2017-05-25T08:52:13","guid":{"rendered":"http:\/\/blog.repsaj.nl\/?p=2230"},"modified":"2017-05-25T09:52:13","modified_gmt":"2017-05-25T08:52:13","slug":"azure-wordpress-and-azure-redis-cache","status":"publish","type":"post","link":"http:\/\/blog.repsaj.nl\/index.php\/2017\/05\/azure-wordpress-and-azure-redis-cache\/","title":{"rendered":"[Azure] WordPress and Azure Redis Cache"},"content":{"rendered":"<p>I a quest to optimize the performance of my WordPress powered site, I thought I&#8217;d give Redis Cache a go. Redis Cache has become the industry default when it comes to caching in a key-value style. Azure has a Redis Cache offering which you can use to enhance the performance of any app. If you&#8217;re not familiar with caching: it&#8217;s a mechanism to eliminate timely data retrieval actions. Caching can be implemented several different places: you web browser uses caching so that it does not have to retrieve all files on every load. Redis Cache is usually more targeted towards scenario&#8217;s like database connections. Instead of getting items from a database table, which usually is relatively slow, you can get them from the cache instead.<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<h2>Creating a Redis Cache instance<\/h2>\n<p>This is the easiest step, as with a lot of &#8220;create x on Azure&#8221; steps. You simply head over to the Azure Portal and create a new Redis instance. Also similar to other Azure steps, you&#8217;ll need to select your subscription, resource group and a pricing tier (no, it&#8217;s not free).<\/p>\n<p>&nbsp;<\/p>\n<h2>Preparing your WordPress instance<\/h2>\n<p>To use Redis Cache, you&#8217;ll need to install a plugin. I&#8217;ve chosen to use the <a href=\"https:\/\/wordpress.org\/plugins\/redis-cache\" target=\"_blank\">Redis Object Cache<\/a>\u00a0plugin. This one supports multiple clients to connect with Redis. In order to use one of these clients, you&#8217;ll need to install extensions for PHP so that the clients become available. Here&#8217;s what you need to do:<\/p>\n<ul>\n<li>Download the extension you prefer. I went with the\u00a0<strong>redis<\/strong> php extension. When hosting on Windows, you&#8217;ll need the precompiled DLL which you can download <a href=\"https:\/\/pecl.php.net\/package\/redis\" target=\"_blank\">here<\/a>. Make sure you pick the correct version for the PHP version you&#8217;re running (which you can check in the application settings).<\/li>\n<li>Open up\u00a0<strong>Kudu<\/strong> by clicking the &#8220;Advanced Tools&#8221; option in your app service instance.<\/li>\n<li>Create a new folder <strong>ext<\/strong>\u00a0in the D:\\home\\site path.<\/li>\n<li>Upload the DLL for the extension there, you can simply drag &amp; drop it in any modern browser.<\/li>\n<li>Next, create a folder\u00a0<strong>ini<\/strong>, also in the D:\\home\\site path.<\/li>\n<li>Here you&#8217;ll need to create a new file called\u00a0<strong>extensions.ini<\/strong> which will point PHP to the extension we just uploaded. Copy\/paste the following:\n<pre class=\"lang:php decode:true\">; Enable Extensions\r\nextension=d:\\home\\site\\ext\\php_redis.dll\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Configuring the plugin<\/h2>\n<p>With all the prerequisites set-up, we can now configure the plugin. This plugin does not feature a UI for configuration so instead we&#8217;ll need to edit the config file ourselves.<\/p>\n<ul>\n<li>Again go to\u00a0<strong>Kudu<\/strong><\/li>\n<li>Navigate to d:\\home\\site\\wwwroot and edit\u00a0<strong>wp-config.php<\/strong><\/li>\n<li>Copy \/ paste the following:\n<pre class=\"lang:default decode:true\">\/\/ Redis Cache plugin configuration\r\ndefine('WP_REDIS_SCHEME', 'tcp');\r\ndefine('WP_REDIS_HOST', '&lt;redishost&gt;');\r\ndefine('WP_REDIS_PORT', '6379');\r\ndefine('WP_REDIS_DATABASE', '0');\r\ndefine('WP_REDIS_PASSWORD', '&lt;yourpass&gt;');\r\ndefine('WP_CACHE_KEY_SALT', '&lt;prefix&gt;');<\/pre>\n<p>Some explanation of the settings you need to change:<\/p>\n<ul>\n<li><strong>&lt;redishost&gt;<\/strong>: replace this with the URL of your redis instance, which would be &lt;name&gt;.redis.cache.windows.net<\/li>\n<li><strong>&lt;yourpass&gt;<\/strong>:\u00a0open up &#8220;Access Keys&#8221; for your Redis instance and copy\/paste the primary access key<\/li>\n<li><strong>&lt;prefix&gt;<\/strong>: this is especially useful when you&#8217;ve also got a staging instance of your website and you don&#8217;t want to create an additional cache instance. The prefix will allow you to prefix all of the cache keys to prevent multiple WordPress instances using the same cache keys (and thus getting each others data).<\/li>\n<\/ul>\n<\/li>\n<li>I also tried to secure the connection by using the SSL port (6380 by default), but that didn&#8217;t work for me. If you&#8217;ve got that figured out, drop the solution in the comments please!<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Verifying it all works<\/h2>\n<p>Now that you&#8217;ve got everything set-up and configured, you can enable the plugin from the WordPress admin section. It&#8217;s found under\u00a0<strong>Settings &gt; Redis<\/strong>. When the connection is up &amp; running, it should display the following:<\/p>\n<p><a href=\"http:\/\/blog.repsaj.nl\/index.php\/2017\/05\/azure-wordpress-and-azure-redis-cache\/wordpressredis\/\" rel=\"attachment wp-att-2231\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2231\" src=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2017\/05\/wordpressredis.png\" alt=\"wordpressredis\" width=\"424\" height=\"212\" srcset=\"http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2017\/05\/wordpressredis.png 424w, http:\/\/blog.repsaj.nl\/wp-content\/uploads\/2017\/05\/wordpressredis-300x150.png 300w\" sizes=\"(max-width: 424px) 100vw, 424px\" \/><\/a><\/p>\n<p>You can also verify that your cache is being populated with items by downloading the <a href=\"https:\/\/redisdesktop.com\/\">Redis Desktop Manager<\/a> and inspecting the redis databases in your instance.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Note:\u00a0<\/strong>using Redis Cache is just one of the ways to improve the performance of your site. There are numerous plugins for WordPress which help to improve the speed of your database, implement front-end caching and other optimizations. You&#8217;ll need to pick the one(s) right for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I a quest to optimize the performance of my WordPress powered site, I thought I&#8217;d give Redis Cache a go. Redis Cache has become the industry default when it comes to caching in a key-value style. Azure has a Redis Cache offering which you can use to enhance the performance of any app. If you&#8217;re<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[34],"tags":[78,194,193],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3KFR1-zY","_links":{"self":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/2230"}],"collection":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/comments?post=2230"}],"version-history":[{"count":0,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/posts\/2230\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/media?parent=2230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/categories?post=2230"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.repsaj.nl\/index.php\/wp-json\/wp\/v2\/tags?post=2230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}