{"id":15307,"date":"2021-10-04T08:29:35","date_gmt":"2021-10-04T07:29:35","guid":{"rendered":"https:\/\/www.oderland.se\/support\/?post_type=ht_kb&#038;p=15307"},"modified":"2022-02-17T12:32:36","modified_gmt":"2022-02-17T11:32:36","slug":"how-do-i-get-started-with-redis-via-socket-in-laravel","status":"publish","type":"ht_kb","link":"https:\/\/www.oderland.se\/support\/en\/artikel\/how-do-i-get-started-with-redis-via-socket-in-laravel\/","title":{"rendered":"How do I get started with Redis via socket in Laravel?"},"content":{"rendered":"\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">This guide is intended for advanced users.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">These instructions are written specifically for Laravel 9. They may not work for older versions of Laravel.<\/p>\n\n\n\n<p>We offer Redis on all our <a rel=\"noreferrer noopener\" href=\"https:\/\/www.oderland.com\/web-hosting\/\" target=\"_blank\">web hosting accounts<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/www.oderland.com\/solutions\/agency\/\" target=\"_blank\">Agency<\/a> services. We run Redis via socket on our servers, thus Laravel needs to be reconfigured to use it for <em>e.g.<\/em> queue workers (as Laravel usually expects Redis to be run on a specific port). <\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">To set up a Laravel worker, please refer to <a rel=\"noreferrer noopener\" href=\"https:\/\/www.oderland.se\/support\/en\/artikel\/how-do-i-manage-laravel-workers-via-cpanel\/\" data-type=\"ht_kb\" data-id=\"16448\" target=\"_blank\">these instructions<\/a>.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Begin by entering that the <a href=\"https:\/\/laravel.com\/docs\/9.x\/redis#introduction)\" target=\"_blank\" rel=\"noreferrer noopener\">Predis Composer package<\/a> is required by the project. <em>I.e.<\/em>, run the following command in the root of your project:<br><code>composer require predis\/predis<\/code><br>This is needed since the PECL version of phpredis cannot be used to access Redis via socket.<\/li><li>Under the Redis settings in the <code>config\/database.php<\/code> file of the project, add the following rows for <code>scheme<\/code> and <code>path<\/code>:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">'default' =&gt; [\n             'url' =&gt; env('REDIS_URL'),\n             'host' =&gt; env('REDIS_HOST', '127.0.0.1'),\n             'password' =&gt; env('REDIS_PASSWORD', null),\n             'port' =&gt; env('REDIS_PORT', '6379'),\n             'database' =&gt; env('REDIS_DB', '0'),\n             'scheme' =&gt; env('REDIS_SCHEME', 'tcp'),\n             'path' =&gt; env('REDIS_PATH', ''),\n         ],\n'cache' =&gt; [\n             'url' =&gt; env('REDIS_URL'),\n             'host' =&gt; env('REDIS_HOST', '127.0.0.1'),\n             'password' =&gt; env('REDIS_PASSWORD', null),\n             'port' =&gt; env('REDIS_PORT', '6379'),\n             'database' =&gt; env('REDIS_CACHE_DB', '1'),\n             'scheme' =&gt; env('REDIS_SCHEME', 'tcp'),\n             'path' =&gt; env('REDIS_PATH', ''),\n         ],<\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>In your <code>.env<\/code> file for the project, replace all lines beginning with <code>REDIS_*<\/code> with the following:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">REDIS_CLIENT=predis\nREDIS_SCHEME=unix\nREDIS_PATH=\/tmp\/redis\nREDIS_PASSWORD=null\nREDIS_PORT=0<\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>To use Redis for queue management, update <code>QUEUE_CONNECTION<\/code> to <code>redis<\/code> according to <a href=\"https:\/\/laravel.com\/docs\/9.x\/redis\" target=\"_blank\" rel=\"noreferrer noopener\">the default settings for Redis in Laravel<\/a>. You can set <code>redis<\/code> as both <code>CACHE_DRIVER<\/code> and <code>SESSION_DRIVER<\/code>.<\/li><li>Clear the cache for all settings by running <code>php artisan config:cache<\/code>. This will apply the settings according to the instructions above.<\/li><\/ol>\n\n\n\n<p>If anything is added to the queue, Redis will manage it from now on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We offer Redis on all our web hosting accounts and Agency services. We run Redis via socket on our servers, thus Laravel needs to be reconfigured to use it for e.g. queue workers (as Laravel usually expects Redis to be run on a specific port). Begin by entering that the&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"ht-kb-category":[213],"ht-kb-tag":[],"class_list":["post-15307","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-developer-tools"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/15307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/comments?post=15307"}],"version-history":[{"count":9,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/15307\/revisions"}],"predecessor-version":[{"id":16492,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb\/15307\/revisions\/16492"}],"wp:attachment":[{"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/media?parent=15307"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb-category?post=15307"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.oderland.se\/support\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=15307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}