<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: devTalk</title>
    <description>The latest articles on DEV Community by devTalk (@devtalk94).</description>
    <link>https://dev.to/devtalk94</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3228626%2F5495a7f0-c356-4253-865c-b83286ec1fe4.jpg</url>
      <title>DEV Community: devTalk</title>
      <link>https://dev.to/devtalk94</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devtalk94"/>
    <language>en</language>
    <item>
      <title>MySQL Slow Query Log: Enable, Read and Find Slow Queries</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Thu, 19 Nov 2026 02:47:47 +0000</pubDate>
      <link>https://dev.to/devtalk94/mysql-slow-query-log-enable-read-and-find-slow-queries-3h5a</link>
      <guid>https://dev.to/devtalk94/mysql-slow-query-log-enable-read-and-find-slow-queries-3h5a</guid>
      <description>&lt;p&gt;"The database is slow" is not a diagnosis. Before you add an index or rewrite a query, you need to know which statements are slow, how often they run, and how much work each one does. MySQL's slow query log records exactly that. This is Part 1 of a two-part series: here we turn the log on, read it, and group the results. &lt;a href="https://dev-talk.com/post/mysql-explain-fix-slow-queries-indexes" rel="noopener noreferrer"&gt;Part 2&lt;/a&gt; takes the worst offenders and fixes them with &lt;code&gt;EXPLAIN&lt;/code&gt; and indexes.&lt;/p&gt;

&lt;p&gt;Everything below was run on MySQL 8.0.46 (Ubuntu package) against a test schema with 500,000 rows in &lt;code&gt;orders&lt;/code&gt; and 20,000 in &lt;code&gt;users&lt;/code&gt;, both with only primary keys. The application-side examples ran on Laravel 13.40.0 and PHP 8.3. The numbers in the output blocks come from those runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn the slow query log on
&lt;/h2&gt;

&lt;p&gt;The MySQL manual says the slow query log is disabled by default, that &lt;code&gt;long_query_time&lt;/code&gt; defaults to 10 seconds, and that the file is named &lt;code&gt;host_name-slow.log&lt;/code&gt; in the data directory unless you give it a path. Put the settings in your server config so they survive restarts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[mysqld]&lt;/span&gt;
&lt;span class="na"&gt;slow_query_log&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="na"&gt;slow_query_log_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;span class="na"&gt;long_query_time&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The directory must exist and be writable by the MySQL user. I used &lt;code&gt;long_query_time = 0.03&lt;/code&gt; in my tests only because my table is small and fast; start at one second in production and lower it as you fix the worst queries. After a restart with those settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysql&amp;gt; SHOW VARIABLES WHERE Variable_name IN ('slow_query_log','long_query_time','log_queries_not_using_indexes','min_examined_row_limit','log_output');
log_output                      FILE
log_queries_not_using_indexes   OFF
long_query_time                 0.030000
min_examined_row_limit          0
slow_query_log                  ON
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change it without a restart
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="no"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;slow_query_log&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ON'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="no"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;long_query_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manual documents &lt;code&gt;slow_query_log&lt;/code&gt; and &lt;code&gt;slow_query_log_file&lt;/code&gt; as runtime-changeable global variables. I toggled the log off and on and read the value back each time. A &lt;code&gt;SET GLOBAL&lt;/code&gt; does not survive a restart, so put the permanent values in the config file.&lt;/p&gt;

&lt;h3&gt;
  
  
  The catch: existing connections keep the old threshold
&lt;/h3&gt;

&lt;p&gt;A global change to &lt;code&gt;long_query_time&lt;/code&gt; applies to &lt;em&gt;new&lt;/em&gt; connections. I tested it: connection A was opened while the global value was 10 seconds, then the global value was lowered to 0.03. Both connections then ran the same slow query pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;entries logged: 1
logged: SELECT COUNT(*) FROM orders WHERE DATE(created_at) = "2026-03-16";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the query from the new connection (…03-16) was logged. The old connection's query was not. That matters for PHP-FPM with persistent connections and for queue workers and Octane processes that stay up for days: after you lower the threshold, restart them or you will wonder why the log is empty.&lt;/p&gt;

&lt;h2&gt;
  
  
  What gets logged
&lt;/h2&gt;

&lt;p&gt;Per the manual, a statement is written after it has executed and its locks have been released, so log order may differ from execution order. It must run longer than &lt;code&gt;long_query_time&lt;/code&gt; and examine at least &lt;code&gt;min_examined_row_limit&lt;/code&gt; rows. Time spent waiting for the initial locks is not counted as execution time. The manual's intro says "more than" the threshold while its decision list says "at least", so treat the exact boundary as unspecified.&lt;/p&gt;

&lt;p&gt;I ran six statements: five slow ones plus a primary key lookup. Five were logged, and the lookup was not. Here is one raw entry with the volatile parts replaced:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Time: &amp;lt;ts&amp;gt;
# User@Host: root[root] @ localhost []
# Query_time: &amp;lt;t&amp;gt;  Lock_time: &amp;lt;t&amp;gt; Rows_sent: 20  Rows_examined: 500020
use shop;
SET timestamp=&amp;lt;ts&amp;gt;;
SELECT * FROM orders WHERE user_id = 1234 ORDER BY created_at DESC LIMIT 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manual defines the fields: &lt;code&gt;Query_time&lt;/code&gt; is the execution time in seconds, &lt;code&gt;Lock_time&lt;/code&gt; the time to acquire locks, &lt;code&gt;Rows_sent&lt;/code&gt; the rows returned to the client, and &lt;code&gt;Rows_examined&lt;/code&gt; the rows examined by the server layer. The one to watch is the relationship between the last two. This query returned 20 rows after examining 500,020. All five entries:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;Rows_sent&lt;/th&gt;
&lt;th&gt;Rows_examined&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Latest 20 orders for one user&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;500,020&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;COUNT(*)&lt;/code&gt; with &lt;code&gt;DATE(created_at) = ...&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;500,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;reference LIKE '%0042'&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;500,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pending orders in a 7-day window&lt;/td&gt;
&lt;td&gt;2,016&lt;/td&gt;
&lt;td&gt;500,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Join of orders and users, grouped&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;600,005&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every one of them read the whole table to return a handful of rows. Execution time depends on caching and hardware, but a huge &lt;code&gt;Rows_examined&lt;/code&gt; compared with &lt;code&gt;Rows_sent&lt;/code&gt; tells you the query is missing an index or defeating one, and it is the same on every run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Group the log with mysqldumpslow
&lt;/h2&gt;

&lt;p&gt;A busy server logs the same query shape thousands of times with different literals. &lt;code&gt;mysqldumpslow&lt;/code&gt; ships with MySQL and collapses them. I ran the same "latest orders for a user" query for five different user ids plus one other query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysqldumpslow -s c /var/log/mysql/mysql-slow.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Count: 5  Time=&amp;lt;t&amp;gt;s (&amp;lt;t&amp;gt;s)  Lock=&amp;lt;t&amp;gt;s (&amp;lt;t&amp;gt;s)  Rows=20.0 (100), root[root]@localhost
  SELECT * FROM orders WHERE user_id = N ORDER BY created_at DESC LIMIT N
Count: 1  Time=&amp;lt;t&amp;gt;s (&amp;lt;t&amp;gt;s)  Lock=&amp;lt;t&amp;gt;s (&amp;lt;t&amp;gt;s)  Rows=1.0 (1), root[root]@localhost
  SELECT COUNT(*) FROM orders WHERE DATE(created_at) = 'S'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Numbers become &lt;code&gt;N&lt;/code&gt; and strings become &lt;code&gt;'S'&lt;/code&gt;, so the five calls count as one statement. &lt;code&gt;-s&lt;/code&gt; picks the sort: &lt;code&gt;c&lt;/code&gt; by count, &lt;code&gt;t&lt;/code&gt; by total time. Sort by total time to find what costs the most overall, and by count to find what is called most. One quirk on my Ubuntu build: when &lt;code&gt;-t&lt;/code&gt; (top N) was larger than the number of distinct statements, the script printed the groups and then ended with &lt;code&gt;Died at /usr/bin/mysqldumpslow line 163&lt;/code&gt;. Leave &lt;code&gt;-t&lt;/code&gt; off for small logs.&lt;/p&gt;

&lt;p&gt;Percona's &lt;code&gt;pt-query-digest&lt;/code&gt; does the same job with more detail. I did not install or test it here.&lt;/p&gt;

&lt;h2&gt;
  
  
  log_queries_not_using_indexes: useful, but noisy
&lt;/h2&gt;

&lt;p&gt;The manual says that with this option on, queries that do not use indexes for row lookups are logged even when they are fast. I raised the threshold to 10 seconds and enabled it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="no"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;long_query_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="no"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;log_queries_not_using_indexes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id FROM orders WHERE user_id = 1234;
SELECT id FROM users WHERE country = 'LK' LIMIT 3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those two were logged. Primary key lookups (&lt;code&gt;WHERE id = 5&lt;/code&gt; on either table) were not. On a busy system with many small tables this can flood the log, which is why the manual describes &lt;code&gt;log_throttle_queries_not_using_indexes&lt;/code&gt;, a per-minute cap. With it set to 2, five different non-indexed queries produced 2 log entries. The manual says suppressed queries are summarized later in the log. Treat the option as a periodic audit and not something to leave on permanently.&lt;/p&gt;

&lt;h2&gt;
  
  
  No log file? Use the performance schema
&lt;/h2&gt;

&lt;p&gt;If you can't change server settings or restart, the &lt;code&gt;performance_schema&lt;/code&gt; keeps per-statement-shape totals in memory. In my run it was enabled by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="no"&gt;COUNT_STAR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SUM_ROWS_EXAMINED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SUM_ROWS_SENT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;SUM_NO_INDEX_USED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;LEFT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DIGEST_TEXT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;performance_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;events_statements_summary_by_digest&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="no"&gt;SCHEMA_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'shop'&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="no"&gt;DIGEST_TEXT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'SELECT%orders%'&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="no"&gt;SUM_ROWS_EXAMINED&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 | 1500060 | 60 | 3 | SELECT * FROM `orders` WHERE `user_id` = ? ORDER BY `created_at` DESC LIMIT ?
1 | 500000  | 1  | 1 | SELECT COUNT ( * ) FROM `orders` WHERE DATE ( `created_at` ) = ?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sorting by rows examined puts the worst offenders first. It tells the same story as the slow log: three calls, one and a half million rows examined, sixty rows returned, no index used. The counters reset when the server restarts and can be cleared with &lt;code&gt;TRUNCATE&lt;/code&gt; on the summary table, so it is good for "what is hot right now" and weaker for history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Catch slow queries from Laravel
&lt;/h2&gt;

&lt;p&gt;The database log shows what MySQL saw. The application log can add the request, the user and the code path. Laravel's &lt;code&gt;DB::listen&lt;/code&gt; receives every query with its time in milliseconds. In &lt;code&gt;AppServiceProvider::boot()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Database&lt;/span&gt;\&lt;span class="nc"&gt;Events&lt;/span&gt;\&lt;span class="nc"&gt;QueryExecuted&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;QueryExecuted&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// milliseconds&lt;/span&gt;
            &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Slow query'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'ms'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'sql'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'bindings'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;bindings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran the same listener with a 30 ms threshold. The slow query was logged and the primary key lookup was not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;local.WARNING: Slow query {"ms":&amp;lt;ms&amp;gt;,"sql":"select * from `orders` where `user_id` = ? order by `created_at` desc limit 20","bindings":[1234]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be careful with the similarly named &lt;code&gt;DB::whenQueryingForLongerThan&lt;/code&gt;. Reading its source in Laravel 13.40, it compares the connection's &lt;em&gt;total&lt;/em&gt; query duration so far, not a single query, and runs its handler once. I ran three queries of roughly 130 ms each with a 150 ms threshold, and the handler fired exactly once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cumulative threshold crossed; last query: select * from `orders` where `user_id` = ? order by `created_at` desc limit 20
queries run: 3; handler fires once
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is useful for "this request spent too long in the database overall". For a single slow statement, use &lt;code&gt;DB::listen&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When you have the builder in hand, &lt;code&gt;toRawSql()&lt;/code&gt; gives you a statement you can paste into a MySQL session, and &lt;code&gt;explain()&lt;/code&gt; runs &lt;code&gt;EXPLAIN&lt;/code&gt; for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'orders'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user_id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;orderByDesc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'created_at'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$q&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;toRawSql&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// select * from `orders` where `user_id` = 1234 order by `created_at` desc limit 20&lt;/span&gt;

&lt;span class="nv"&gt;$row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$q&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;explain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// type=ALL key=NULL Extra=Using where; Using filesort&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never log raw bindings for queries that touch passwords, tokens or personal data unless your log storage is as protected as your database. The MySQL manual says passwords are rewritten in the slow log, but ordinary values such as emails and names are written as they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rotate the file.&lt;/strong&gt; Move the old log away and run &lt;code&gt;FLUSH SLOW LOGS&lt;/code&gt; so MySQL opens a new one. I used this between test runs and it produced a clean file each time. Set up log rotation so the file does not grow without limit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sample before you tune.&lt;/strong&gt; Collect at least a full business cycle (a day, a week with month-end) before deciding what is worst. A nightly report and a hot endpoint look very different.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read access.&lt;/strong&gt; The log contains real literals from real queries. Limit who can read it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost of logging.&lt;/strong&gt; I did not measure the overhead of the log. With a sensible threshold it only writes the slow statements, but a very low threshold or &lt;code&gt;log_queries_not_using_indexes&lt;/code&gt; can write a lot.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud databases.&lt;/strong&gt; Managed services (RDS, Cloud SQL and others) usually set these through parameter groups or flags and may write to a table or a managed log. I did not test any; the manual notes that &lt;code&gt;log_output&lt;/code&gt; can send the log to a table as well as a file.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Leaving &lt;code&gt;long_query_time&lt;/code&gt; at the default of 10 seconds and concluding the application has no slow queries.&lt;/li&gt;
&lt;li&gt;Lowering the threshold at runtime and not restarting long-lived workers.&lt;/li&gt;
&lt;li&gt;Reading single entries instead of grouping with &lt;code&gt;mysqldumpslow&lt;/code&gt; or the digest table, and chasing a one-off while the frequent query goes unnoticed.&lt;/li&gt;
&lt;li&gt;Judging a query only by &lt;code&gt;Query_time&lt;/code&gt;. Compare &lt;code&gt;Rows_examined&lt;/code&gt; with &lt;code&gt;Rows_sent&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Leaving &lt;code&gt;log_queries_not_using_indexes&lt;/code&gt; on permanently.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pt-query-digest&lt;/code&gt; for richer reports from the same log file (not tested here).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application performance monitoring&lt;/strong&gt; tools that sample queries with request context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The&lt;/strong&gt;&lt;code&gt;sys&lt;/code&gt;&lt;strong&gt;schema&lt;/strong&gt; views over the performance schema. I only queried the digest table directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/mysql-explain-fix-slow-queries-indexes" rel="noopener noreferrer"&gt;MySQL Slow Query Log and EXPLAIN, Part 2: Read EXPLAIN and Fix Slow Queries with Indexes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-redis-caching-patterns-cache-aside-invalidation" rel="noopener noreferrer"&gt;Laravel Redis Caching Patterns, Part 1: Cache-Aside, Key Design, Invalidation and Tags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/postgresql-vs-mysql-performance-comparison" rel="noopener noreferrer"&gt;PostgreSQL vs MySQL: Performance Comparison (Tested on the Same Machine)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/mysql-too-many-connections" rel="noopener noreferrer"&gt;MySQL "Too many connections" (Error 1040): Causes and How to Fix It&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What &lt;code&gt;long_query_time&lt;/code&gt; should I use?
&lt;/h3&gt;

&lt;p&gt;Start with 1 second and look at the log after a normal week. If it is empty, lower it. If it is overwhelming, fix the top few statements first and keep the threshold. The right value is whatever your slowest acceptable query is.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is a query logged that runs fast when I try it?
&lt;/h3&gt;

&lt;p&gt;Caching, a different parameter value, or contention at the time it ran. Copy the exact statement with its literals from the log and run it, and look at &lt;code&gt;Rows_examined&lt;/code&gt;, which does not depend on timing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the slow log show queries that were killed or failed?
&lt;/h3&gt;

&lt;p&gt;I did not test this. The manual says statements that cannot be parsed, such as syntax errors, are not logged as of MySQL 8.0.29.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is the slow log the same on MariaDB?
&lt;/h3&gt;

&lt;p&gt;The concept is the same. I tested MySQL 8.0 only, so check the MariaDB documentation for variable names and defaults.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/slow-query-log.html" rel="noopener noreferrer"&gt;MySQL 8.0 Reference Manual: The Slow Query Log&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/laravel/framework" rel="noopener noreferrer"&gt;laravel/framework source: Connection::whenQueryingForLongerThan and listen&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/mysql-slow-query-log-find-slow-queries" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>slowquerylog</category>
      <category>performance</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Hello Again Attack: Windows Hello &amp; BitLocker PIN Risk</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Thu, 19 Nov 2026 02:36:46 +0000</pubDate>
      <link>https://dev.to/devtalk94/hello-again-attack-windows-hello-bitlocker-pin-risk-2c7n</link>
      <guid>https://dev.to/devtalk94/hello-again-attack-windows-hello-bitlocker-pin-risk-2c7n</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 18 November 2026. Based on the research paper (arXiv 2611.18126, ACM CCS '26). Vendor fixes were still pending when I checked. See&lt;/em&gt;&lt;em&gt;How this was checked&lt;/em&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A short PIN is safe on a Windows PC for one reason: the TPM stops answering after a few wrong guesses. Researchers at TU Berlin showed that on many machines this lockout can be reset by rolling back the TPM's stored state, so the attacker never reaches the limit. The attack needs physical access and soldering-level hardware work, so it is not a drive-by exploit. It does change how much a four-digit PIN is worth on a stolen laptop, and that is what this article is about.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What breaks:&lt;/strong&gt; the TPM's failed-guess counter (dictionary attack protection) can be reset on affected systems, so PIN guessing continues past the lockout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What is affected:&lt;/strong&gt; Windows Hello PINs and BitLocker TPM+PIN protectors on systems where the firmware TPM keeps its state in external SPI flash.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What the attacker needs:&lt;/strong&gt; the device in hand, plus hardware work on the flash chip (one path also needs voltage glitching; another needs only a flash programmer).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What you can do now:&lt;/strong&gt; longer PINs, enhanced (alphanumeric) BitLocker startup PINs, and keeping firmware current. Details below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How the lockout normally works
&lt;/h2&gt;

&lt;p&gt;Windows Hello PINs and BitLocker TPM+PIN rely on the TPM's dictionary attack protection. After a number of failures the TPM refuses further guesses for a while. The paper uses a default rate of one try per 10 minutes as its baseline for a naive attacker.&lt;/p&gt;

&lt;p&gt;On many x86 systems the TPM is a firmware TPM (fTPM) running inside the CPU's security processor. It has no storage of its own, so its non-volatile state, including the lockout counters, is kept on the motherboard's SPI flash chip. That creates an obvious weakness: whoever controls the flash can restore an older copy of it, and the counter goes back with it. To defend against this, some flash chips implement RPMC, Replay Protected Monotonic Counters (JEDEC JESD260), which are counters that can only go up and are authenticated with an HMAC key.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the paper found
&lt;/h2&gt;

&lt;p&gt;The authors (Werling, Finder, Jacob, Prein, Kühnapfel and Seifert, TU Berlin) found ways around this protection on several platforms:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Weakness&lt;/th&gt;
&lt;th&gt;Where&lt;/th&gt;
&lt;th&gt;Effect&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HMAC key leak by voltage glitching&lt;/td&gt;
&lt;td&gt;Winbond RPMC flash&lt;/td&gt;
&lt;td&gt;The chip returns its HMAC key, which lets the attacker forge counter responses. The paper measured about 1 second per leak.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unverified counter increment&lt;/td&gt;
&lt;td&gt;AMD controller&lt;/td&gt;
&lt;td&gt;The controller does not check that an increment succeeded. An interposer board can suppress the increment command and reply with a fake success.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No RPMC flash at all&lt;/td&gt;
&lt;td&gt;Two AMD desktops tested (Zen 2 and Zen 5)&lt;/td&gt;
&lt;td&gt;Re-flashing an old SPI image with a programmer reset the lockout counters. No special interposer was needed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constant key data&lt;/td&gt;
&lt;td&gt;Intel RPMC controllers&lt;/td&gt;
&lt;td&gt;Classed by the paper as a weakness, not a vulnerability. It lowers the cost of exploiting the Winbond key leak.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Counter overflow, corruption&lt;/td&gt;
&lt;td&gt;Winbond, Macronix, GigaDevice flash&lt;/td&gt;
&lt;td&gt;Counters can overflow at their maximum (roughly 4 to 6 weeks of incrementing in the authors' tests), and GigaDevice counters could be corrupted by glitching (about 10% success per attempt).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  What an attacker actually needs
&lt;/h2&gt;

&lt;p&gt;This is why the risk is real but narrow. From the paper:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Physical possession of the machine.&lt;/li&gt;
&lt;li&gt;For the interposer paths, desoldering the flash chip and fitting a socket, plus an interposer built from inexpensive parts (the authors used a Raspberry Pi Pico 2W, roughly $5, with a multiplexer and level shifting).&lt;/li&gt;
&lt;li&gt;For the Winbond key leak, voltage glitching equipment.&lt;/li&gt;
&lt;li&gt;Automation to type PINs and reboot repeatedly.&lt;/li&gt;
&lt;li&gt;No knowledge of the PIN. Note also that Windows itself limited the Windows Hello demo to 5 tries per boot.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Someone who steals a laptop at an airport is unlikely to do this on the spot. A motivated attacker with a lab and a target worth the effort, or someone who has your laptop overnight, is the realistic threat model.&lt;/p&gt;

&lt;h2&gt;
  
  
  How fast it was in practice
&lt;/h2&gt;

&lt;p&gt;Measured results from the paper (236 PIN attempts in each run):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Windows Hello&lt;/strong&gt; on an AMD laptop: 57 minutes net, about 4.1 tries per minute.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BitLocker TPM+PIN&lt;/strong&gt; on an Intel laptop (Framework Laptop 13): 8 min 40 s in the first run and 6 min 55 s after the automation was optimized, about 34 tries per minute.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The worst-case times for exhausting the PIN space are &lt;em&gt;estimates&lt;/em&gt; derived from those rates:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;PIN&lt;/th&gt;
&lt;th&gt;With lockout (naive, 10 min per try)&lt;/th&gt;
&lt;th&gt;With counter rollback&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;4-digit Windows Hello PIN&lt;/td&gt;
&lt;td&gt;69 days&lt;/td&gt;
&lt;td&gt;40 hours&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6-digit Windows Hello PIN&lt;/td&gt;
&lt;td&gt;not listed here&lt;/td&gt;
&lt;td&gt;168 days&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6-digit BitLocker PIN&lt;/td&gt;
&lt;td&gt;19 years&lt;/td&gt;
&lt;td&gt;20 days&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The paper also estimates that moving Hello from 4 to 6 digits and BitLocker from 6 to 8 would raise the rollback worst case to 168 days (Hello) and about 6 years (BitLocker). These are worst cases for numeric PINs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who has said what
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft:&lt;/strong&gt; according to the paper, closed the Windows Hello report as moderate severity (defense in depth), with no CVE and no bounty, and committed to raising the recommended minimum Hello PIN length to 6 digits. The paper says Microsoft will communicate when its fix ships.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AMD:&lt;/strong&gt; acknowledged the report and passed it on for internal review. As of the paper, no committed fix. Some news coverage of the paper cites an AMD bulletin and CVE for this; I could not open AMD's site from my environment, and the paper itself lists no CVE, so I am not quoting one. Check AMD's product security page directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intel:&lt;/strong&gt; first closed the key-reuse report as informative, then classified it as a security weakness (not a vulnerability) after the case was reopened.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Winbond:&lt;/strong&gt; evaluating; a silicon revision is one option. No committed fix or date. Flash hardware already deployed cannot be patched by software alone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Macronix:&lt;/strong&gt; confirmed the counter wraparound and closed it as impractical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GigaDevice:&lt;/strong&gt; engaged; fix or statement pending.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do about it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  For individuals
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use a longer PIN. Each extra digit multiplies the search space by ten, which is the only lever you control.&lt;/li&gt;
&lt;li&gt;For a laptop that leaves the house, use a BitLocker startup PIN and not just the TPM, and prefer an alphanumeric one (below).&lt;/li&gt;
&lt;li&gt;Keep UEFI and firmware updates current. AMD and the flash vendors have not shipped fixes for everything yet, but updates are where they will arrive.&lt;/li&gt;
&lt;li&gt;Treat a laptop that was out of your sight for hours, with a short PIN, as potentially accessed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  For administrators
&lt;/h3&gt;

&lt;p&gt;BitLocker's startup PIN length and character set are controlled by two Group Policy settings under &lt;em&gt;Computer Configuration &amp;gt; Administrative Templates &amp;gt; Windows Components &amp;gt; BitLocker Drive Encryption &amp;gt; Operating System Drives&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Configure minimum PIN length for startup:&lt;/strong&gt; the documented range is 4 to 20 characters. Raise the minimum.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow enhanced PINs for startup:&lt;/strong&gt; when enabled, new startup PINs can include letters, symbols and spaces, not only digits. Not all hardware supports enhanced PINs in the pre-boot environment, so test on your models before rolling it out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Existing protectors do not change when you change the policy. Users must set a new PIN. I did not run the following on Windows (this environment is Linux), but the standard way to inspect and replace the protector from an elevated prompt is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;manage-bde -status C:
manage-bde -protectors -delete C: -type TPMAndPIN
manage-bde -protectors -add C: -TPMAndPIN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you have a recovery key backed up before deleting protectors, and run the commands from an elevated session. Check &lt;code&gt;manage-bde -?&lt;/code&gt; on your Windows build if the syntax differs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking your AMD machine on Linux
&lt;/h3&gt;

&lt;p&gt;The paper notes that on AMD systems, Linux 5.19 and later expose &lt;code&gt;rpmc_spirom_available&lt;/code&gt; and &lt;code&gt;rpmc_production_enabled&lt;/code&gt; through sysfs, and that &lt;code&gt;fwupdmgr security&lt;/code&gt; reports the status of AMD SPI replay protection. I did not run these here because the sandbox has no AMD hardware, so I cannot show output. They tell you whether your board has RPMC support, which is a precondition, not proof that you are safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common misreadings
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;"Windows Hello is broken for everyone."&lt;/strong&gt; The demonstrated attacks need physical access and hardware modification. Remote attackers are not in scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"A TPM is useless."&lt;/strong&gt; The TPM still protects against online and software guessing. The issue is the storage the firmware TPM depends on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;"Dedicated TPM chips are affected the same way."&lt;/strong&gt; The paper's focus is firmware TPMs storing state on SPI flash. I did not verify the effect on discrete TPMs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is there a CVE for the Hello Again attack?
&lt;/h3&gt;

&lt;p&gt;The paper lists none, and says Microsoft issued no CVE for the Windows Hello case. Some secondary reports mention an AMD identifier; I could not confirm it from an AMD source.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can someone do this remotely?
&lt;/h3&gt;

&lt;p&gt;Not according to the paper. Every demonstrated path involves physical access to the flash chip.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is a six-digit PIN enough?
&lt;/h3&gt;

&lt;p&gt;It is better, not safe. The paper's estimate for a 6-digit Windows Hello PIN with rollback is 168 days worst case, and for a 6-digit BitLocker PIN it is 20 days. For high-value laptops, use a longer or alphanumeric BitLocker PIN.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does a Microsoft update fix it?
&lt;/h3&gt;

&lt;p&gt;Not yet, as far as I could find. Microsoft committed to a longer recommended Hello PIN, and fixes for the hardware flaws depend on AMD, the flash vendors and BIOS updates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does BitLocker without a PIN get worse?
&lt;/h3&gt;

&lt;p&gt;This research targets PIN guessing. TPM-only BitLocker has a different exposure that I did not cover here.&lt;/p&gt;

&lt;h2&gt;
  
  
  update log
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;18 November 2026:&lt;/strong&gt; first version, days after the paper appeared.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck:&lt;/strong&gt; Microsoft's final guidance on Hello PIN length, AMD's firmware and bulletin status, Winbond and GigaDevice statements, and any CVE assigned.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/pdf/2611.18126" rel="noopener noreferrer"&gt;Hello Again: Exploiting Replay Protected Monotonic Counters to Brute-Force Windows Hello PINs (arXiv 2611.18126)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cryptika.com/new-hello-again-attack-bypasses-windows-hello-and-bitlocker-pin-lockout-protection/" rel="noopener noreferrer"&gt;Cryptika: New Hello Again Attack Bypasses Windows Hello and BitLocker PIN Lockout Protection&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tenable.com/audits/items/MSCT_Windows_10_1803_v1.0.0.audit:0cc3c0750ac8850a0051560fed3862ff" rel="noopener noreferrer"&gt;Configure minimum PIN length for startup (policy description)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tenable.com/audits/items/MSCT_Windows_11_v1.0.0.audit:3b755d422ae77747dcd2f50c2bbd8819" rel="noopener noreferrer"&gt;Allow enhanced PINs for startup (policy description)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/hello-again-windows-hello-attack" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>windowshello</category>
      <category>bitlocker</category>
      <category>tpm</category>
      <category>hardwaresecurity</category>
    </item>
    <item>
      <title>Laravel Redis Cache Stampede, Locks and Memory Limits</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:31:04 +0000</pubDate>
      <link>https://dev.to/devtalk94/laravel-redis-cache-stampede-locks-and-memory-limits-433f</link>
      <guid>https://dev.to/devtalk94/laravel-redis-cache-stampede-locks-and-memory-limits-433f</guid>
      <description>&lt;p&gt;A cache that works under light traffic can fail under load in three ways: many requests rebuild the same expired value at once, a counter quietly never expires, or Redis fills up and either rejects writes or evicts something you needed. This is Part 2 of the series. &lt;a href="https://dev-talk.com/post/laravel-redis-caching-patterns-cache-aside-invalidation" rel="noopener noreferrer"&gt;Part 1&lt;/a&gt; covers cache-aside, key layout, models and invalidation. Here I reproduce each failure with a real Redis server and then fix it.&lt;/p&gt;

&lt;p&gt;Tested on Laravel 13.40.0, PHP 8.3.6 with phpredis 5.3.7, and Redis 7.0.15. Each result below is copied from a script I ran twice with identical output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache stampede: 20 requests, one cold key
&lt;/h2&gt;

&lt;p&gt;When a hot key expires, every request that arrives before the first one finishes rebuilds it. The "slow query" below takes about 0.8 seconds, and I started 20 PHP processes at once against a cold key, counting how many times the closure really ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// naive&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;slowQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;naive: closure ran 20 time(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All 20 hit the database. For a query that takes seconds, or a key that thousands of requests want, that is how a cache expiry becomes an outage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fix 1: a lock around the rebuild
&lt;/h3&gt;

&lt;p&gt;Laravel's atomic locks (they need the &lt;code&gt;redis&lt;/code&gt;, &lt;code&gt;memcached&lt;/code&gt;, &lt;code&gt;dynamodb&lt;/code&gt;, &lt;code&gt;database&lt;/code&gt;, &lt;code&gt;file&lt;/code&gt; or &lt;code&gt;array&lt;/code&gt; driver, and all servers must use the same central cache server, per the docs) let one process rebuild while the others wait:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dashboardStats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'stats:dashboard'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Fast path: no lock for the common hit.&lt;/span&gt;
    &lt;span class="nv"&gt;$cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$cached&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$cached&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Slow path: one process rebuilds, the rest wait up to 5 seconds.&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lock:$key"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Re-check inside the lock: a waiting process finds the value the first one stored.&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;expensiveQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lock: closure ran 1 time(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Details that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;block(5, ...)&lt;/code&gt; throws &lt;code&gt;Illuminate\Contracts\Cache\LockTimeoutException&lt;/code&gt; if the lock isn't acquired within 5 seconds (documented). Decide what a waiter does then: usually compute anyway or return an error, but not wait forever.&lt;/li&gt;
&lt;li&gt;The lock's own TTL (10 seconds here) should be longer than the slowest realistic rebuild. If it expires mid-rebuild, a second process can start one. That follows from how expiring locks work; I did not test an expired lock.&lt;/li&gt;
&lt;li&gt;The re-check inside the lock is what makes the others stop. &lt;code&gt;remember&lt;/code&gt; does it for you.&lt;/li&gt;
&lt;li&gt;By default the lock key is stored through the &lt;code&gt;default&lt;/code&gt; Redis connection (database 0), not next to the cache keys. After starting a lock in a test I saw &lt;code&gt;laravel-database-laravel-cache-report&lt;/code&gt; in database 0 and nothing in database 1. &lt;code&gt;REDIS_CACHE_LOCK_CONNECTION&lt;/code&gt; in &lt;code&gt;config/cache.php&lt;/code&gt; controls this.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fix 2: Cache::flexible (serve stale, refresh in the background)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Cache::flexible&lt;/code&gt; takes two numbers: how long the value is fresh, and its total lifetime. Between the two, the stale value is returned immediately and the refresh runs after the response (per the docs, as a deferred function).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$stats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;flexible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'stats:dashboard'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;expensiveQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tested it with &lt;code&gt;[2, 6]&lt;/code&gt; and a counter for how often the closure ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;returned compute#1
  runs=1  &amp;lt;- cold miss
returned compute#1
  runs=1  &amp;lt;- fresh hit
returned compute#1
  runs=2  &amp;lt;- stale read, refreshed before the command exits
returned compute#2
  runs=2  &amp;lt;- fresh again
returned compute#3
  runs=3  &amp;lt;- expired, recomputed inline
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The stale read returned the old value (compute #1) and then refreshed it, so the next call saw compute #2. After the full 6 seconds, the value was gone and the caller waited for a fresh compute. So the second number is the total lifetime of the entry, not extra time on top of the first. (I ran this as an Artisan command, where the deferred refresh finished before the process exited. In a web request the docs say it runs after the response is sent; I did not test HTTP.)&lt;/p&gt;

&lt;p&gt;With 20 processes asking at once while the value was stale, the closure ran once more, not 20 times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runs after the burst: 2  (1 = the initial compute)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The framework source explains why: the refresh takes a lock and skips the work if another process has already refreshed the value. &lt;strong&gt;But flexible does not protect a cold key.&lt;/strong&gt; With the same 20-process test on an empty cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flexible: closure ran 20 time(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a miss, the source computes the value directly without a lock. So the right combination is: use &lt;code&gt;flexible&lt;/code&gt; for keys that are already warm, and use the lock pattern (or warm the key from a scheduled command or a deploy step) for the first fill.&lt;/p&gt;

&lt;h2&gt;
  
  
  Counters: increment() on a missing key never expires
&lt;/h2&gt;

&lt;p&gt;Counters are the other thing people cache in Redis: page views, login attempts, API quotas.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hits:bad'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;// key does not exist yet&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hits:bad'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hits:bad = 2
  TTL=-1  (-1 = never expires)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Redis, the key was created with no expiry. A "per hour" counter built this way counts forever. The Laravel docs' own example initializes the key first with &lt;code&gt;add&lt;/code&gt;, which only writes if the key doesn't exist and is atomic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hits:good'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// creates it with a 60-second TTL only if missing&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hits:good'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'hits:good'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hits:good = 2
  TTL=60
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives you a simple fixed-window limiter. Allow 3 requests per minute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'limit:ip'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'limit:ip'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// reject&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request 1 -&amp;gt; count 1 -&amp;gt; allowed
request 2 -&amp;gt; count 2 -&amp;gt; allowed
request 3 -&amp;gt; count 3 -&amp;gt; allowed
request 4 -&amp;gt; count 4 -&amp;gt; blocked
request 5 -&amp;gt; count 5 -&amp;gt; blocked
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two limits to know: a fixed window lets a burst through at the boundary (3 at the end of one minute, 3 at the start of the next), and if the key expires between &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;increment&lt;/code&gt;, &lt;code&gt;increment&lt;/code&gt; recreates it without a TTL. That window is tiny, but I did not try to hit it. For HTTP rate limiting, Laravel's built-in rate limiter is the better tool; this pattern is for your own counters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory: what happens when Redis fills up
&lt;/h2&gt;

&lt;p&gt;Redis does not limit memory unless you tell it to. On a fresh Redis 7.0.15 I read the defaults:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;maxmemory         0              (no limit)
maxmemory-policy  noeviction
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Redis docs list the policies. These are the ones that matter for Laravel:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Policy&lt;/th&gt;
&lt;th&gt;What the Redis docs say&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;noeviction&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Nothing is evicted; commands that would add data return an error. Reads still work.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;allkeys-lru&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Evicts the least recently used keys from the whole keyspace.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;volatile-lru&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Evicts the least recently used keys that have a TTL. With no TTL keys, it behaves like &lt;code&gt;noeviction&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I limited &lt;code&gt;maxmemory&lt;/code&gt; to 3 MB above current use, then wrote 2,000 values of 4 KB each through &lt;code&gt;Cache::put&lt;/code&gt; under each policy. I also stored 100 plain keys without a TTL in database 0 to stand in for data that must not disappear (think queued jobs or sessions; these were raw keys, not real Laravel queue structures).&lt;/p&gt;

&lt;h3&gt;
  
  
  noeviction: your cache calls start throwing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stored &amp;lt;N&amp;gt;, then RedisException: OOM command not allowed when used memory &amp;gt; 'maxmemory'.
dbsize&amp;gt;0 and &amp;lt;2000: yes; evicted_keys=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Redis kept what it had and refused new writes. In a Laravel app that means &lt;code&gt;Cache::put&lt;/code&gt; throws, and so does anything else that writes to that server. Whether that is acceptable depends on what else lives there.&lt;/p&gt;

&lt;h3&gt;
  
  
  allkeys-lru: great for a cache, dangerous for everything else
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stored all 2000
evicted_keys&amp;gt;0: yes; job keys left in db0: 0 of 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All 2,000 writes succeeded, and Redis made room by evicting old keys, including all 100 of my no-TTL keys in a different database. Eviction works on the whole server's keyspace, not per database. If your queues, sessions or locks share this Redis instance, &lt;code&gt;allkeys-lru&lt;/code&gt; can evict them.&lt;/p&gt;

&lt;h3&gt;
  
  
  volatile-lru: protects keys without a TTL, until they fill the memory
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cache keys with a TTL:
stored all 2000
evicted_keys&amp;gt;0: yes; job keys left in db0: 100 of 100
cache keys with no TTL (Cache::forever):
stored &amp;lt;N&amp;gt;, then RedisException: OOM command not allowed when used memory &amp;gt; 'maxmemory'.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With TTL'd cache writes, Redis evicted only keys that had TTLs and my 100 no-TTL keys survived. But when I wrote the same data with &lt;code&gt;Cache::forever&lt;/code&gt;, nothing was evictable and writes failed with the same OOM error. Under &lt;code&gt;volatile-lru&lt;/code&gt;, every cache key needs a TTL.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I'd do
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Run the cache on its own Redis instance&lt;/strong&gt; with &lt;code&gt;maxmemory&lt;/code&gt; set and &lt;code&gt;allkeys-lru&lt;/code&gt;. Keep queues, sessions and anything that must not vanish on another instance (with enough memory and &lt;code&gt;noeviction&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Point the cache connection at that instance. In the default &lt;code&gt;config/database.php&lt;/code&gt;, the &lt;code&gt;cache&lt;/code&gt; connection reads the same &lt;code&gt;REDIS_HOST&lt;/code&gt; as &lt;code&gt;default&lt;/code&gt;, so add dedicated variables:&lt;code&gt;// config/database.php, in the 'cache' connection
'host' =&amp;gt; env('REDIS_CACHE_HOST', env('REDIS_HOST', '127.0.0.1')),
'port' =&amp;gt; env('REDIS_CACHE_PORT', env('REDIS_PORT', '6379')),&lt;/code&gt;&lt;code&gt;REDIS_CACHE_HOST=10.0.0.5
REDIS_CACHE_PORT=6379
REDIS_CACHE_LOCK_CONNECTION=cache&lt;/code&gt; Setting &lt;code&gt;REDIS_CACHE_LOCK_CONNECTION=cache&lt;/code&gt; moves the lock keys onto the same instance. I tested this with two local Redis servers: cache keys and the lock key landed on the second one and nothing on the first.&lt;/li&gt;
&lt;li&gt;Put a TTL on every cache key, even long ones. Avoid &lt;code&gt;Cache::forever&lt;/code&gt; and &lt;code&gt;rememberForever&lt;/code&gt; unless you are certain the data is small and bounded.&lt;/li&gt;
&lt;li&gt;Watch &lt;code&gt;used_memory&lt;/code&gt; and &lt;code&gt;evicted_keys&lt;/code&gt; in &lt;code&gt;INFO&lt;/code&gt;. A rising &lt;code&gt;evicted_keys&lt;/code&gt; with a falling hit rate means the cache is too small.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;code&gt;Cache::remember&lt;/code&gt; alone on an expensive, hot key.&lt;/li&gt;
&lt;li&gt;Assuming &lt;code&gt;Cache::flexible&lt;/code&gt; also handles the first fill.&lt;/li&gt;
&lt;li&gt;Waiting on a lock without handling &lt;code&gt;LockTimeoutException&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Calling &lt;code&gt;increment&lt;/code&gt; on a key you never created with a TTL.&lt;/li&gt;
&lt;li&gt;Setting &lt;code&gt;allkeys-lru&lt;/code&gt; on a Redis server that also holds queues or sessions.&lt;/li&gt;
&lt;li&gt;Leaving &lt;code&gt;maxmemory&lt;/code&gt; unset and finding out when the host runs out of RAM.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Warm the key on a schedule&lt;/strong&gt; (a scheduled command or a deploy step) so users never see a cold miss. Pair it with a TTL longer than the schedule interval.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add random jitter to TTLs&lt;/strong&gt; so many keys written together don't expire together. This is a common technique; I did not measure its effect here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis Cluster or managed Redis&lt;/strong&gt; when one node isn't enough. I did not test either.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-redis-caching-patterns-cache-aside-invalidation" rel="noopener noreferrer"&gt;Laravel Redis Caching Patterns, Part 1: Cache-Aside, Key Design, Invalidation and Tags&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 3: Deploy over SSH with Releases and Rollback&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-scheduler-not-running-cron-fixes" rel="noopener noreferrer"&gt;Laravel Scheduler Not Running: Cron and schedule:run Fixes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I need the lock if I use Cache::flexible?
&lt;/h3&gt;

&lt;p&gt;For the first fill of a key, yes (or warm it ahead of time). Flexible's own refresh is already guarded by an internal lock.&lt;/p&gt;

&lt;h3&gt;
  
  
  What should the lock TTL be?
&lt;/h3&gt;

&lt;p&gt;Longer than your slowest normal rebuild, short enough that a crashed process doesn't block others for long. As a starting point, a few times the normal rebuild time; measure your own queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I rely on Redis eviction instead of TTLs?
&lt;/h3&gt;

&lt;p&gt;Not with &lt;code&gt;volatile-*&lt;/code&gt; policies, because they only evict keys that have a TTL. With &lt;code&gt;allkeys-*&lt;/code&gt; it works, but then the instance should hold nothing you can't lose.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the memory test prove how much cache I can hold?
&lt;/h3&gt;

&lt;p&gt;No. It shows how Redis behaves at the limit under three policies. Real capacity depends on your value sizes, key count and Redis overhead, so measure &lt;code&gt;used_memory&lt;/code&gt; on your own data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://laravel.com/framework/docs/13.x/cache" rel="noopener noreferrer"&gt;Laravel 13.x documentation: Cache (atomic locks, flexible, increment)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/redis" rel="noopener noreferrer"&gt;Laravel documentation: Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://redis.io/docs/latest/develop/reference/eviction/" rel="noopener noreferrer"&gt;Redis documentation: Key eviction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/laravel/framework" rel="noopener noreferrer"&gt;laravel/framework source: Repository::flexible&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/laravel-redis-cache-stampede-locks-counters-memory" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>redis</category>
      <category>caching</category>
      <category>locks</category>
    </item>
    <item>
      <title>Laravel Redis Caching: Cache-Aside, Keys and Invalidation</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:24:06 +0000</pubDate>
      <link>https://dev.to/devtalk94/laravel-redis-caching-cache-aside-keys-and-invalidation-407a</link>
      <guid>https://dev.to/devtalk94/laravel-redis-caching-cache-aside-keys-and-invalidation-407a</guid>
      <description>&lt;p&gt;Most Laravel caching bugs are not about Redis. They are about what the code stores, how long it lives, and who removes it when the data changes. This is Part 1 of a two-part series on Redis caching in Laravel 13. Here we cover the basic read-through pattern, what Redis actually holds, and invalidation. &lt;a href="https://dev-talk.com/post/laravel-redis-cache-stampede-locks-counters-memory" rel="noopener noreferrer"&gt;Part 2&lt;/a&gt; covers cache stampedes, locks, counters and memory limits.&lt;/p&gt;

&lt;p&gt;Every example below was run on Laravel 13.40.0, PHP 8.3.6 with phpredis 5.3.7, and Redis 7.0.15. The outputs are copied from those runs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Laravel's docs say Redis caching needs either the PhpRedis extension or the &lt;code&gt;predis/predis&lt;/code&gt; package, and that PhpRedis is the default client. In &lt;code&gt;.env&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="na"&gt;CACHE_STORE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;redis&lt;/span&gt;
&lt;span class="na"&gt;REDIS_CLIENT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;phpredis&lt;/span&gt;
&lt;span class="na"&gt;REDIS_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;
&lt;span class="na"&gt;REDIS_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;
&lt;span class="na"&gt;REDIS_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6379&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now write one value and look at what Redis stores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product:42'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Widget'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db1 (cache connection): laravel-database-laravel-cache-product:42
db0 (default connection): []
TTL=600 TYPE=string
RAW: a:2:{s:2:"id";i:42;s:4:"name";s:6:"Widget";}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things to notice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The key has two prefixes.&lt;/strong&gt; &lt;code&gt;laravel-database-&lt;/code&gt; comes from the Redis connection options (&lt;code&gt;REDIS_PREFIX&lt;/code&gt;), and &lt;code&gt;laravel-cache-&lt;/code&gt; comes from &lt;code&gt;config/cache.php&lt;/code&gt; (&lt;code&gt;CACHE_PREFIX&lt;/code&gt;). Both default to your slugified &lt;code&gt;APP_NAME&lt;/code&gt;. The Laravel docs warn that two instances of the same app on one Redis server share the prefix and read each other's data, so give each its own &lt;code&gt;REDIS_PREFIX&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache keys live in Redis database 1.&lt;/strong&gt; The default &lt;code&gt;cache&lt;/code&gt; connection uses &lt;code&gt;REDIS_CACHE_DB&lt;/code&gt; (default &lt;code&gt;1&lt;/code&gt;), while the &lt;code&gt;default&lt;/code&gt; connection uses database 0.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The value is a PHP-serialized string with a TTL.&lt;/strong&gt; It is not JSON, so other languages can't read it, and what you store decides what you can safely unserialize later (see the model section below).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cache-aside with remember()
&lt;/h2&gt;

&lt;p&gt;The pattern: look in the cache, and on a miss load from the database and store the result. &lt;code&gt;Cache::remember&lt;/code&gt; does exactly that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Support&lt;/span&gt;\&lt;span class="nc"&gt;Facades&lt;/span&gt;\&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductReader&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"product:$id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;only&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Laravel docs describe it the same way: if the item does not exist, the closure runs and its result is stored. I counted closure executions across three calls with the same key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;value={"computed":true} closure_runs=1
value={"computed":true} closure_runs=1
value={"computed":true} closure_runs=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why the example returns false for "not found"
&lt;/h3&gt;

&lt;p&gt;I ran the closure three times in a row for four different return values and counted how often it executed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;null: closure ran 3 times in 3 calls
false: closure ran 1 times in 3 calls
empty-array: closure ran 1 times in 3 calls
zero: closure ran 1 times in 3 calls
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A closure that returns &lt;code&gt;null&lt;/code&gt; is never cached, so every request for a product that doesn't exist goes to the database. Returning &lt;code&gt;false&lt;/code&gt; (or any non-null placeholder) caches the "not found" answer for the TTL. Use a shorter TTL for negative results than for real ones so a newly created record doesn't stay invisible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache arrays, not Eloquent models
&lt;/h2&gt;

&lt;p&gt;This one is specific to Laravel 13. The default &lt;code&gt;config/cache.php&lt;/code&gt; now contains &lt;code&gt;'serializable_classes' =&amp;gt; false&lt;/code&gt;, and the upgrade guide says it was added to harden unserialization against gadget chain attacks if your &lt;code&gt;APP_KEY&lt;/code&gt; leaks. The effect on a cached model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user:model'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;get_class&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user:model'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// __PHP_Incomplete_Class&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model class on read: __PHP_Incomplete_Class
raw model value starts: O:15:"App\Models\User":36:{s:1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The write works, the read silently gives you an unusable object. There are two ways out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Store plain arrays&lt;/strong&gt; (what the upgrade guide recommends as the non-object option). They are smaller, they survive a class rename or refactor, and they don't depend on the unserialize allow-list:&lt;code&gt;raw array value: a:3:{s:2:"id";i:1;s:4:"name";s:3:"ann";s:5:"email";s:16:"ann@example.test";}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow-list the classes&lt;/strong&gt; you intentionally cache, as the upgrade guide shows:&lt;code&gt;// config/cache.php
'serializable_classes' =&amp;gt; [
App\Models\User::class,
],&lt;/code&gt; With that in place the same test returned &lt;code&gt;App\Models\User&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Apps upgraded from Laravel 12 may not have this key in their own &lt;code&gt;config/cache.php&lt;/code&gt;. In the Laravel 13.40 source, a missing key resolves to &lt;code&gt;null&lt;/code&gt; and the Redis store then calls plain &lt;code&gt;unserialize()&lt;/code&gt;. I read that in the code and did not run an upgraded app, so check your config file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Invalidate on write
&lt;/h2&gt;

&lt;p&gt;A TTL is a fallback, not an invalidation strategy. When the underlying record changes, remove the key yourself, after the database write has committed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;rename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$product&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;forget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"product:{$product-&amp;gt;id}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;after forget: NULL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next reader repopulates it through &lt;code&gt;remember&lt;/code&gt;. If you put the same value back immediately instead (&lt;code&gt;Cache::put&lt;/code&gt;), you avoid one miss but you also have to be sure the cached shape is identical to what the reader would build. Deleting is the simpler contract.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tags: group keys so you can flush them together
&lt;/h2&gt;

&lt;p&gt;When one change affects many keys (a product list, a category page, a search result), tags let you flush a group. Per the Laravel docs, tags are not supported by the &lt;code&gt;file&lt;/code&gt;, &lt;code&gt;dynamodb&lt;/code&gt;, &lt;code&gt;database&lt;/code&gt; or &lt;code&gt;storage&lt;/code&gt; drivers; Redis works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product:1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Widget'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'sale'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product:2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Gadget'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'users'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user:1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'ann'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product:1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                       &lt;span class="c1"&gt;// NULL: tagged items need their tags to be read&lt;/span&gt;
&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product:1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// 'Widget'&lt;/span&gt;

&lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;tags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'products'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;get without tags: NULL
get with tags   : 'Widget'
after flush products -&amp;gt; product:1=NULL, product:2=NULL, user:1='ann'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flushing the &lt;code&gt;products&lt;/code&gt; tag removed both products, including the one that also carried the &lt;code&gt;sale&lt;/code&gt; tag, and left the unrelated &lt;code&gt;users&lt;/code&gt; tag alone. Inside Redis, the keys of tagged items are namespaced with a hash, and each tag has its own bookkeeping key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;laravel-database-laravel-cache-&amp;lt;sha1&amp;gt;:user:1
laravel-database-laravel-cache-tag:sale:entries
laravel-database-laravel-cache-tag:users:entries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two practical consequences. You can't look up a tagged item by its plain key, so forgetting to pass the tags is a silent miss (shown above). And the leftover &lt;code&gt;tag:sale:entries&lt;/code&gt; key shows the bookkeeping isn't removed for every tag on a flush, so don't use tags for an unbounded set of one-off values. Prefer a small, fixed set of tag names.&lt;/p&gt;

&lt;h2&gt;
  
  
  Never call Cache::flush() on a shared database
&lt;/h2&gt;

&lt;p&gt;The docs say &lt;code&gt;Cache::flush()&lt;/code&gt; ignores your prefix and removes everything in the cache store. I put a key from "another application" in the same Redis database and flushed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mine after Cache::flush(): NULL
foreign key after flush: []  keys in db1: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The foreign key was gone. If several applications use one Redis server, give each its own database number (&lt;code&gt;REDIS_CACHE_DB&lt;/code&gt;) or its own server, and delete groups of keys with tags or &lt;code&gt;forget&lt;/code&gt; instead of flushing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key design
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Put the entity and the id in the key (&lt;code&gt;product:42&lt;/code&gt;), and anything that changes the result (&lt;code&gt;product:42:locale:en&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Don't put user input directly in a key without limiting its shape. Unbounded key names fill memory (Part 2).&lt;/li&gt;
&lt;li&gt;Keep the format in one place (a small class or enum), so reads and invalidation can't drift apart.&lt;/li&gt;
&lt;li&gt;Set a TTL on every cache key. Part 2 shows why a key without one can't be evicted under some memory policies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Caching Eloquent models in Laravel 13 without allow-listing the class.&lt;/li&gt;
&lt;li&gt;Returning &lt;code&gt;null&lt;/code&gt; for "not found" and wondering why the database still gets hit.&lt;/li&gt;
&lt;li&gt;Relying on TTL alone for data users expect to see change immediately.&lt;/li&gt;
&lt;li&gt;Reading a tagged item without its tags.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;Cache::flush()&lt;/code&gt; on a Redis database other apps share.&lt;/li&gt;
&lt;li&gt;Sharing one prefix between staging and production on the same Redis server. The docs note that changing a prefix later makes existing cached values and queued jobs under the old prefix be ignored, so choose it before go-live.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Predis&lt;/strong&gt; instead of PhpRedis, if you can't install the extension. Set &lt;code&gt;REDIS_CLIENT=predis&lt;/code&gt; and install the package. I only tested PhpRedis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP caching&lt;/strong&gt; (ETag, &lt;code&gt;Cache-Control&lt;/code&gt;) for responses that don't need a server-side cache at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The database or file store&lt;/strong&gt; for tiny apps. Redis becomes worthwhile when you need tags, atomic operations or multiple servers sharing one cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-redis-cache-stampede-locks-counters-memory" rel="noopener noreferrer"&gt;Laravel Redis Caching Patterns, Part 2: Stampede Protection, Locks, Counters and Memory Limits&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-env-configuration-env-vs-config" rel="noopener noreferrer"&gt;Laravel .env Configuration: env() vs config()&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Should I cache the query result or the final HTML/JSON?
&lt;/h3&gt;

&lt;p&gt;Cache the smallest thing that is expensive to compute and cheap to reuse. Query results as arrays are the safest default. Full responses are fine when the output is identical for all users; otherwise the key must include whatever varies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is a long TTL always better for hit rate?
&lt;/h3&gt;

&lt;p&gt;It raises the hit rate and the chance of serving stale data. If you invalidate on write, a long TTL is safe because writes keep the cache correct. If you can't invalidate precisely, keep the TTL short.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do cache keys and queue keys end up in different databases?
&lt;/h3&gt;

&lt;p&gt;The default &lt;code&gt;cache&lt;/code&gt; connection uses database 1 and the &lt;code&gt;default&lt;/code&gt; connection uses database 0. Logical databases share one Redis server's memory and settings, so this separates keys, not resources. Part 2 covers what that means for eviction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need Redis for caching at all?
&lt;/h3&gt;

&lt;p&gt;No. The &lt;code&gt;database&lt;/code&gt; or &lt;code&gt;file&lt;/code&gt; stores work. Redis adds speed, tags, atomic counters and locks that work across servers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://laravel.com/framework/docs/13.x/cache" rel="noopener noreferrer"&gt;Laravel 13.x documentation: Cache&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/redis" rel="noopener noreferrer"&gt;Laravel documentation: Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/upgrade" rel="noopener noreferrer"&gt;Laravel 13.x upgrade guide: Cache serializable_classes configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/laravel/framework" rel="noopener noreferrer"&gt;laravel/framework source: CacheManager, RedisStore&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/laravel-redis-caching-patterns-cache-aside-invalidation" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>redis</category>
      <category>caching</category>
      <category>performance</category>
    </item>
    <item>
      <title>Claude Code API Abuse: Hidden C2 and Data Theft Explained</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Tue, 17 Nov 2026 16:04:56 +0000</pubDate>
      <link>https://dev.to/devtalk94/claude-code-api-abuse-hidden-c2-and-data-theft-explained-3do</link>
      <guid>https://dev.to/devtalk94/claude-code-api-abuse-hidden-c2-and-data-theft-explained-3do</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 17 November 2026. Based on Darktrace's 12 November 2026 research and follow-up coverage. See&lt;/em&gt;&lt;em&gt;How this was checked&lt;/em&gt;&lt;em&gt;at the end.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Researchers at Darktrace showed that an attacker who already controls a developer's Linux machine and has stolen their Claude Console credentials can turn Claude Code into a remotely controlled implant. The command channel and the stolen data both travel through &lt;code&gt;api.anthropic.com&lt;/code&gt;, a destination most companies allow by default. Nothing in this is a bug in Claude, and Darktrace says it has not seen it in real attacks. It still matters, because it moves the problem from "block the bad domain" to "notice the odd behavior of an approved tool."&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick facts
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Detail&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Who&lt;/td&gt;
&lt;td&gt;Darktrace Signal Labs (Moishe Tajtelbaum and Sam Lister), blog post dated 12 November 2026&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What&lt;/td&gt;
&lt;td&gt;A lab proof of concept: Claude memory stores as a command channel, the Files API as an exfiltration path&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is it a vulnerability?&lt;/td&gt;
&lt;td&gt;No. Darktrace says it "does not rely on a vulnerability in the Claude platform"; no CVE&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Prerequisites&lt;/td&gt;
&lt;td&gt;A compromised device and stolen Claude Console credentials&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;In the wild?&lt;/td&gt;
&lt;td&gt;Not observed by Darktrace&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model used in the lab&lt;/td&gt;
&lt;td&gt;Claude Sonnet 4.5, non-interactive mode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Anthropic response&lt;/td&gt;
&lt;td&gt;None found. Help Net Security reports Darktrace shared the findings with Anthropic "as a courtesy"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How the lab attack worked
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Foothold and credentials.&lt;/strong&gt; After compromising a Linux device, a small shell payload (run through &lt;code&gt;dash&lt;/code&gt;) looked for a Claude Code installation and sent the user's Claude API and OAuth credentials to a staging server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The command channel.&lt;/strong&gt; Using those credentials, the attacker created a &lt;em&gt;memory store&lt;/em&gt; in the user's Claude Console workspace. Memory stores are collections of text files that agents read and update across sessions. Darktrace used three files: a heartbeat (check-ins), an input file (queued jobs) and an output file (results).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistence.&lt;/strong&gt; The payload used &lt;code&gt;systemd-run&lt;/code&gt; to create a transient service that repeatedly launched Claude Code processes. Help Net Security reports they ran with &lt;code&gt;--dangerously-skip-permissions&lt;/code&gt;, which turns off tool-use confirmation prompts. The first script was then discarded.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tasking in plain English.&lt;/strong&gt; Each process checked in, read the next job from the input file, ran it and wrote the result back. The operator gave goals, not commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Results.&lt;/strong&gt; Across nine jobs on a simulated Active Directory network, the agent found a host with FTP, SMB and SSH open, took files from an anonymous FTP share, generated 190 usernames, sprayed one password at the domain controller, found one valid account, located a 1 GB file on an SMB share, split it into three parts and uploaded them to the Files API.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why it is hard to see
&lt;/h2&gt;

&lt;p&gt;Darktrace's point is that the agent reads and writes the memory files through the same API endpoint it uses for inference, so the command traffic looks like normal Claude use. The process is an approved coding tool, the destination is a sanctioned provider, and no separate command server exists after the first stage. A firewall or proxy that allows &lt;code&gt;api.anthropic.com&lt;/code&gt; sees nothing unusual. Help Net Security quotes Bazalgette, who is cited alongside Darktrace's findings, as saying "approved is not the same as safe, and only behaviour tells you the difference."&lt;/p&gt;

&lt;h2&gt;
  
  
  What this is not
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is not a remote exploit. The attacker already needs a foothold and the credentials.&lt;/li&gt;
&lt;li&gt;It is not a prompt-injection or sandbox-escape result.&lt;/li&gt;
&lt;li&gt;It is one lab test on one platform. Darktrace says it has not reproduced the technique elsewhere. Help Net Security notes OpenAI has a comparable file-upload endpoint.&lt;/li&gt;
&lt;li&gt;The names and credentials in the published walkthrough are fictitious, so the IP address and account name in the write-ups are not indicators you can hunt for.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Treat AI platform keys like production credentials
&lt;/h3&gt;

&lt;p&gt;The attack starts with stolen credentials. Per Darktrace and the Cloud Security Alliance's analysis of the research:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prefer OAuth or identity federation over static API keys. In the Help Net Security summary of Darktrace's findings, a standard API key could reach memory stores, while OAuth credentials could not.&lt;/li&gt;
&lt;li&gt;Where static keys are unavoidable, make them short-lived and limited to a single workspace, and keep them out of shell history, dotfiles and environment variables.&lt;/li&gt;
&lt;li&gt;Look for credentials on developer machines. The CSA note points at &lt;code&gt;~/.claude/.credentials.json&lt;/code&gt;, &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; values and keys in shell history.&lt;/li&gt;
&lt;li&gt;Rotate keys on any machine you suspect was compromised.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Block unattended permission bypass
&lt;/h3&gt;

&lt;p&gt;The Claude Code documentation says &lt;code&gt;bypassPermissions&lt;/code&gt; mode skips permission prompts and should only be used in isolated environments such as containers or VMs. It also documents a setting that prevents it, best placed in managed settings so users cannot override it. On Linux, the documented location is &lt;code&gt;/etc/claude-code/managed-settings.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"permissions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"disableBypassPermissionsMode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"disable"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces the chance of a silent, prompt-free agent on your developers' machines. It does not stop an attacker who can run their own binary or use the API directly, so it is one layer, not a fix. I did not test this setting; it is taken from the documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Hunt for the process pattern
&lt;/h3&gt;

&lt;p&gt;Darktrace's detection advice is behavioral: correlate agent process launches with network activity, compare against a baseline, and watch for unusual command-line arguments and abnormal upload-to-download ratios to the API. A few starting points on Linux (my suggestions, not from the report, and I could not run them in my environment, so adapt them first):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Claude processes: who started them, how long they have run, and with what arguments&lt;/span&gt;
ps -eo pid,ppid,user,etime,args &lt;span class="o"&gt;|&lt;/span&gt; grep &lt;span class="s1"&gt;'[c]laude'&lt;/span&gt;

&lt;span class="c"&gt;# Transient services created with systemd-run&lt;/span&gt;
systemctl list-units --type=service --all &lt;span class="s1"&gt;'run-*'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Things worth alerting on: a Claude Code process started by &lt;code&gt;systemd-run&lt;/code&gt; or cron outside your approved automation, a Claude Code process running with &lt;code&gt;--dangerously-skip-permissions&lt;/code&gt; on a developer laptop, and an agent process spawning reconnaissance tools such as &lt;code&gt;nmap&lt;/code&gt;, &lt;code&gt;nc&lt;/code&gt; or &lt;code&gt;smbclient&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Review the workspace
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Check every Claude Console workspace for memory stores you do not recognize.&lt;/li&gt;
&lt;li&gt;Review Files API uploads for unexpected or large files.&lt;/li&gt;
&lt;li&gt;Remember that blocking &lt;code&gt;api.anthropic.com&lt;/code&gt; is unrealistic for teams that use it daily, which is why the monitoring above matters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The bigger lesson
&lt;/h2&gt;

&lt;p&gt;The same pattern applies to any approved service that can store data and run logic: a trusted destination hides a malicious conversation. The practical defenses are old ones, applied to a new kind of credential: least privilege, short-lived secrets, separate workspaces, and behavior-based detection. If your developers' laptops hold keys that can create storage and run an AI agent, those keys deserve the same protection as cloud admin tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/cursor-claude-code-extension-backdoor-what-to-check" rel="noopener noreferrer"&gt;Cursor and Claude Code Extension Backdoor: What to Check&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/git-security-release-cve-2026-111760" rel="noopener noreferrer"&gt;Git Security Release CVE-2026-111760: What to Update&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is this a Claude Code vulnerability?
&lt;/h3&gt;

&lt;p&gt;No. Darktrace says it uses legitimate features and requires prior device compromise and stolen credentials. There is no CVE and no patch to install.&lt;/p&gt;

&lt;h3&gt;
  
  
  Has it been used in real attacks?
&lt;/h3&gt;

&lt;p&gt;Darktrace says it has not observed the technique in the wild. The Cloud Security Alliance note expects key-stealing malware to add agent-tasking modules, but labels that an inference with no public evidence.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to stop using Claude Code?
&lt;/h3&gt;

&lt;p&gt;Nothing in the research says so. Protect the credentials, restrict permission bypass, and monitor agent behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it affect other AI coding tools?
&lt;/h3&gt;

&lt;p&gt;Darktrace tested one platform and has not reproduced it elsewhere. Any provider API that combines text storage with inference could allow a similar pattern, depending on how credentials are scoped.&lt;/p&gt;

&lt;h2&gt;
  
  
  update log
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;17 November 2026:&lt;/strong&gt; first published.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; any Anthropic statement or product change (alerts on new memory stores, controls for inference-only keys), reports of use in real attacks, and Darktrace's detection content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://darktrace.com/blog/living-off-the-ai-shared-memories-as-a-covert-c2-channel" rel="noopener noreferrer"&gt;Darktrace: Living off the AI: Shared Memories as a Covert C2 Channel&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.helpnetsecurity.com/?p=391055" rel="noopener noreferrer"&gt;Help Net Security: Stolen Claude API keys can turn Claude Code into a remote-controlled implant&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://labs.cloudsecurityalliance.org/research/csa-research-note-coding-agent-api-key-implant-20261113-csa/" rel="noopener noreferrer"&gt;Cloud Security Alliance: Living Off the Model API: Stolen Claude Keys as Agent Implants&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cybersecuritynews.com/claude-codes-trusted-api/" rel="noopener noreferrer"&gt;Cyber Security News: Claude Code's Trusted API Could Help Attackers Hide Malicious Commands and Data Theft&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/permissions.md" rel="noopener noreferrer"&gt;Claude Code documentation: Configure permissions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.claude.com/docs/en/managed-settings.md" rel="noopener noreferrer"&gt;Claude Code documentation: Deploy managed settings&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/claude-code-api-abuse-hidden-c2-data-theft" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claudecode</category>
      <category>darktrace</category>
      <category>c2</category>
      <category>dataexfiltration</category>
    </item>
    <item>
      <title>GitHub Actions for Laravel: Run Tests with PHP Matrix, MySQL</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:16:19 +0000</pubDate>
      <link>https://dev.to/devtalk94/github-actions-for-laravel-run-tests-with-php-matrix-mysql-14ik</link>
      <guid>https://dev.to/devtalk94/github-actions-for-laravel-run-tests-with-php-matrix-mysql-14ik</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 12 November 2026. See the&lt;/em&gt;&lt;em&gt;update log&lt;/em&gt;&lt;em&gt;at the end.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A Laravel test suite that only runs on your laptop will eventually fail on the server for a reason you cannot reproduce: a missing PHP extension, a different PHP version, or a MySQL behavior that SQLite hides. A CI workflow fixes that by running the same checks in a clean machine on every push and pull request. This is Part 1 of a three-part series on a Laravel pipeline in GitHub Actions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 (this article):&lt;/strong&gt; run the tests on a PHP version matrix with a MySQL service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 2:&lt;/strong&gt; &lt;a href="https://dev-talk.com/post/github-actions-laravel-cache-composer-npm" rel="noopener noreferrer"&gt;cache Composer and npm&lt;/a&gt; so runs are faster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 3:&lt;/strong&gt; &lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;deploy over SSH&lt;/a&gt; with releases, an atomic switch and rollback.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The workflow below passes &lt;code&gt;actionlint&lt;/code&gt; and GitHub's workflow schema check, and its shell steps were run locally against a real MySQL server on Laravel 13.40.0. I could not run &lt;code&gt;php artisan test&lt;/code&gt; itself or the workflow on GitHub's runners, and the "How this was checked" section at the end lists exactly what that means.&lt;/p&gt;

&lt;h2&gt;
  
  
  The workflow
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;.github/workflows/ci.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Tests&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;main&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.workflow }}-${{ github.ref }}&lt;/span&gt;
  &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ github.event_name == 'pull_request' }}&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;tests&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;PHP ${{ matrix.php }}&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;

    &lt;span class="na"&gt;strategy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;fail-fast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="na"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;php&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'8.3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'8.4'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;mysql&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql:8.4&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;MYSQL_ROOT_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;password&lt;/span&gt;
          &lt;span class="na"&gt;MYSQL_DATABASE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;testing&lt;/span&gt;
        &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;3306:3306&lt;/span&gt;
        &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;
          &lt;span class="s"&gt;--health-cmd="mysqladmin ping -ppassword"&lt;/span&gt;
          &lt;span class="s"&gt;--health-interval=10s&lt;/span&gt;
          &lt;span class="s"&gt;--health-timeout=5s&lt;/span&gt;
          &lt;span class="s"&gt;--health-retries=5&lt;/span&gt;

    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;DB_CONNECTION&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mysql&lt;/span&gt;
      &lt;span class="na"&gt;DB_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;127.0.0.1&lt;/span&gt;
      &lt;span class="na"&gt;DB_PORT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3306&lt;/span&gt;
      &lt;span class="na"&gt;DB_DATABASE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;testing&lt;/span&gt;
      &lt;span class="na"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;root&lt;/span&gt;
      &lt;span class="na"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;password&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check out code&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v7&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;persist-credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up PHP&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;shivammathur/setup-php@v2&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;php-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ matrix.php }}&lt;/span&gt;
          &lt;span class="na"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mbstring, pdo_mysql, zip, pcntl&lt;/span&gt;
          &lt;span class="na"&gt;coverage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;none&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install Composer dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer install --prefer-dist --no-interaction --no-progress&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Prepare the application&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;cp .env.example .env&lt;/span&gt;
          &lt;span class="s"&gt;php artisan key:generate&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run tests&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php artisan test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What each part does
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Triggers, permissions and concurrency
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;on: push&lt;/code&gt; to &lt;code&gt;main&lt;/code&gt; plus &lt;code&gt;pull_request&lt;/code&gt; gives you a check on every PR and on every merge.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;permissions: contents: read&lt;/code&gt; limits what the job's &lt;code&gt;GITHUB_TOKEN&lt;/code&gt; can do. Laravel's own starter workflow sets the same thing. Tests only need to read the code.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;concurrency&lt;/code&gt; groups runs by workflow and branch. GitHub's docs say a group holds at most one running and one pending run, and that &lt;code&gt;cancel-in-progress: true&lt;/code&gt; also cancels the one that is running. Here that applies to pull requests only, so a new push to a PR cancels the stale run, while runs on &lt;code&gt;main&lt;/code&gt; are never cancelled. That matters in Part 3, when &lt;code&gt;main&lt;/code&gt; pushes start deployments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The matrix
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;matrix.php&lt;/code&gt; runs the job once per PHP version. Laravel 13 requires PHP 8.3 or newer, so 8.3 and 8.4 are a sensible floor and a current version; Laravel's own starter workflow also includes 8.5, and you can add it. &lt;code&gt;fail-fast: false&lt;/code&gt; lets every version finish, so one failure doesn't hide a second one on another version.&lt;/p&gt;

&lt;h3&gt;
  
  
  The MySQL service container
&lt;/h3&gt;

&lt;p&gt;GitHub starts &lt;code&gt;mysql:8.4&lt;/code&gt; next to the job. Because the job runs directly on the runner and not in a container, the docs say you reach the service at &lt;code&gt;localhost&lt;/code&gt; (or &lt;code&gt;127.0.0.1&lt;/code&gt;) on the mapped port, which is why &lt;code&gt;ports&lt;/code&gt; maps 3306 and &lt;code&gt;DB_HOST&lt;/code&gt; is &lt;code&gt;127.0.0.1&lt;/code&gt;. The &lt;code&gt;options&lt;/code&gt; block is the health check pattern from GitHub's service container docs (their example uses PostgreSQL and &lt;code&gt;pg_isready&lt;/code&gt;; I adapted it to &lt;code&gt;mysqladmin ping&lt;/code&gt;). Without it, the first test can start before MySQL accepts connections and fail with a connection error.&lt;/p&gt;

&lt;p&gt;Pick the MySQL image tag that matches production. If you run MariaDB, use the MariaDB image and its own health command instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  setup-php
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;shivammathur/setup-php&lt;/code&gt; installs the PHP version and extensions and a current Composer by default. &lt;code&gt;coverage: none&lt;/code&gt; disables Xdebug and PCOV; the action's README notes that Xdebug is enabled by default on Ubuntu images and recommends turning it off if you don't need coverage, which speeds up PHP. Add &lt;code&gt;pdo_mysql&lt;/code&gt; and anything else your app needs to the &lt;code&gt;extensions&lt;/code&gt; list. The extension list is where "works locally, fails in CI" most often starts.&lt;/p&gt;

&lt;h3&gt;
  
  
  checkout and persist-credentials
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;actions/checkout&lt;/code&gt; normally leaves the auth token in the local git config for the rest of the job, so scripts can run authenticated git commands. &lt;code&gt;persist-credentials: false&lt;/code&gt; opts out. Your tests don't push to the repository, so there is no reason to keep it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the database setup before trusting it
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Prepare the application&lt;/code&gt; step and a migration run were executed against a local MySQL server with the same environment variables the job sets (the port was 3307 locally, not 3306):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   INFO  Application key set successfully.

Creating migration table ...................................... DONE
0001_01_01_000000_create_users_table .......................... DONE
0001_01_01_000001_create_cache_table .......................... DONE
0001_01_01_000002_create_jobs_table ........................... DONE
2026_11_08_000001_add_is_admin_to_users ....................... DONE
tables: cache cache_locks failed_jobs job_batches jobs migrations password_reset_tokens sessions users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That confirms the &lt;code&gt;.env.example&lt;/code&gt; copy, key generation and the &lt;code&gt;DB_*&lt;/code&gt; variables reach MySQL. One gotcha is worth checking in your own repository: the &lt;code&gt;phpunit.xml&lt;/code&gt; in the Laravel starter project sets &lt;code&gt;DB_CONNECTION&lt;/code&gt; to &lt;code&gt;sqlite&lt;/code&gt; and &lt;code&gt;DB_DATABASE&lt;/code&gt; to &lt;code&gt;:memory:&lt;/code&gt;. If you want your tests to run on the MySQL service, remove or comment out those two lines (or use a separate &lt;code&gt;phpunit.ci.xml&lt;/code&gt; and pass it to PHPUnit). I did not run PHPUnit, so I can't tell you which value wins if both are present. Don't leave it to chance: the fix above is unambiguous.&lt;/p&gt;

&lt;p&gt;Also decide which database you want. SQLite in memory is faster and is a fine default for most suites. MySQL in CI is worth it when your code depends on MySQL behavior: JSON columns, full-text search, collations, or raw queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt;&lt;code&gt;composer.lock&lt;/code&gt;&lt;strong&gt;committed.&lt;/strong&gt; CI then installs whatever versions are newest that day. Commit the lock file for applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Missing PHP extension.&lt;/strong&gt; Add it to &lt;code&gt;extensions&lt;/code&gt;; don't install it from a shell step.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using the service name as the host.&lt;/strong&gt; &lt;code&gt;DB_HOST: mysql&lt;/code&gt; works only when the job itself runs in a container. On the runner, use &lt;code&gt;127.0.0.1&lt;/code&gt; with a mapped port.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping the health check.&lt;/strong&gt; Intermittent connection errors at the start of the run usually mean the database wasn't ready.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Putting real credentials in the workflow.&lt;/strong&gt; The MySQL password above is a throwaway for a container that disappears after the job. Real secrets belong in GitHub's secrets store (Part 3).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQLite only:&lt;/strong&gt; remove the &lt;code&gt;services&lt;/code&gt; block and the &lt;code&gt;DB_*&lt;/code&gt; variables and keep Laravel's default &lt;code&gt;phpunit.xml&lt;/code&gt;. Simplest and fastest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel tests:&lt;/strong&gt; &lt;code&gt;php artisan test --parallel&lt;/code&gt; if your suite supports it. Test it locally first; shared databases need care.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static analysis and style checks:&lt;/strong&gt; add Pint or PHPStan as separate jobs so a style failure doesn't hide a test failure.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-cache-composer-npm" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 2: Cache Composer and npm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 3: Deploy over SSH with Releases and Rollback&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-env-configuration-env-vs-config" rel="noopener noreferrer"&gt;Laravel .env Configuration: env() vs config()&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Do I need a matrix?
&lt;/h3&gt;

&lt;p&gt;Only if you support more than one PHP version. If production runs one version, test that one, and add the next version when you plan to upgrade.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why &lt;code&gt;cp .env.example .env&lt;/code&gt; in CI?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;.env&lt;/code&gt; is not committed. The example file gives Laravel a baseline, &lt;code&gt;key:generate&lt;/code&gt; adds an application key, and the job-level &lt;code&gt;DB_*&lt;/code&gt; variables are already in the process environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I run the workflow locally?
&lt;/h3&gt;

&lt;p&gt;Tools like &lt;code&gt;act&lt;/code&gt; exist for that. I did not test one. What I did instead was run each shell step locally and lint the file, which catches most mistakes before a push. &lt;code&gt;actionlint&lt;/code&gt; is a quick linter for workflow files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should lint and static analysis run in the same job?
&lt;/h3&gt;

&lt;p&gt;Separate jobs are easier to read: a style failure then doesn't hide a test failure, and the jobs run in parallel. The trade-off is one more runner start-up per job.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update log&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;12 November 2026:&lt;/strong&gt; first version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; the major versions of &lt;code&gt;actions/checkout&lt;/code&gt; and &lt;code&gt;shivammathur/setup-php&lt;/code&gt;, the PHP versions in Laravel's own &lt;code&gt;tests.yml&lt;/code&gt;, the default &lt;code&gt;phpunit.xml&lt;/code&gt; database lines, and the Actions concurrency docs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/actions/checkout" rel="noopener noreferrer"&gt;actions/checkout README&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/shivammathur/setup-php" rel="noopener noreferrer"&gt;shivammathur/setup-php README&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/laravel/laravel/blob/master/.github/workflows/tests.yml" rel="noopener noreferrer"&gt;laravel/laravel: tests.yml and phpunit.xml&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/actions/tutorials/use-containerized-services/create-postgresql-service-containers" rel="noopener noreferrer"&gt;GitHub Docs: Creating PostgreSQL service containers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/enterprise-server@3.14/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency" rel="noopener noreferrer"&gt;GitHub Docs: Control the concurrency of workflows and jobs (Enterprise Server 3.14 page)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rhysd/actionlint" rel="noopener noreferrer"&gt;actionlint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/github-actions-laravel-run-tests-php-matrix-mysql" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>laravel</category>
      <category>cicd</category>
      <category>mysql</category>
    </item>
    <item>
      <title>Cache Composer and npm in GitHub Actions for Laravel</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:15:51 +0000</pubDate>
      <link>https://dev.to/devtalk94/cache-composer-and-npm-in-github-actions-for-laravel-3b7b</link>
      <guid>https://dev.to/devtalk94/cache-composer-and-npm-in-github-actions-for-laravel-3b7b</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 12 November 2026. See the&lt;/em&gt;&lt;em&gt;update log&lt;/em&gt;&lt;em&gt;at the end.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most of the time in a Laravel CI run goes to downloading packages: Composer dependencies on every run, and npm packages whenever you build front-end assets. Each run starts on a clean machine, so without a cache the same files are fetched again and again. This is Part 2 of the series. &lt;a href="https://dev-talk.com/post/github-actions-laravel-run-tests-php-matrix-mysql" rel="noopener noreferrer"&gt;Part 1&lt;/a&gt; built the test workflow; here we add caching to it, and &lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;Part 3&lt;/a&gt; reuses the same steps in the deploy job.&lt;/p&gt;

&lt;p&gt;I did not time any run, so there are no speed-up numbers here. What follows is the configuration, why each line exists, and how to confirm the cache is working in your own logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to cache, and what not to
&lt;/h2&gt;

&lt;p&gt;Cache the package manager's &lt;strong&gt;download cache&lt;/strong&gt;, not the installed &lt;code&gt;vendor&lt;/code&gt; directory. The &lt;code&gt;setup-php&lt;/code&gt; README says it plainly: do not cache &lt;code&gt;vendor&lt;/code&gt; with &lt;code&gt;actions/cache&lt;/code&gt;, because that has side effects. The download cache is safe, since &lt;code&gt;composer install&lt;/code&gt; still runs and builds a correct &lt;code&gt;vendor&lt;/code&gt; from the lock file, it just skips the downloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Composer
&lt;/h2&gt;

&lt;p&gt;Add two steps before &lt;code&gt;composer install&lt;/code&gt; in the test job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Find the Composer cache directory&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer-cache&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "dir=$(composer config cache-files-dir)" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Cache Composer downloads&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/cache@v6&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.composer-cache.outputs.dir }}&lt;/span&gt;
          &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer-${{ runner.os }}-php${{ matrix.php }}-${{ hashFiles('composer.lock') }}&lt;/span&gt;
          &lt;span class="na"&gt;restore-keys&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;composer-${{ runner.os }}-php${{ matrix.php }}-&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install Composer dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer install --prefer-dist --no-interaction --no-progress&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first step asks Composer where its cache lives instead of hardcoding a path. Running that same command from the workflow file locally printed a path ending in &lt;code&gt;composer/files&lt;/code&gt;, and the step wrote it as &lt;code&gt;dir=...&lt;/code&gt; into the step output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dir=&amp;lt;home&amp;gt;/composer/files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second step is &lt;code&gt;actions/cache&lt;/code&gt; (v6 at the time of writing). It restores the directory at the start and saves it when the job ends successfully.&lt;/p&gt;

&lt;h3&gt;
  
  
  How the key works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;key&lt;/code&gt; has the OS, the PHP version from the matrix and a hash of &lt;code&gt;composer.lock&lt;/code&gt;. When you change a dependency, the hash changes, so you get a fresh cache entry.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;restore-keys&lt;/code&gt; is a list of prefixes tried in order when the exact key isn't found. After a lock file change, the job restores the most recent cache for the same OS and PHP version, so most packages are still local and Composer only downloads what changed. The action's README describes this as restoring a stale cache when there is no exact match.&lt;/li&gt;
&lt;li&gt;The PHP version is in the key so each matrix entry has its own cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;cache-hit&lt;/code&gt; output is &lt;code&gt;true&lt;/code&gt; only for an exact key match, and &lt;code&gt;false&lt;/code&gt; when a &lt;code&gt;restore-keys&lt;/code&gt; entry or nothing was restored, per the action's README. A partial restore is normal and good.&lt;/p&gt;

&lt;h2&gt;
  
  
  npm
&lt;/h2&gt;

&lt;p&gt;If the job builds assets (Part 3 does), &lt;code&gt;actions/setup-node&lt;/code&gt; can cache npm for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Node.js&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v7&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'24'&lt;/span&gt;
          &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build front-end assets&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;npm ci&lt;/span&gt;
          &lt;span class="s"&gt;npm run build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;cache: npm&lt;/code&gt; the action caches npm's package data and, according to its README, looks for &lt;code&gt;package-lock.json&lt;/code&gt; (or &lt;code&gt;npm-shrinkwrap.json&lt;/code&gt;, &lt;code&gt;yarn.lock&lt;/code&gt;) in the repository root and uses its hash as part of the key. If your lock file is somewhere else, set &lt;code&gt;cache-dependency-path&lt;/code&gt;. Use &lt;code&gt;npm ci&lt;/code&gt;, not &lt;code&gt;npm install&lt;/code&gt;: it installs exactly what the lock file says and fails if &lt;code&gt;package.json&lt;/code&gt; and the lock file disagree.&lt;/p&gt;

&lt;p&gt;Read the &lt;code&gt;setup-node&lt;/code&gt; README for your version before relying on defaults. It describes automatic npm caching when &lt;code&gt;package.json&lt;/code&gt; has a &lt;code&gt;packageManager&lt;/code&gt; field set to npm, and a &lt;code&gt;package-manager-cache&lt;/code&gt; option to turn that off. Being explicit with &lt;code&gt;cache: npm&lt;/code&gt; avoids depending on that behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to confirm it works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Push a commit. The first run should report that no cache was found for your key, and the post-job step saves one.&lt;/li&gt;
&lt;li&gt;Push a commit that doesn't touch &lt;code&gt;composer.lock&lt;/code&gt;. The cache step should report a hit on the exact key, and Composer should install from local files.&lt;/li&gt;
&lt;li&gt;Change a dependency. You should see a restore through &lt;code&gt;restore-keys&lt;/code&gt; (not an exact hit), then a new cache saved under the new key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The exact log wording belongs to the action and can change, so look at the cache step in the run log rather than searching for a fixed string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits and gotchas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Size and eviction.&lt;/strong&gt; The action's README says a repository can hold up to 10 GB of caches, with older entries evicted by last access, and caches not accessed within a week are evicted as well. A small project may never notice; a busy monorepo might.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caches don't update.&lt;/strong&gt; The tips document in the &lt;code&gt;cache&lt;/code&gt; repository states that a cache is immutable. If the key matches, nothing is saved again. That is why the lock file hash goes in the key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch scope.&lt;/strong&gt; The README says caches are scoped to the key, version and branch, and the default branch's cache is available to other branches. A cache written on a feature branch is not visible to other feature branches, so runs on &lt;code&gt;main&lt;/code&gt; are what warm the cache for everyone else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A missing lock file means a useless key.&lt;/strong&gt; &lt;code&gt;hashFiles('composer.lock')&lt;/code&gt; is empty if the file doesn't exist, so the key never changes. Commit your lock files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runner version.&lt;/strong&gt; The README notes &lt;code&gt;actions/cache&lt;/code&gt; v5 and newer run on Node 24 and need Actions Runner 2.327.1 or newer. This only matters on self-hosted runners; GitHub-hosted runners are kept current.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Built-in cache in other setup actions.&lt;/strong&gt; &lt;code&gt;setup-node&lt;/code&gt; has its own as shown above. For Composer, the explicit &lt;code&gt;actions/cache&lt;/code&gt; step is what the &lt;code&gt;setup-php&lt;/code&gt; docs show.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache the PHP extensions too.&lt;/strong&gt; The &lt;code&gt;setup-php&lt;/code&gt; README has a section on caching extensions. It helps when you compile extensions from PECL, and does little if you only use ones bundled with the image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skip work instead of caching it.&lt;/strong&gt; Run the full suite in pull requests, but skip jobs that don't matter for a change with path filters in &lt;code&gt;on:&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Caching &lt;code&gt;vendor&lt;/code&gt; instead of Composer's download directory.&lt;/li&gt;
&lt;li&gt;Using a key without the lock file hash, so the cache is stale forever.&lt;/li&gt;
&lt;li&gt;Using a key that changes on every run (a timestamp or run number), so nothing is ever restored.&lt;/li&gt;
&lt;li&gt;Forgetting the PHP version in the key when the matrix runs several versions.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;npm install&lt;/code&gt; in CI, which can change the lock file and produce different results from one run to another.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-run-tests-php-matrix-mysql" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 1: Run Tests with a PHP Matrix and MySQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 3: Deploy over SSH with Releases and Rollback&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Should the cache step go before or after setup-php?
&lt;/h3&gt;

&lt;p&gt;After. The cache path comes from &lt;code&gt;composer config cache-files-dir&lt;/code&gt;, so Composer must already exist, and &lt;code&gt;setup-php&lt;/code&gt; installs it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What if I suspect a bad cache entry?
&lt;/h3&gt;

&lt;p&gt;Change the key prefix (for example &lt;code&gt;composer-v2-...&lt;/code&gt;). Entries are immutable, so a new prefix is the simplest way to start from an empty cache. You can also delete caches from the repository's Actions settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does the deploy job in Part 3 reuse this cache?
&lt;/h3&gt;

&lt;p&gt;It uses the same key format with PHP 8.4, so it should match the entry the PHP 8.4 test job saved, subject to the branch scope rules above. I did not observe this on GitHub, so check the cache step in your own deploy log.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update log&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;12 November 2026:&lt;/strong&gt; first version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; the current major versions of &lt;code&gt;actions/cache&lt;/code&gt; and &lt;code&gt;actions/setup-node&lt;/code&gt;, the cache size and eviction limits, and the &lt;code&gt;setup-node&lt;/code&gt; automatic caching defaults.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/actions/cache" rel="noopener noreferrer"&gt;actions/cache README, examples and tips&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/actions/setup-node" rel="noopener noreferrer"&gt;actions/setup-node README&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/shivammathur/setup-php" rel="noopener noreferrer"&gt;shivammathur/setup-php README: Cache Composer Dependencies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rhysd/actionlint" rel="noopener noreferrer"&gt;actionlint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/github-actions-laravel-cache-composer-npm" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>githubactions</category>
      <category>laravel</category>
      <category>caching</category>
      <category>composer</category>
    </item>
    <item>
      <title>Deploy Laravel with GitHub Actions over SSH</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:15:13 +0000</pubDate>
      <link>https://dev.to/devtalk94/deploy-laravel-with-github-actions-over-ssh-4b3e</link>
      <guid>https://dev.to/devtalk94/deploy-laravel-with-github-actions-over-ssh-4b3e</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 12 November 2026. See the&lt;/em&gt;&lt;em&gt;update log&lt;/em&gt;&lt;em&gt;at the end.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The simplest GitHub Actions deploy is "SSH in, &lt;code&gt;git pull&lt;/code&gt;, run a few commands". It works until a migration fails halfway, or a request arrives while files are half-updated, or you need to go back to yesterday's code. This final part of the series uses a releases directory instead: each deploy builds a new directory, runs migrations, warms the caches, and only then switches a &lt;code&gt;current&lt;/code&gt; symlink. If anything before the switch fails, the live site is untouched. It builds on &lt;a href="https://dev-talk.com/post/github-actions-laravel-run-tests-php-matrix-mysql" rel="noopener noreferrer"&gt;Part 1 (tests)&lt;/a&gt; and &lt;a href="https://dev-talk.com/post/github-actions-laravel-cache-composer-npm" rel="noopener noreferrer"&gt;Part 2 (caching)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I ran the deploy job's shell steps and the server script locally, against a real MySQL server, with a stand-in for &lt;code&gt;ssh&lt;/code&gt;. The SSH transport itself, the GitHub runners and the web server were not part of that test, which is spelled out at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  The layout on the server
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/var/www/app/
  releases/
    20261112101500-abc1234/     one directory per deploy
    20261112113000-def7654/
  shared/
    .env                        production configuration
    storage/                    logs, cache, sessions, uploads
  current -&amp;gt; releases/20261112113000-def7654
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point your web server's document root at &lt;code&gt;/var/www/app/current/public&lt;/code&gt;. Everything that must survive a deploy (&lt;code&gt;.env&lt;/code&gt; and &lt;code&gt;storage&lt;/code&gt;) lives in &lt;code&gt;shared&lt;/code&gt; and is linked into each release.&lt;/p&gt;

&lt;h3&gt;
  
  
  One-time server setup
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create a deploy user and give it write access to &lt;code&gt;/var/www/app&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;shared/.env&lt;/code&gt; with the production settings and &lt;code&gt;shared/storage&lt;/code&gt; with the usual Laravel subfolders (&lt;code&gt;app&lt;/code&gt;, &lt;code&gt;framework/cache&lt;/code&gt;, &lt;code&gt;framework/sessions&lt;/code&gt;, &lt;code&gt;framework/views&lt;/code&gt;, &lt;code&gt;logs&lt;/code&gt;). Make them writable by the user that runs PHP-FPM.&lt;/li&gt;
&lt;li&gt;Generate a dedicated SSH key pair for deployments, put the public key in the deploy user's &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt;, and use the private key as a GitHub secret. Don't reuse your personal key.&lt;/li&gt;
&lt;li&gt;Get the server's host key line, for example from your own machine with &lt;code&gt;ssh-keyscan -t ed25519 your.server.example&lt;/code&gt;, and compare its fingerprint with the server's before trusting it. That line becomes a secret too.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  GitHub setup
&lt;/h3&gt;

&lt;p&gt;Create an environment named &lt;code&gt;production&lt;/code&gt; in the repository settings and add four secrets to it: &lt;code&gt;DEPLOY_HOST&lt;/code&gt;, &lt;code&gt;DEPLOY_USER&lt;/code&gt;, &lt;code&gt;DEPLOY_SSH_KEY&lt;/code&gt; and &lt;code&gt;DEPLOY_KNOWN_HOSTS&lt;/code&gt;. GitHub's environment docs say environment secrets are available only to jobs that use that environment, and only after its protection rules pass. You can add required reviewers there if you want a human to approve each deploy, plus a wait timer and a restriction on which branches may deploy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The deploy job
&lt;/h2&gt;

&lt;p&gt;Add this job to the workflow from Parts 1 and 2 (same file, same indentation as &lt;code&gt;tests&lt;/code&gt;). It runs only for pushes to &lt;code&gt;main&lt;/code&gt;, and only after the tests pass:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deploy to production&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tests&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'push' &amp;amp;&amp;amp; github.ref == 'refs/heads/main'&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;

    &lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deploy-production&lt;/span&gt;
      &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;APP_DIR&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/var/www/app&lt;/span&gt;

    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check out code&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v7&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;persist-credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up PHP&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;shivammathur/setup-php@v2&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;php-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'8.4'&lt;/span&gt;
          &lt;span class="na"&gt;coverage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;none&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Find the Composer cache directory&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer-cache&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "dir=$(composer config cache-files-dir)" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Cache Composer downloads&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/cache@v6&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.composer-cache.outputs.dir }}&lt;/span&gt;
          &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer-${{ runner.os }}-php8.4-${{ hashFiles('composer.lock') }}&lt;/span&gt;
          &lt;span class="na"&gt;restore-keys&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
            &lt;span class="s"&gt;composer-${{ runner.os }}-php8.4-&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install production dependencies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;composer install --no-dev --prefer-dist --no-interaction --no-progress --optimize-autoloader&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set up Node.js&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v7&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'24'&lt;/span&gt;
          &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Build front-end assets&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;npm ci&lt;/span&gt;
          &lt;span class="s"&gt;npm run build&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Configure SSH&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;DEPLOY_HOST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DEPLOY_HOST }}&lt;/span&gt;
          &lt;span class="na"&gt;DEPLOY_USER&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DEPLOY_USER }}&lt;/span&gt;
          &lt;span class="na"&gt;DEPLOY_SSH_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DEPLOY_SSH_KEY }}&lt;/span&gt;
          &lt;span class="na"&gt;DEPLOY_KNOWN_HOSTS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.DEPLOY_KNOWN_HOSTS }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;set -euo pipefail&lt;/span&gt;
          &lt;span class="s"&gt;umask 077&lt;/span&gt;
          &lt;span class="s"&gt;mkdir -p ~/.ssh&lt;/span&gt;
          &lt;span class="s"&gt;printf '%s\n' "$DEPLOY_SSH_KEY" &amp;gt; ~/.ssh/deploy_key&lt;/span&gt;
          &lt;span class="s"&gt;printf '%s\n' "$DEPLOY_KNOWN_HOSTS" &amp;gt; ~/.ssh/known_hosts&lt;/span&gt;
          &lt;span class="s"&gt;cat &amp;gt; ~/.ssh/config &amp;lt;&amp;lt;EOF&lt;/span&gt;
          &lt;span class="s"&gt;Host deploy&lt;/span&gt;
            &lt;span class="s"&gt;HostName $DEPLOY_HOST&lt;/span&gt;
            &lt;span class="s"&gt;User $DEPLOY_USER&lt;/span&gt;
            &lt;span class="s"&gt;IdentityFile ~/.ssh/deploy_key&lt;/span&gt;
            &lt;span class="s"&gt;IdentitiesOnly yes&lt;/span&gt;
            &lt;span class="s"&gt;StrictHostKeyChecking yes&lt;/span&gt;
          &lt;span class="s"&gt;EOF&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Upload the release&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;set -euo pipefail&lt;/span&gt;
          &lt;span class="s"&gt;RELEASE="$(date -u +%Y%m%d%H%M%S)-${GITHUB_SHA::7}"&lt;/span&gt;
          &lt;span class="s"&gt;echo "RELEASE=$RELEASE" &amp;gt;&amp;gt; "$GITHUB_ENV"&lt;/span&gt;
          &lt;span class="s"&gt;tar --exclude=./.git --exclude=./node_modules --exclude=./tests -czf - . \&lt;/span&gt;
            &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="s"&gt;ssh deploy "mkdir -p '$APP_DIR/releases/$RELEASE' &amp;amp;&amp;amp; tar -xzf - -C '$APP_DIR/releases/$RELEASE'"&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Activate the release&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ssh deploy "APP_DIR='$APP_DIR' RELEASE='$RELEASE' bash -s" &amp;lt; deploy/activate.sh&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Points worth knowing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;needs: tests&lt;/code&gt; and the &lt;code&gt;if&lt;/code&gt; condition mean pull requests never deploy and a failing test job blocks the deploy.&lt;/li&gt;
&lt;li&gt;The job-level &lt;code&gt;concurrency&lt;/code&gt; group has &lt;code&gt;cancel-in-progress: false&lt;/code&gt;. Per GitHub's docs a group has at most one running and one pending run, so two quick merges queue instead of fighting over the server, and a deploy that is running is never cancelled halfway.&lt;/li&gt;
&lt;li&gt;Secrets are passed through &lt;code&gt;env&lt;/code&gt; and read as shell variables, not pasted into the script text with &lt;code&gt;${{ }}&lt;/code&gt;. That keeps secret values out of the generated script.&lt;/li&gt;
&lt;li&gt;The workflow builds on the runner (&lt;code&gt;composer install --no-dev&lt;/code&gt;, &lt;code&gt;npm run build&lt;/code&gt;) and ships the result, so the server needs PHP and Composer's output, not Node or build tools.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;StrictHostKeyChecking yes&lt;/code&gt; together with the pinned &lt;code&gt;known_hosts&lt;/code&gt; secret means the job fails if the server's key changes, instead of silently trusting a new one.&lt;/li&gt;
&lt;li&gt;The upload is &lt;code&gt;tar&lt;/code&gt; piped through &lt;code&gt;ssh&lt;/code&gt;, so it needs nothing beyond what the runner and server already have. The release name is a UTC timestamp plus the short commit SHA, which sorts by time and tells you which commit it is.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;set -euo pipefail&lt;/code&gt; is written explicitly so a failing &lt;code&gt;tar&lt;/code&gt; in the pipe fails the step.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The activation script
&lt;/h2&gt;

&lt;p&gt;Commit this as &lt;code&gt;deploy/activate.sh&lt;/code&gt;. The job pipes it into &lt;code&gt;bash -s&lt;/code&gt; on the server, so the script text is versioned with the code but nothing needs to be installed on the server beforehand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Runs on the server. Expects APP_DIR and RELEASE in the environment.&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail

: &lt;span class="s2"&gt;"${APP_DIR:?APP_DIR is required}"&lt;/span&gt;
: &lt;span class="s2"&gt;"${RELEASE:?RELEASE is required}"&lt;/span&gt;

&lt;span class="nv"&gt;release_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$APP_DIR/releases/$RELEASE"&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"$release_dir"&lt;/span&gt;

&lt;span class="c"&gt;# Shared state lives outside the release.&lt;/span&gt;
ln -sfn &lt;span class="s2"&gt;"$APP_DIR/shared/.env"&lt;/span&gt; .env
rm -rf storage
ln -sfn &lt;span class="s2"&gt;"$APP_DIR/shared/storage"&lt;/span&gt; storage

&lt;span class="c"&gt;# If either command fails, set -e stops here and "current" still points at the old release.&lt;/span&gt;
php artisan migrate --force
php artisan optimize

&lt;span class="c"&gt;# Atomic switch: build the new link beside "current", then rename it over the old one.&lt;/span&gt;
ln -sfn &lt;span class="s2"&gt;"$release_dir"&lt;/span&gt; &lt;span class="s2"&gt;"$APP_DIR/current.tmp"&lt;/span&gt;
mv -Tf &lt;span class="s2"&gt;"$APP_DIR/current.tmp"&lt;/span&gt; &lt;span class="s2"&gt;"$APP_DIR/current"&lt;/span&gt;

php artisan reload

&lt;span class="c"&gt;# Keep the five newest releases.&lt;/span&gt;
ls -1dt &lt;span class="s2"&gt;"$APP_DIR"&lt;/span&gt;/releases/*/ &lt;span class="o"&gt;|&lt;/span&gt; tail -n +6 &lt;span class="o"&gt;|&lt;/span&gt; xargs -r rm -rf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order is the point. Migrations and cache building happen &lt;em&gt;before&lt;/em&gt; the switch. The switch is a rename: &lt;code&gt;ln -sfn&lt;/code&gt; creates &lt;code&gt;current.tmp&lt;/code&gt; beside the old link, and &lt;code&gt;mv -Tf&lt;/code&gt; renames it over &lt;code&gt;current&lt;/code&gt;. A bare &lt;code&gt;ln -sfn target current&lt;/code&gt; would remove and recreate the link, leaving a brief gap. The &lt;code&gt;.env&lt;/code&gt; link is created before &lt;code&gt;php artisan optimize&lt;/code&gt;, because the Laravel deployment docs say that once configuration is cached the &lt;code&gt;.env&lt;/code&gt; file is no longer loaded, so the cache has to be built with the real production values.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan reload&lt;/code&gt; is the single reload command that the Laravel deployment docs (master branch) recommend. In Laravel 13.40 its source runs &lt;code&gt;queue:restart&lt;/code&gt; and &lt;code&gt;schedule:interrupt&lt;/code&gt; plus any commands that packages register, such as Octane or Reverb. On Laravel 12 and older, which don't have it, replace the line with &lt;code&gt;php artisan queue:restart&lt;/code&gt;. Your queue workers must be run by a process monitor (Supervisor or systemd) that restarts them after they exit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happened when I ran it
&lt;/h2&gt;

&lt;p&gt;I took the &lt;code&gt;run:&lt;/code&gt; scripts straight out of the workflow YAML and ran them with a stand-in &lt;code&gt;ssh&lt;/code&gt; that executes the remote command locally. The "server" was a directory with a shared &lt;code&gt;.env&lt;/code&gt; pointing at a local MySQL database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First deploy:&lt;/strong&gt; migrations ran, caches were built, the link was created, and a PHP server pointed at &lt;code&gt;current/public&lt;/code&gt; answered with the new release:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INFO  Preparing database.
Creating migration table ...................................... DONE
INFO  Running migrations.
0001_01_01_000000_create_users_table .......................... DONE
0001_01_01_000001_create_cache_table .......................... DONE
0001_01_01_000002_create_jobs_table ........................... DONE
2026_11_08_000001_add_is_admin_to_users ....................... DONE
INFO  Caching framework bootstrap, configuration, and metadata.
activate exit code: 0
current -&amp;gt; &amp;lt;ts&amp;gt;-abc1234
release dir has: 3 of vendor/artisan/public; tests dir: 0; .env -&amp;gt; app/shared/.env
storage -&amp;gt; app/shared/storage
tables in app_prod: 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A request to the PHP server started in &lt;code&gt;current/public&lt;/code&gt; then returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"app":"Laravel","users":0,"release":"&amp;lt;release&amp;gt;"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Second deploy&lt;/strong&gt; with a new migration applied it and moved &lt;code&gt;current&lt;/code&gt; to the new release:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2026_11_12_000001_add_nickname_to_users ....................... DONE
config ......................................................... DONE
events ......................................................... DONE
routes ......................................................... DONE
views ......................................................... DONE
INFO  Reloading services.
activate exit code: 0
current -&amp;gt; &amp;lt;ts&amp;gt;-def7654
nickname column: nickname
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;A broken migration&lt;/strong&gt; (one that throws an exception) stopped the script before the switch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INFO  Running migrations.
boom
activate exit code: 1
current unchanged: still &amp;lt;ts&amp;gt;-def7654
releases on disk: 3 (failed release left in place)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The site kept serving the previous release, and the job failed, which is what you want. The failed release directory stays on disk until the pruning step removes it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pruning:&lt;/strong&gt; after five more deploys, only five release directories remained.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rolling back
&lt;/h2&gt;

&lt;p&gt;Rolling back is the same atomic switch, pointed at an older release. On the server (or through &lt;code&gt;ssh&lt;/code&gt;), with the release name you want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /var/www/app
ln -sfn releases/20261112101500-abc1234 current.tmp
mv -Tf current.tmp current
&lt;span class="nb"&gt;cd&lt;/span&gt; current &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; php artisan reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I ran exactly this in the test and &lt;code&gt;current&lt;/code&gt; moved back to the first release, with the reload reporting DONE for the queue and schedule tasks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INFO  Reloading services.
queue ......................................................... DONE
schedule ...................................................... DONE
current -&amp;gt; &amp;lt;ts&amp;gt;-abc1234
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things a rollback does &lt;strong&gt;not&lt;/strong&gt; do. It doesn't undo database migrations: in my test the &lt;code&gt;nickname&lt;/code&gt; column from the second deploy stayed in place after rolling back. And it only works while the old release still exists, which is why pruning keeps five. Treat that as a design rule: write migrations so that the previous release's code still works with the new schema (add columns before using them, remove them a release later).&lt;/p&gt;

&lt;h2&gt;
  
  
  Production considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PHP-FPM and OPcache.&lt;/strong&gt; After a symlink switch, PHP-FPM may keep serving cached file paths or compiled scripts from the old release depending on your OPcache settings. Many setups reload PHP-FPM as the last deploy step (for example &lt;code&gt;sudo systemctl reload php8.4-fpm&lt;/code&gt; with a narrow sudoers rule for that single command). I did not test this, and it depends on your &lt;code&gt;opcache&lt;/code&gt; and &lt;code&gt;realpath_cache&lt;/code&gt; settings, so verify it on your server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permissions.&lt;/strong&gt; The deploy user writes the release, but PHP-FPM must be able to read it and write to &lt;code&gt;shared/storage&lt;/code&gt; and &lt;code&gt;bootstrap/cache&lt;/code&gt; inside the release. A release extracted by one user and served by another is a common source of 500 errors after a deploy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Health check.&lt;/strong&gt; The test app answered through the symlink. In production, add a final workflow step that requests a URL (a fresh Laravel app registers a health route at &lt;code&gt;/up&lt;/code&gt;) and fails if it doesn't answer, so a broken release is noticed in the job and not by a user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Migrations at scale.&lt;/strong&gt; Running &lt;code&gt;migrate --force&lt;/code&gt; before the switch means old code runs against the new schema for a moment. Long-locking migrations on big tables need separate planning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't put secrets in the release.&lt;/strong&gt; The tarball contains the workspace. Keep &lt;code&gt;.env&lt;/code&gt; out of the repository, as the starter's &lt;code&gt;.gitignore&lt;/code&gt; does.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Building the config cache before linking &lt;code&gt;.env&lt;/code&gt;, so production runs with the wrong values.&lt;/li&gt;
&lt;li&gt;Using &lt;code&gt;ln -sfn&lt;/code&gt; directly on &lt;code&gt;current&lt;/code&gt; and calling it atomic.&lt;/li&gt;
&lt;li&gt;Calling &lt;code&gt;env()&lt;/code&gt; outside config files; with a cached config it returns &lt;code&gt;null&lt;/code&gt; for &lt;code&gt;.env&lt;/code&gt; values (the Laravel deployment docs warn about this).&lt;/li&gt;
&lt;li&gt;Letting a pull request deploy because the &lt;code&gt;if&lt;/code&gt; condition is missing.&lt;/li&gt;
&lt;li&gt;Skipping host key pinning and accepting any host key.&lt;/li&gt;
&lt;li&gt;Forgetting to restart queue workers, so they keep running the old code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deployer&lt;/strong&gt; (a PHP deployment tool) or a hosted service such as Envoyer implement the same releases-and-symlink idea with more features. I did not test any of them here.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Managed platforms.&lt;/strong&gt; The Laravel docs say that Laravel Cloud handles reloading services automatically, so the reload step isn't needed there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Containers.&lt;/strong&gt; If you deploy Docker images, the release directory idea is replaced by image tags and a rolling update. That is a different pipeline, not a variation of this one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-run-tests-php-matrix-mysql" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 1: Run Tests with a PHP Matrix and MySQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-cache-composer-npm" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 2: Cache Composer and npm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-scheduler-not-running-cron-fixes" rel="noopener noreferrer"&gt;Laravel Scheduler Not Running: Cron and schedule:run Fixes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/nginx-502-bad-gateway-php-fpm-causes-fixes" rel="noopener noreferrer"&gt;Nginx 502 Bad Gateway with PHP-FPM: Causes and Fixes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Why build on the runner and not on the server?
&lt;/h3&gt;

&lt;p&gt;The server then needs no Node, no build tools and no access to package registries, and the code that was tested is the code that is shipped. The trade-off is uploading &lt;code&gt;vendor&lt;/code&gt; with every release.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need downtime or maintenance mode?
&lt;/h3&gt;

&lt;p&gt;Not for the switch itself, which is a rename. If a particular migration can't safely run while old code is serving traffic, put the app in maintenance mode around that deploy.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I deploy from a tag instead of a branch?
&lt;/h3&gt;

&lt;p&gt;Change the &lt;code&gt;on:&lt;/code&gt; trigger and the &lt;code&gt;if&lt;/code&gt; condition to match the tag, and keep the rest. An environment's deployment branch and tag rules can restrict which refs may deploy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where does the first release get its database?
&lt;/h3&gt;

&lt;p&gt;From &lt;code&gt;shared/.env&lt;/code&gt;. Create the database and user once; &lt;code&gt;migrate --force&lt;/code&gt; creates the tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update log&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;12 November 2026:&lt;/strong&gt; first version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; the Laravel deployment page (&lt;code&gt;optimize&lt;/code&gt;, &lt;code&gt;reload&lt;/code&gt;), the major versions of &lt;code&gt;checkout&lt;/code&gt;, &lt;code&gt;setup-php&lt;/code&gt;, &lt;code&gt;cache&lt;/code&gt; and &lt;code&gt;setup-node&lt;/code&gt;, and GitHub's environment protection rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/master/deployment" rel="noopener noreferrer"&gt;Laravel documentation: Deployment (master branch)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments" rel="noopener noreferrer"&gt;GitHub Docs: Managing environments for deployment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/enterprise-server@3.14/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency" rel="noopener noreferrer"&gt;GitHub Docs: Control the concurrency of workflows and jobs (Enterprise Server 3.14 page)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/actions/checkout" rel="noopener noreferrer"&gt;actions/checkout&lt;/a&gt;, &lt;a href="https://github.com/shivammathur/setup-php" rel="noopener noreferrer"&gt;shivammathur/setup-php&lt;/a&gt;, &lt;a href="https://github.com/actions/cache" rel="noopener noreferrer"&gt;actions/cache&lt;/a&gt;, &lt;a href="https://github.com/actions/setup-node" rel="noopener noreferrer"&gt;actions/setup-node&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rhysd/actionlint" rel="noopener noreferrer"&gt;actionlint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cicd</category>
      <category>deployment</category>
      <category>githubactions</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Laravel Sanctum vs Passport vs JWT: Which Auth to Use</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Sun, 15 Nov 2026 18:12:01 +0000</pubDate>
      <link>https://dev.to/devtalk94/laravel-sanctum-vs-passport-vs-jwt-which-auth-to-use-4e0a</link>
      <guid>https://dev.to/devtalk94/laravel-sanctum-vs-passport-vs-jwt-which-auth-to-use-4e0a</guid>
      <description>&lt;p&gt;"Sanctum, Passport or JWT?" gets asked as if the three were competitors. They aren't quite. Sanctum and Passport are first-party Laravel packages. JWT is not a package at all: it's a token format (RFC 7519) that third-party Laravel packages build on. The useful question is not "which is best" but &lt;strong&gt;who is calling your API, and do you need OAuth2?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For most Laravel applications the answer is Sanctum, and Laravel's own documentation says so. This article explains why, shows what each option does with real output, and covers the cases where Passport or JWT is the right call. I ran Sanctum 4.4.0 in a Laravel 13.40 app and tested JWT behavior with &lt;code&gt;firebase/php-jwt&lt;/code&gt; 7.2.1. Passport I could only check against the documentation, and I say so where it matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Sanctum&lt;/th&gt;
&lt;th&gt;Passport&lt;/th&gt;
&lt;th&gt;JWT (community packages)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What it is&lt;/td&gt;
&lt;td&gt;Lightweight first-party package: cookie auth for SPAs, plus simple API tokens&lt;/td&gt;
&lt;td&gt;First-party full OAuth2 server&lt;/td&gt;
&lt;td&gt;A signed token format; packages such as &lt;code&gt;tymon/jwt-auth&lt;/code&gt; and &lt;code&gt;php-open-source-saver/jwt-auth&lt;/code&gt; wrap it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Your own SPA, mobile app, or simple API tokens&lt;/td&gt;
&lt;td&gt;Third parties logging in through your app (OAuth2), MCP servers&lt;/td&gt;
&lt;td&gt;Stateless verification across services, if you accept the trade-offs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Revoking a token&lt;/td&gt;
&lt;td&gt;Delete a row; immediate&lt;/td&gt;
&lt;td&gt;Revoke server-side&lt;/td&gt;
&lt;td&gt;Needs server-side state (a denylist) to revoke early&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Setup weight&lt;/td&gt;
&lt;td&gt;Light&lt;/td&gt;
&lt;td&gt;Heavy (clients, keys, grants)&lt;/td&gt;
&lt;td&gt;Medium, plus your own key and lifetime decisions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The decision flow, in order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is it a regular browser app on the same Laravel project? Use Laravel's built-in session authentication; you don't need any of these.&lt;/li&gt;
&lt;li&gt;Is it your own SPA or mobile app, or do you just want to hand out API tokens? &lt;strong&gt;Sanctum.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Do outside developers need "Log in with your app" or standard OAuth2 flows, or will an MCP client connect? &lt;strong&gt;Passport.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Do several independent services need to verify tokens without calling back to one database? Consider &lt;strong&gt;JWT&lt;/strong&gt;, and plan revocation first.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Sanctum: two things in one package
&lt;/h2&gt;

&lt;p&gt;The docs describe two separate problems Sanctum solves. First, API tokens: a simple way to issue tokens "without the complication of OAuth", stored in one database table and sent in the &lt;code&gt;Authorization&lt;/code&gt; header. Second, SPA authentication, where Sanctum doesn't use tokens at all and relies on Laravel's cookie-based session authentication instead, only for requests that come from your own SPA frontend. It is fine to use only one of the two.&lt;/p&gt;

&lt;p&gt;The setup from the docs is &lt;code&gt;php artisan install:api&lt;/code&gt;, then the &lt;code&gt;HasApiTokens&lt;/code&gt; trait on your user model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/Models/User.php&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Laravel&lt;/span&gt;\&lt;span class="nc"&gt;Sanctum&lt;/span&gt;\&lt;span class="nc"&gt;HasApiTokens&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Authenticatable&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;HasApiTokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;HasFactory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Notifiable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Protect routes with the &lt;code&gt;sanctum&lt;/code&gt; guard. The &lt;code&gt;abilities&lt;/code&gt; check needs its middleware alias registered once in &lt;code&gt;bootstrap/app.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// bootstrap/app.php, inside withMiddleware()&lt;/span&gt;
&lt;span class="nv"&gt;$middleware&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;alias&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'abilities'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; \&lt;span class="nc"&gt;Laravel&lt;/span&gt;\&lt;span class="nc"&gt;Sanctum&lt;/span&gt;\&lt;span class="nc"&gt;Http&lt;/span&gt;\&lt;span class="nc"&gt;Middleware&lt;/span&gt;\&lt;span class="nc"&gt;CheckAbilities&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'ability'&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; \&lt;span class="nc"&gt;Laravel&lt;/span&gt;\&lt;span class="nc"&gt;Sanctum&lt;/span&gt;\&lt;span class="nc"&gt;Http&lt;/span&gt;\&lt;span class="nc"&gt;Middleware&lt;/span&gt;\&lt;span class="nc"&gt;CheckForAnyAbility&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// routes/api.php&lt;/span&gt;
&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/user'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;only&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'abilities:orders:read'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/orders'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'orders'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'abilities:orders:write'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/orders'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'created'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/logout'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;currentAccessToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Issuing tokens is one call. This is the pattern from the docs for a mobile login endpoint, which checks the credentials and returns a token named after the device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/sanctum/token'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'device_name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nc"&gt;Hash&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;ValidationException&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;withMessages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'The provided credentials are incorrect.'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;device_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;plainTextToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What Sanctum does, as tested
&lt;/h3&gt;

&lt;p&gt;I created a user and three tokens: one with all abilities, one limited to &lt;code&gt;orders:read&lt;/code&gt;, and one that expires after two seconds. This is what is stored:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;full      abilities=["*"]            expires_at=NULL                 stored=b702e54970e2...
readonly  abilities=["orders:read"]  expires_at=NULL                 stored=4018077e2989...
short     abilities=["*"]            expires_at=2026-11-11 15:05:31  stored=921fc96a0f45...
plain-text token shown to user: 1|R1vlLbpDsiZM...
sha256(secret part) matches stored hash: true
config sanctum.expiration = NULL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three facts are visible here. The user's token looks like &lt;code&gt;1|random&lt;/code&gt;, not a JWT. The database holds only a SHA-256 hash, which matches the docs, so the plain text exists only at creation time. And &lt;code&gt;expires_at&lt;/code&gt; is &lt;code&gt;NULL&lt;/code&gt; with &lt;code&gt;sanctum.expiration&lt;/code&gt; unset: the docs confirm that by default Sanctum tokens never expire and can only be invalidated by revoking them. Set an expiration unless you really want that.&lt;/p&gt;

&lt;p&gt;The requests, against a local server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl /api/user   (no token)
{"message":"Unauthenticated."}  [401]

$ curl /api/user   (full token)
{"id":1,"name":"Ann","email":"ann@example.test"}  [200]

$ GET /api/orders  (readonly token, needs orders:read)
{"orders":[]}  [200]

$ POST /api/orders (readonly token, needs orders:write)
{"message":"Invalid ability provided."}  [403]

$ POST /api/orders (full token)
{"created":true}  [200]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(With debug mode on, the 403 response also carries a stack trace; I show only the message.) Revocation takes effect on the very next request, because the token's row is gone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ POST /api/logout (full token)
{"ok":true}  [200]

$ GET /api/user    (same token again)
{"message":"Unauthenticated."}  [401]

$ GET /api/user    (short token, 2s lifetime, age ~3s)
{"message":"Unauthenticated."}  [401]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set a global lifetime in &lt;code&gt;config/sanctum.php&lt;/code&gt; (&lt;code&gt;'expiration'&lt;/code&gt; is in minutes) or per token, as the docs show: &lt;code&gt;createToken('name', ['*'], now()-&amp;gt;plus(weeks: 1))&lt;/code&gt;. Add the documented &lt;code&gt;sanctum:prune-expired --hours=24&lt;/code&gt; command to your scheduler so old rows don't pile up.&lt;/p&gt;

&lt;p&gt;For a first-party SPA, the docs say SPA and API must share a top-level domain (subdomains are fine). You configure stateful domains, call &lt;code&gt;/sanctum/csrf-cookie&lt;/code&gt; first, then log in. In that mode no token is stored in the browser, which removes a whole class of "where do I keep the token" questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Passport: when you actually need OAuth2
&lt;/h2&gt;

&lt;p&gt;Passport is a full OAuth2 server. The docs put it plainly: if your application absolutely needs to support OAuth2, use Passport; to authenticate a single-page application or mobile application, or to issue API tokens, use Sanctum. The authentication page adds that most applications don't need the complexity of the OAuth2 specification, and that Passport is the choice if you're building an MCP server that AI clients will connect to, since those clients typically expect OAuth.&lt;/p&gt;

&lt;p&gt;What you get, per the Passport documentation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authorization code grant, and authorization code with PKCE for SPAs and mobile apps.&lt;/li&gt;
&lt;li&gt;Client credentials for machine-to-machine access, and device authorization for browserless devices.&lt;/li&gt;
&lt;li&gt;Scopes, refresh tokens and personal access tokens.&lt;/li&gt;
&lt;li&gt;The password and implicit grants are marked deprecated: "We no longer recommend" them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Setup is heavier: &lt;code&gt;php artisan install:api --passport&lt;/code&gt; runs migrations for OAuth clients and tokens and generates encryption keys, and you then create clients with &lt;code&gt;passport:client&lt;/code&gt; variants. By default Passport issues long-lived access tokens that expire after one year, which you can shorten with &lt;code&gt;Passport::tokensExpireIn()&lt;/code&gt; and related methods. I did not install Passport for this article, so none of that was run; it is all from the documentation.&lt;/p&gt;

&lt;p&gt;If your use of Passport amounts to issuing personal access tokens to your own users, the docs themselves suggest considering Sanctum instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  JWT: a token format, not a package choice
&lt;/h2&gt;

&lt;p&gt;A JWT carries its claims inside the token and is signed, so a server can verify it without a database lookup. RFC 7519 defines the registered claims: &lt;code&gt;iss&lt;/code&gt; (issuer), &lt;code&gt;sub&lt;/code&gt; (subject), &lt;code&gt;aud&lt;/code&gt; (audience), &lt;code&gt;exp&lt;/code&gt; (expiry, after which the token must not be accepted), &lt;code&gt;nbf&lt;/code&gt;, &lt;code&gt;iat&lt;/code&gt; and &lt;code&gt;jti&lt;/code&gt; (a unique ID). Laravel doesn't ship a JWT guard. The common packages are &lt;code&gt;tymon/jwt-auth&lt;/code&gt; and its fork &lt;code&gt;php-open-source-saver/jwt-auth&lt;/code&gt;. When I read their repositories on 11 November 2026, both allowed Laravel 13 in &lt;code&gt;composer.json&lt;/code&gt; and had commits within the previous few weeks (Tymon's latest tag was 2.3.1; the fork's was v2.10.0 and requires PHP 8.3 or newer). That tells you they're maintained, not that they're right for you.&lt;/p&gt;

&lt;p&gt;To see how JWTs behave without any framework, I ran the plain &lt;code&gt;firebase/php-jwt&lt;/code&gt; library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header alg: HS256
payload is only encoded, not encrypted: {"iss":"https://api.example.test","aud":"example-mobile-app","sub":"42","iat":N,"exp":N,"jti":"tok-001"}

1 valid token                     accepted, sub=42
2 payload edited                  Firebase\JWT\SignatureInvalidException: Signature verification failed
3 alg "none" token                UnexpectedValueException: Algorithm not supported
4 wrong key                       Firebase\JWT\SignatureInvalidException: Signature verification failed
5 after "logout", no denylist     accepted
6 same token, jti denylisted      RuntimeException: token revoked (jti on denylist)
7 after exp (3s later)            Firebase\JWT\ExpiredException: Expired token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(&lt;code&gt;iat&lt;/code&gt; and &lt;code&gt;exp&lt;/code&gt; are replaced by &lt;code&gt;N&lt;/code&gt; because they are timestamps that change on every run.) What this shows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The payload is readable by anyone holding the token.&lt;/strong&gt; It's base64-encoded, not encrypted. Never put secrets or personal data in it that the client shouldn't see.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tampering is caught.&lt;/strong&gt; Editing the payload (line 2) or using the wrong key (line 4) fails signature verification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The&lt;/strong&gt;&lt;code&gt;none&lt;/code&gt;&lt;strong&gt;algorithm is rejected, because the caller pinned the algorithm.&lt;/strong&gt; Passing the expected algorithm in &lt;code&gt;new Key($secret, 'HS256')&lt;/code&gt; is what protects you. RFC 8725, the JWT best-practices document, makes this the first rule: libraries must let the caller specify the supported algorithms, and applications should not trust the token's own &lt;code&gt;alg&lt;/code&gt; header.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logout does nothing by itself (line 5).&lt;/strong&gt; The signature and expiry are all the server checks, so a stolen or "logged out" token is accepted until &lt;code&gt;exp&lt;/code&gt;. To revoke early you need server-side state, such as the &lt;code&gt;jti&lt;/code&gt; denylist in line 6. At that point you have given up part of the "no database lookup" advantage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expiry works (line 7)&lt;/strong&gt;, which is why access-token lifetimes should be short.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;RFC 8725 also recommends validating the issuer and audience and using explicit typing; my &lt;code&gt;$check&lt;/code&gt; function does the first two by hand. Whatever package you choose, confirm it validates &lt;code&gt;iss&lt;/code&gt;, &lt;code&gt;aud&lt;/code&gt; and &lt;code&gt;exp&lt;/code&gt; and that your key is long and random. For a first-party app that only talks to your own Laravel backend, JWT adds complexity that Sanctum avoids.&lt;/p&gt;

&lt;p&gt;A fair design comparison, labelled as reasoning rather than a benchmark: Sanctum looks the token up in your database on each request (that's how revocation can be immediate), while a JWT can be verified from the signature alone. For one Laravel app that difference rarely matters. It matters more when many independent services must verify tokens without sharing a database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one for which situation
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Your situation&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Server-rendered Laravel app&lt;/td&gt;
&lt;td&gt;Built-in session auth&lt;/td&gt;
&lt;td&gt;No tokens needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Your own SPA on the same top-level domain&lt;/td&gt;
&lt;td&gt;Sanctum (cookie mode)&lt;/td&gt;
&lt;td&gt;No token stored in the browser&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Your own mobile app&lt;/td&gt;
&lt;td&gt;Sanctum tokens&lt;/td&gt;
&lt;td&gt;Simple, revocable per device, with abilities&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Public API where customers generate their own keys&lt;/td&gt;
&lt;td&gt;Sanctum tokens&lt;/td&gt;
&lt;td&gt;Hashed storage, abilities, easy revocation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;"Log in with our app" for third-party developers&lt;/td&gt;
&lt;td&gt;Passport&lt;/td&gt;
&lt;td&gt;That is what OAuth2 is for&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server-to-server access with client credentials&lt;/td&gt;
&lt;td&gt;Passport&lt;/td&gt;
&lt;td&gt;Standard grant for machine access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MCP server for AI clients&lt;/td&gt;
&lt;td&gt;Passport&lt;/td&gt;
&lt;td&gt;The Laravel docs recommend it; MCP clients typically expect OAuth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Many separate services must verify tokens independently&lt;/td&gt;
&lt;td&gt;JWT, or an external identity provider&lt;/td&gt;
&lt;td&gt;Stateless verification; plan revocation and key rotation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Installing Passport for a first-party mobile app.&lt;/strong&gt; You pay for OAuth2 you don't use. The docs steer you to Sanctum.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leaving Sanctum tokens non-expiring.&lt;/strong&gt; It's the default. Set &lt;code&gt;sanctum.expiration&lt;/code&gt; or a per-token expiry and prune old rows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using tokens for a same-domain SPA.&lt;/strong&gt; Sanctum's cookie mode exists so the browser doesn't hold a bearer token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Granting&lt;/strong&gt;&lt;code&gt;['*']&lt;/code&gt;&lt;strong&gt;to every token.&lt;/strong&gt; Give tokens the abilities they need; you saw a limited token get a 403.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Long-lived JWTs with no revocation plan.&lt;/strong&gt; Keep access tokens short and decide how you'd cut off a stolen one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trusting the&lt;/strong&gt;&lt;code&gt;alg&lt;/code&gt;&lt;strong&gt;header.&lt;/strong&gt; Pin the algorithm on verification.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Putting sensitive data in a JWT payload.&lt;/strong&gt; Signed is not secret.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treating password and implicit grants as current.&lt;/strong&gt; Passport's docs call them deprecated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;p&gt;Built-in session authentication covers a monolithic app. The Laravel docs also note that the cookie-based libraries and the token packages aren't mutually exclusive, so an app can serve a web UI and an API at once. If your organization already runs an identity provider (Keycloak, Auth0, or similar), validating its JWTs in Laravel can be the better design than building your own issuer; I haven't evaluated those products here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/common-api-design-mistakes" rel="noopener noreferrer"&gt;10 Common API Design Mistakes Developers Make&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-env-configuration-env-vs-config" rel="noopener noreferrer"&gt;Laravel .env Configuration: env() vs config() Explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-scheduler-not-running-cron-fixes" rel="noopener noreferrer"&gt;Laravel Scheduler Not Running: Cron and schedule:run Fixes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is Sanctum a JWT implementation?
&lt;/h3&gt;

&lt;p&gt;No. In the test, the token looked like &lt;code&gt;1|random-string&lt;/code&gt;, and the database stored only its SHA-256 hash. Authentication is a lookup, not a signature check.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I revoke a JWT?
&lt;/h3&gt;

&lt;p&gt;Not by itself. You need server-side state, such as a denylist of token IDs, or very short lifetimes with refresh tokens. Both packages mentioned above have a token blacklist in their source (a &lt;code&gt;TokenBlacklistedException&lt;/code&gt; and blacklist handling in &lt;code&gt;JWT.php&lt;/code&gt;); check their docs for how entries are stored and for how long.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do Sanctum tokens expire?
&lt;/h3&gt;

&lt;p&gt;Only if you configure it. The default is no expiry. Use &lt;code&gt;sanctum.expiration&lt;/code&gt; (minutes) for a global limit or pass an expiry date to &lt;code&gt;createToken&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I use Sanctum and Passport in the same app?
&lt;/h3&gt;

&lt;p&gt;The Laravel docs say the cookie-based authentication and the token packages are not mutually exclusive. I did not test running both packages together, and most apps only need one.&lt;/p&gt;

&lt;h3&gt;
  
  
  What about refresh tokens?
&lt;/h3&gt;

&lt;p&gt;Passport issues refresh tokens as part of OAuth2. Sanctum's documentation doesn't describe refresh tokens: you issue a new token or let the user log in again. Both JWT packages I read have a &lt;code&gt;refresh()&lt;/code&gt; method in their source; check how the one you choose handles it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/sanctum" rel="noopener noreferrer"&gt;Laravel documentation: Sanctum&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/framework/docs/passport" rel="noopener noreferrer"&gt;Laravel documentation: Passport&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/authentication" rel="noopener noreferrer"&gt;Laravel documentation: Authentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rfc-editor.org/rfc/rfc7519" rel="noopener noreferrer"&gt;RFC 7519: JSON Web Token (JWT)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rfc-editor.org/rfc/rfc8725.html" rel="noopener noreferrer"&gt;RFC 8725: JSON Web Token Best Current Practices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/laravel/sanctum" rel="noopener noreferrer"&gt;laravel/sanctum on GitHub&lt;/a&gt;, &lt;a href="https://github.com/firebase/php-jwt" rel="noopener noreferrer"&gt;firebase/php-jwt on GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/laravel-sanctum-vs-passport-vs-jwt" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>sanctum</category>
      <category>passport</category>
      <category>jwt</category>
    </item>
    <item>
      <title>Git Security Release: 6 Vulnerabilities and CVE-2026-111760</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Sun, 15 Nov 2026 14:31:33 +0000</pubDate>
      <link>https://dev.to/devtalk94/git-security-release-6-vulnerabilities-and-cve-2026-111760-1910</link>
      <guid>https://dev.to/devtalk94/git-security-release-6-vulnerabilities-and-cve-2026-111760-1910</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 15 November 2026. This is a recent security release; see the&lt;/em&gt;&lt;em&gt;update log&lt;/em&gt;&lt;em&gt;and check the Git announcement for changes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On 10 November 2026 the Git project released fixes for six vulnerabilities. One of them is the kind that makes developers nervous: cloning a malicious repository with &lt;code&gt;git clone --recurse-submodules&lt;/code&gt; can lead to attacker-controlled code running on your machine. The other five are a mix of file-write, memory-corruption and denial-of-service bugs that matter most to servers and tools that handle untrusted repositories.&lt;/p&gt;

&lt;p&gt;This article walks through all six, says which ones you should worry about, shows how to check your Git version (with a script I tested), and lists what you can do until you have patched. A caution up front: the Git announcement gives no severity scores, and I could not run the exploits, so the severity talk below is based on what the maintainers wrote.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fixed in:&lt;/strong&gt; Git 2.56.1 and the maintenance releases 2.55.1, 2.54.1, 2.53.1, 2.52.1, 2.51.3 and 2.50.2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Affected:&lt;/strong&gt; per the announcement, all versions back to v2.27.0. Versions older than 2.50 are no longer serviced upstream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The serious one:&lt;/strong&gt; CVE-2026-111760, code execution during a recursive clone of an attacker-controlled repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exploited in the wild:&lt;/strong&gt; none of the coverage I read reports it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Action:&lt;/strong&gt; update Git, and update every tool that bundles its own copy of Git.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The six vulnerabilities at a glance
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CVE&lt;/th&gt;
&lt;th&gt;What happens&lt;/th&gt;
&lt;th&gt;Triggered by&lt;/th&gt;
&lt;th&gt;Impact (per the announcement)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-111760&lt;/td&gt;
&lt;td&gt;Integer truncation in path handling lets a crafted path be written as &lt;code&gt;.git&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;git clone --recurse-submodules&lt;/code&gt; of an attacker's repository&lt;/td&gt;
&lt;td&gt;Remote code execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-113408&lt;/td&gt;
&lt;td&gt;Unvalidated &lt;code&gt;HEAD&lt;/code&gt; symref from a server (protocol v2) with &lt;code&gt;..&lt;/code&gt; segments&lt;/td&gt;
&lt;td&gt;Cloning from a malicious server, then a later operation like &lt;code&gt;git commit&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;A ref file written outside the refs directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-114467&lt;/td&gt;
&lt;td&gt;More than two GPG signatures overflow a fixed array in &lt;code&gt;remove_signature()&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Merging a tag whose message has more than two PGP signatures&lt;/td&gt;
&lt;td&gt;Stack corruption: denial of service, a risk for forges&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-114469&lt;/td&gt;
&lt;td&gt;Binary patch size check looks only at the compressed size&lt;/td&gt;
&lt;td&gt;Applying an attacker's binary patch (for example &lt;code&gt;git apply&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Out-of-bounds read and crash&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-105437&lt;/td&gt;
&lt;td&gt;Size overflow in the three-way merge buffer, with many conflicts and a large &lt;code&gt;conflict-marker-size&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Any textual three-way merge: merge, rebase, cherry-pick, merge-tree&lt;/td&gt;
&lt;td&gt;Heap buffer overflow; on forges that read attributes from trees, a risk for anyone who can push and request a merge&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CVE-2026-114466&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;fast-import&lt;/code&gt; features &lt;code&gt;rewrite-submodules-from/to&lt;/code&gt; and &lt;code&gt;export-pack-edges&lt;/code&gt; access arbitrary files&lt;/td&gt;
&lt;td&gt;Feeding an untrusted fast-import stream&lt;/td&gt;
&lt;td&gt;Arbitrary file read (content can leak in error messages) and append&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  CVE-2026-111760: how a clone can run code
&lt;/h2&gt;

&lt;p&gt;The Git maintainers describe the bug like this. Git stores the length of a path name in a 32-bit field, but computes it as a larger type. A path of about 232 bytes makes the stored length wrap around to 4. Path validation looks at the full, long name and finds nothing wrong. Checkout, however, writes only the first 4 bytes, and those 4 bytes can be &lt;code&gt;.git&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the entry is a symlink, it can replace the &lt;code&gt;.git&lt;/code&gt; file of a submodule. Normally a submodule's &lt;code&gt;.git&lt;/code&gt; is a small file that points to the real repository directory. Pointing it at a directory the attacker controls, one that holds hooks or configuration, means Git will later run attacker-specified code. Git refuses to replace a &lt;code&gt;.git&lt;/code&gt; directory with a symlink, but a freshly cloned submodule's &lt;code&gt;.git&lt;/code&gt; is a file, and The Hacker News notes that this check does not block that case.&lt;/p&gt;

&lt;p&gt;Requirements, per the announcement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You clone an attacker-controlled repository with &lt;code&gt;--recurse-submodules&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Such a repository fails the &lt;code&gt;LARGE_PATHNAME&lt;/code&gt; and &lt;code&gt;TREE_NOT_SORTED&lt;/code&gt; fsck checks, so major forges would be expected to refuse a push of it. But a malicious &lt;code&gt;.gitmodules&lt;/code&gt; in a normal-looking repository that points at one is enough.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That second point is the practical risk. The repository you clone looks innocent. The submodule it pulls in is the weapon. Credit for the report goes to Robert Chen. A secondary source rates it High with a CVSS base score of 8.0; the Git announcement itself gives no score.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is at risk
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Developers&lt;/strong&gt; who clone unfamiliar repositories (open source, a contractor's repo, a "try this" link) with &lt;code&gt;--recurse-submodules&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI systems&lt;/strong&gt; that check out pull requests from forks or arbitrary repositories with recursive submodules, especially when the job has secrets or deploy credentials.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code hosting and review tools&lt;/strong&gt; that merge, apply patches or import repositories for users. The merge, patch and signature bugs mostly matter here, and GitLab is cited as saying that servers running &lt;code&gt;git merge-tree&lt;/code&gt; are most exposed to CVE-2026-105437.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything that bundles its own Git&lt;/strong&gt;: GUI clients, IDEs, deployment tools, and container images. Updating the Git on your PATH does not update those.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Check your version
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare it with the fixed releases. This script does that for you. It knows the seven fixed releases and prints a clear verdict:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Usage: ./chk_git.sh                (checks the git on PATH)&lt;/span&gt;
&lt;span class="c"&gt;#        ./chk_git.sh "git version 2.54.0"   (checks a version string)&lt;/span&gt;
&lt;span class="c"&gt;# Fixed upstream releases for the November 2026 security release:&lt;/span&gt;
&lt;span class="c"&gt;#   2.50.2 2.51.3 2.52.1 2.53.1 2.54.1 2.55.1 2.56.1&lt;/span&gt;
&lt;span class="kd"&gt;declare&lt;/span&gt; -A &lt;span class="nv"&gt;FIXED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;2.50&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2 &lt;span class="o"&gt;[&lt;/span&gt;2.51&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3 &lt;span class="o"&gt;[&lt;/span&gt;2.52&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="o"&gt;[&lt;/span&gt;2.53&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="o"&gt;[&lt;/span&gt;2.54&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="o"&gt;[&lt;/span&gt;2.55&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="o"&gt;[&lt;/span&gt;2.56&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;raw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"${1:-$(git --version)}"&lt;/span&gt;
&lt;span class="nv"&gt;ver&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$raw"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -oE &lt;span class="s1"&gt;'[0-9]+\.[0-9]+\.[0-9]+'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; head -1&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; -z &lt;span class="s2"&gt;"$ver"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"could not parse: $raw"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 2&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;. &lt;span class="nb"&gt;read&lt;/span&gt; -r maj min pat &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;"$ver"&lt;/span&gt;
&lt;span class="nv"&gt;series&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$maj.$min"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$maj"&lt;/span&gt; -gt 2 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$maj"&lt;/span&gt; -eq 2 &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$min"&lt;/span&gt; -gt 56 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$ver: newer than the 2.56 series, assumed to include the fixes"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 0
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -z &lt;span class="s2"&gt;"${FIXED[$series]:-}"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$ver: series $series gets no upstream maintenance release for this advisory."&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"   Distribution packages may carry backported fixes: check your vendor's security notice."&lt;/span&gt;
  &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$pat"&lt;/span&gt; -ge &lt;span class="s2"&gt;"${FIXED[$series]}"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$ver: includes the fix (needs $series.${FIXED[$series]} or newer)"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 0
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$ver: VULNERABLE. Update to $series.${FIXED[$series]} or newer (2.56.1 is the newest line)"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Results from my tests of the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.50.1: VULNERABLE. Update to 2.50.2 or newer (2.56.1 is the newest line)
2.50.2: includes the fix (needs 2.50.2 or newer)
2.54.0: VULNERABLE. Update to 2.54.1 or newer (2.56.1 is the newest line)
2.54.1: includes the fix (needs 2.54.1 or newer)
2.56.0: VULNERABLE. Update to 2.56.1 or newer (2.56.1 is the newest line)
2.56.1: includes the fix (needs 2.56.1 or newer)
2.57.0: newer than the 2.56 series, assumed to include the fixes
2.43.0: series 2.43 gets no upstream maintenance release for this advisory.
   Distribution packages may carry backported fixes: check your vendor's security notice.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also handled suffixes such as &lt;code&gt;2.56.0.windows.4&lt;/code&gt; and &lt;code&gt;2.39.5 (Apple Git-154)&lt;/code&gt;, and exits with an error for input it cannot parse. The Git on the machine where I tested was 2.43.0, a distribution package. That is the case the script cannot settle: Linux distributions often backport security fixes into older version numbers, so an old number there does not prove you are vulnerable, and a new-looking number from an unofficial source does not prove you are safe. Check your distribution's security notice for these CVEs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Windows, macOS and bundled copies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Git for Windows:&lt;/strong&gt; my sources disagree. One secondary report says Git for Windows 2.56.1 was released on 11 November, while The Hacker News says that, when it checked, no fixed Git for Windows version was out, and the releases page I fetched listed 2.56.0.windows.4 as the latest. Check the Git for Windows releases page yourself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; per GitHub's statement quoted in the coverage, github.com and GitHub Enterprise Cloud are patched; GitHub Enterprise Server fixes are in 3.19.15, 3.20.11, 3.21.9 and 3.22.4; patched builds of GitHub Desktop and the Copilot app are being coordinated, with Codespaces and Actions to follow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bundled Git:&lt;/strong&gt; any application that ships its own Git needs its own update. Look at the vendor's release notes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Until you can update
&lt;/h2&gt;

&lt;p&gt;The Git maintainers' advice, as quoted by GitHub's Elijah Newren, is to clone only from trusted servers and avoid recursive clones of untrusted repositories. These precautions do not replace installing the fixes. Some concrete ways to follow it:&lt;/p&gt;

&lt;h3&gt;
  
  
  Clone first, look, then fetch submodules
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://example.com/someone/project.git
&lt;span class="nb"&gt;cd&lt;/span&gt; project
git config -f .gitmodules --get-regexp &lt;span class="s1"&gt;'^submodule\..*\.url$'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;submodule.vendor/libs.url ../libs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A plain clone leaves submodule directories empty (I confirmed: zero files in &lt;code&gt;vendor/libs&lt;/code&gt; after cloning). The second command lists every URL the repository wants to fetch. If a submodule points at a host you don't recognize, stop there. If they look fine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git submodule update --init --recursive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tested this workflow with local repositories: the plain clone fetched nothing, the URL listing worked, and the update checked out the submodule. This reduces the chance of fetching a submodule you did not intend to, but it is a manual review step, not a guarantee that a submodule you decide to trust is safe, and it does not remove the underlying flaw.&lt;/p&gt;

&lt;h3&gt;
  
  
  Be careful with untrusted merges and patches
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Don't merge tags or branches from sources you don't trust (CVE-2026-114467, CVE-2026-105437).&lt;/li&gt;
&lt;li&gt;Don't &lt;code&gt;git apply&lt;/code&gt; binary patches from unknown senders (CVE-2026-114469).&lt;/li&gt;
&lt;li&gt;Don't feed &lt;code&gt;git fast-import&lt;/code&gt; streams from untrusted sources (CVE-2026-114466).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  A workaround for the merge overflow: conflict-marker-size
&lt;/h3&gt;

&lt;p&gt;For CVE-2026-105437, The Hacker News cites GitLab suggesting a workaround: set &lt;code&gt;conflict-marker-size=7&lt;/code&gt; in each repository's &lt;code&gt;info/attributes&lt;/code&gt; file. The reason this can work is that the dangerous input is the attacker-controlled attribute value, and &lt;code&gt;info/attributes&lt;/code&gt; overrides the attributes committed in the repository. I tested the precedence with a small repository whose committed &lt;code&gt;.gitattributes&lt;/code&gt; sets the marker size to 20:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'* conflict-marker-size=7\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; .git/info/attributes
git check-attr conflict-marker-size -- f.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f.txt: conflict-marker-size: 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before that file existed, a conflicted merge produced 20-character markers (&lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD&lt;/code&gt;); afterwards it produced the standard 7. So the override works as described. What I could not do is confirm that the override prevents the overflow itself, since I cannot trigger that bug. For a hosting service, this is a stopgap while you roll out a patched Git, not a replacement for it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fast-import change can break scripts
&lt;/h3&gt;

&lt;p&gt;The fix for CVE-2026-114466 turns the risky &lt;code&gt;fast-import&lt;/code&gt; features off unless &lt;code&gt;--allow-unsafe-features&lt;/code&gt; is passed. The Git announcement calls this a backwards-incompatible change with minimal expected impact, since the features mostly serve import/export remote helpers. If you run such a tool after updating and it fails, that flag is why. Add it only when the program generating the stream is trusted.&lt;/p&gt;

&lt;h2&gt;
  
  
  A hardening baseline worth adopting
&lt;/h2&gt;

&lt;p&gt;These are my recommendations, not part of the announcement:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't run &lt;code&gt;git clone --recurse-submodules&lt;/code&gt; as a reflex. Make recursive fetching a deliberate step for repositories you trust.&lt;/li&gt;
&lt;li&gt;In CI, don't check out untrusted forks with recursive submodules in jobs that hold secrets. Separate "build the pull request" from "deploy" and keep credentials out of the first job.&lt;/li&gt;
&lt;li&gt;Inventory the tools on build agents and laptops that bundle Git, and include them in your patching process.&lt;/li&gt;
&lt;li&gt;Keep Git on servers that handle user repositories on a patch schedule of days, not months.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Updating the system Git but leaving an IDE, GUI client or container image with an old bundled copy.&lt;/li&gt;
&lt;li&gt;Assuming "2.4x is old, so I'm vulnerable" or "my distro updated, so I'm safe" without reading the vendor notice.&lt;/li&gt;
&lt;li&gt;Treating a forge's fsck checks as protection when the real payload is a malicious &lt;code&gt;.gitmodules&lt;/code&gt; in an ordinary-looking repository.&lt;/li&gt;
&lt;li&gt;Ignoring the five non-RCE bugs on servers that merge or apply patches for users.&lt;/li&gt;
&lt;li&gt;Applying &lt;code&gt;--allow-unsafe-features&lt;/code&gt; everywhere to make a broken script work again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/red-hat-quay-cve-2026-123710" rel="noopener noreferrer"&gt;Critical Red Hat Quay Flaw (CVE-2026-123710): Unauthenticated Registry Takeover and What to Do&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/cursor-claude-code-extension-backdoor-what-to-check" rel="noopener noreferrer"&gt;Malicious Claude Code Extension in the Cursor Marketplace: What Happened and How to Check Your Machine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/github-actions-laravel-deploy-ssh-releases-rollback" rel="noopener noreferrer"&gt;GitHub Actions for Laravel, Part 3: Deploy over SSH with Releases and Rollback&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Which Git versions are fixed?
&lt;/h3&gt;

&lt;p&gt;2.56.1, 2.55.1, 2.54.1, 2.53.1, 2.52.1, 2.51.3 and 2.50.2. Anything older is no longer serviced upstream; your distribution may have its own patched package.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can a normal git clone run malicious code?
&lt;/h3&gt;

&lt;p&gt;For CVE-2026-111760 the announcement describes a recursive clone (&lt;code&gt;--recurse-submodules&lt;/code&gt;) of an attacker-controlled repository. A plain clone did not fetch submodules in my test. Check the other five for the operations they need (merging, applying patches and so on).&lt;/p&gt;

&lt;h3&gt;
  
  
  Is it being exploited?
&lt;/h3&gt;

&lt;p&gt;None of the sources I read report exploitation. Details are public, so patch anyway.&lt;/p&gt;

&lt;h3&gt;
  
  
  Do I need to update GitHub Desktop, VS Code or other tools?
&lt;/h3&gt;

&lt;p&gt;If they bundle their own Git, yes, once the vendor releases an update. Whether a given tool bundles Git or uses the one on your system differs by tool, and I did not check individual products, so read each vendor's release notes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does disabling submodules fully protect me?
&lt;/h3&gt;

&lt;p&gt;It removes the route for CVE-2026-111760, but the other bugs have other triggers. Update Git.&lt;/p&gt;

&lt;h2&gt;
  
  
  update log
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;15 November 2026:&lt;/strong&gt; first version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; the Git announcement and release notes, the Git for Windows releases page, your distribution's security notice, and GitHub's client rollout.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.openwall.com/lists/oss-security/2026/11/11/10" rel="noopener noreferrer"&gt;oss-security: git v2.56.1 and older maintenance releases fix six vulnerabilities&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.helpnetsecurity.com/2026/11/11/git-project-security-updates/" rel="noopener noreferrer"&gt;Help Net Security: Git fixes six vulnerabilities, including code execution during recursive clones&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thehackernews.com/2026/11/git-patches-flaw-that-lets-malicious.html" rel="noopener noreferrer"&gt;The Hacker News: Git Patches Flaw That Lets Malicious Repositories Execute Code During Recursive Clones&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cybersecuritynews.com/git-fixes-security-vulnerabilities/" rel="noopener noreferrer"&gt;Cyber Security News: Git Fixes 6 Security Vulnerabilities&lt;/a&gt; (the headline this article responds to; not otherwise used)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://finance.biggo.com/news/502ac07c-4968-41f3-941a-d935d0c950c8" rel="noopener noreferrer"&gt;BigGo Finance: Git for Windows v2.56.1 (aggregator, used for the CVSS 8.0 rating and the Windows release date)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/git-for-windows/git/releases" rel="noopener noreferrer"&gt;Git for Windows releases&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/git-security-release-cve-2026-111760" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>git</category>
      <category>cve</category>
      <category>submodules</category>
    </item>
    <item>
      <title>Red Hat Quay CVE-2026-123710: Registry Takeover and Fixes</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Sun, 15 Nov 2026 12:31:37 +0000</pubDate>
      <link>https://dev.to/devtalk94/red-hat-quay-cve-2026-123710-registry-takeover-and-fixes-2egj</link>
      <guid>https://dev.to/devtalk94/red-hat-quay-cve-2026-123710-registry-takeover-and-fixes-2egj</guid>
      <description>&lt;p&gt;&lt;em&gt;Last updated: 15 November 2026. This is a developing issue; see the&lt;/em&gt;&lt;em&gt;update log&lt;/em&gt;&lt;em&gt;and re-check Red Hat's advisory before acting.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Red Hat Quay, the container registry that many teams run on-premises and on OpenShift, has a critical flaw in the way it manages its own signing keys. CVE-2026-123710 is scored 9.8 (Critical) and, as described by Red Hat, lets a client with no account install its own trusted signing key. After that it can read private images and overwrite tags. If you run Quay, the registry itself is the thing at risk, and so is every system that pulls from it.&lt;/p&gt;

&lt;p&gt;This article explains in plain terms what the bug is, who is affected, what to do first (before and after patching) and how to reduce your exposure to a poisoned image. I could not run Quay itself, so the vulnerability details come from Red Hat and security press coverage, and I say which is which. One of the mitigations, restricting the key endpoint at your reverse proxy, I did test with nginx.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;What:&lt;/strong&gt; CVE-2026-123710, CWE-1287 (improper validation of the specified type of input), in Quay's service key server. Red Hat's CVSS 3.1 score is 9.8 with the vector &lt;code&gt;AV:N/AC:L/PR:N/UI:N&lt;/code&gt;: network, low complexity, no privileges, no user interaction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impact:&lt;/strong&gt; an attacker can install a signing key that Quay trusts, then mint tokens that give read and write access to repositories. That means exposure of private images and any secrets inside them, and the ability to replace images that other systems pull.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Affected:&lt;/strong&gt; Red Hat Quay 3 and 5, including standalone deployments, the Quay Operator on OpenShift and the mirror registry for OpenShift, according to The Hacker News' reading of Red Hat's data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exploited in the wild:&lt;/strong&gt; none of the coverage I read says so, and one vendor write-up lists "no public exploit". That can change quickly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; upstream fixes were merged on 11 November. Red Hat has published fixed builds for several Quay 3 branches. See the version note below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How the attack works
&lt;/h2&gt;

&lt;p&gt;Quay signs the tokens that authorize registry access. The signing keys are managed by a service key server, and keys can be rotated through an API. According to The Hacker News, the key server accepts a rotation request if it carries a token signed by a trusted key with the expected audience and issuer. It does not check that the token was issued &lt;em&gt;for key rotation&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;That is the gap:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An unauthenticated client requests an anonymous registry token from the auth endpoint (&lt;code&gt;/v2/auth&lt;/code&gt;) and chooses the audience.&lt;/li&gt;
&lt;li&gt;That token passes the key server's checks, so the client can ask the key server to add or rotate a key.&lt;/li&gt;
&lt;li&gt;The attacker's key is accepted as trusted. It can be set with no expiry, and it survives restarts.&lt;/li&gt;
&lt;li&gt;With that key the attacker can sign tokens that Quay honors for any repository, and can pull private images or push tampered ones under existing tags.&lt;/li&gt;
&lt;li&gt;Red Hat's report also says the rotation deletes the legitimate instance key as a side effect, and the attacker's key can delete replacement keys. That can break legitimate pushes and pulls.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two points from Red Hat that change what you might assume:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Turning off anonymous access does not protect you.&lt;/strong&gt; Red Hat says any valid Quay account can still exploit the flaw.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resetting passwords or regenerating robot tokens does not remove the attacker's key.&lt;/strong&gt; The key lives in Quay's key store, not in a user credential.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A second flaw in the same fix: CVE-2026-110697
&lt;/h2&gt;

&lt;p&gt;The same researcher, Red Hat's Dave O'Connor, found a related issue, scored 9.9. As The Hacker News describes it, the robot-account listing code builds a SQL &lt;code&gt;LIKE&lt;/code&gt; pattern from the namespace name without escaping wildcards. In SQL &lt;code&gt;LIKE&lt;/code&gt;, an underscore matches any single character, so a crafted namespace can match another tenant's namespace and return its robot accounts with their tokens. The only prerequisite reported is the ability to create a namespace. Stolen robot tokens allow reading, pushing or overwriting another tenant's images.&lt;/p&gt;

&lt;p&gt;This one is easier to understand if you have written SQL: it is the same class of mistake as forgetting that &lt;code&gt;%&lt;/code&gt; and &lt;code&gt;_&lt;/code&gt; are special inside a &lt;code&gt;LIKE&lt;/code&gt;. Escape them, or use an exact match when you mean one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which versions are fixed?
&lt;/h2&gt;

&lt;p&gt;This is the part to verify with Red Hat directly, because the sources disagree on timing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Hacker News reports fixed builds for eight Quay 3 branches. It also notes that, when it checked, the CVE entry still showed no fix, and that the second CVE was not listed in the individual advisories.&lt;/li&gt;
&lt;li&gt;A third-party aggregator's summary of Red Hat advisory RHSA-2026:99026 (Red Hat Quay 3.17.7, published 11 November, updated 13 November) lists both CVE-2026-123710 and CVE-2026-110697 among 25 fixed CVEs. I could not open Red Hat's errata page itself, so confirm it on Red Hat's site.&lt;/li&gt;
&lt;li&gt;No fixed Quay 5 build was identified in the sources I read.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice: find your Quay version, look up the errata for your branch on the Red Hat Customer Portal, and upgrade to the build that lists CVE-2026-123710. If your branch has no fixed build yet, use the mitigations below and follow Red Hat's solution article referenced in the coverage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do first
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Restrict the key endpoint
&lt;/h3&gt;

&lt;p&gt;Red Hat's mitigation is to restrict access to the &lt;code&gt;/keys&lt;/code&gt; endpoint at the proxy or load balancer, so that only trusted internal components can reach it. Here is an nginx example. Adjust the network range to match your internal services:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;allow&lt;/span&gt; &lt;span class="mf"&gt;10.20&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;# internal components that need the key server&lt;/span&gt;
    &lt;span class="n"&gt;deny&lt;/span&gt;  &lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//quay_backend;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I tested this pattern with nginx 1.24 in front of a dummy upstream. From a client outside the allowed range, all of these returned &lt;strong&gt;403&lt;/strong&gt;: &lt;code&gt;/keys&lt;/code&gt;, &lt;code&gt;/keys/services/quay/keys/abc&lt;/code&gt;, &lt;code&gt;//keys/x&lt;/code&gt;, &lt;code&gt;/%6beys/x&lt;/code&gt; (URL-encoded) and &lt;code&gt;/keysfoo&lt;/code&gt; (it is a prefix match), and so did a PUT. From an allowed client, the same path reached the upstream and returned 200. Things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/KEYS&lt;/code&gt; (upper case) was &lt;em&gt;not&lt;/em&gt; blocked; it reached the upstream. nginx matches paths case-sensitively. Whether Quay treats that path as the same endpoint I could not check, so test your own deployment and, if needed, deny at a broader level.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;quay_backend&lt;/code&gt; with your real upstream, and keep your existing proxy settings. This snippet is not a complete Quay configuration.&lt;/li&gt;
&lt;li&gt;If another load balancer sits in front of nginx, the client address nginx sees is that balancer's. Configure real client IP handling, or apply the restriction on the outermost layer.&lt;/li&gt;
&lt;li&gt;One vendor write-up also suggests limiting &lt;code&gt;/v2/auth&lt;/code&gt;. Be careful: ordinary &lt;code&gt;docker login&lt;/code&gt; and pulls go through the auth endpoint, so blocking it for clients will break normal use. Red Hat's stated mitigation names &lt;code&gt;/keys&lt;/code&gt; only.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check which parts of your own platform (Clair, build workers, operators) talk to the key server before you apply a deny rule, so you do not cut them off.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Look for planted keys
&lt;/h3&gt;

&lt;p&gt;Red Hat's guidance is to review audit logs for &lt;code&gt;service_key_rotate&lt;/code&gt; and &lt;code&gt;service_key_delete&lt;/code&gt; events where the &lt;code&gt;expiration_date&lt;/code&gt; is null, and to remove unrecognized approved keys. Legitimate service keys are normally expected to expire, so a key with no expiry added through the key server deserves attention. I cannot show you the exact query, because it depends on how you export Quay's audit log (the UI, the log database or your log shipper).&lt;/p&gt;

&lt;p&gt;Two cautions from Red Hat's text: deleting a rogue key is not durable until you are on a fixed build, because the attacker can add it again, and compromise of a key means you should treat what that key could access as exposed.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Patch
&lt;/h3&gt;

&lt;p&gt;Upgrade to a fixed build as described above. After the upgrade, repeat the audit-log and key review, since a key planted earlier would survive an upgrade unless you remove it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Assume images may have been touched? Verify them
&lt;/h2&gt;

&lt;p&gt;If your registry was reachable by untrusted clients while vulnerable, you cannot tell from the registry alone that a tag still points to what you built. The defense is not to trust tags at all.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reference images by digest&lt;/strong&gt; in Kubernetes manifests and deployment files: &lt;code&gt;image: quay.example.com/org/app@sha256:&amp;lt;digest&amp;gt;&lt;/code&gt;. A digest identifies content; if someone overwrites a tag, a deployment pinned by digest still gets the original image or fails to pull.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Record the digest at build time&lt;/strong&gt;, in your CI output, and compare it with what the registry serves now. Tools such as &lt;code&gt;skopeo inspect&lt;/code&gt; or &lt;code&gt;crane digest&lt;/code&gt; can read a digest from a registry. I have not run them against Quay.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Audit recent pushes and tag changes&lt;/strong&gt; for ones you cannot match to a pipeline run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rotate secrets&lt;/strong&gt; that were baked into images. Private images can contain credentials, and this flaw exposes private images. Rotating the Quay robot tokens alone is not enough, as noted above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consider image signing&lt;/strong&gt; (for example Sigstore's cosign) so deployment can verify who built an image. That is a broader project and I did not test it here.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Who should worry most
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Teams running Quay on a network reachable by many users, partners or the internet.&lt;/li&gt;
&lt;li&gt;Multi-tenant installations, because of the second flaw.&lt;/li&gt;
&lt;li&gt;Anyone whose CI/CD pulls base images or deploy images from Quay automatically. A swapped image is a supply chain attack on everything downstream.&lt;/li&gt;
&lt;li&gt;OpenShift users on the integrated registry or the mirror registry, which are listed as affected by The Hacker News.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Red Hat's hosted Quay.io service was listed as already patched for the second CVE at the time of disclosure by one write-up; I found no equivalent statement for the first one, so check Red Hat's notice if you use the hosted service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Disabling anonymous access and considering the problem solved. Any valid account can still exploit it.&lt;/li&gt;
&lt;li&gt;Rotating user passwords and robot tokens, but leaving a rogue signing key in place.&lt;/li&gt;
&lt;li&gt;Deleting a suspicious key before patching, and not checking that it did not come back.&lt;/li&gt;
&lt;li&gt;Blocking &lt;code&gt;/v2/auth&lt;/code&gt; broadly and breaking normal logins.&lt;/li&gt;
&lt;li&gt;Patching without checking that your branch's errata actually lists the CVE.&lt;/li&gt;
&lt;li&gt;Pulling by mutable tags (&lt;code&gt;:latest&lt;/code&gt;, &lt;code&gt;:prod&lt;/code&gt;) when integrity matters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/palo-alto-pan-os-cve-2026-0330-panorama-rce" rel="noopener noreferrer"&gt;Palo Alto PAN-OS Root RCE (CVE-2026-0330): Who Is Affected and What to Patch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/chrome-zero-day-cve-2026-125350-update-check" rel="noopener noreferrer"&gt;Chrome Zero-Day CVE-2026-125350: What It Is, Who Is Affected and How to Update&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/cursor-claude-code-extension-backdoor-what-to-check" rel="noopener noreferrer"&gt;Malicious Claude Code Extension in the Cursor Marketplace: What Happened and How to Check Your Machine&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is CVE-2026-123710 being exploited?
&lt;/h3&gt;

&lt;p&gt;None of the sources I read says it is. One write-up lists no public exploit. Treat it as exploitable, because the attack needs no authentication and Red Hat has published the details.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does it need an account?
&lt;/h3&gt;

&lt;p&gt;No. Anonymous access, which is enabled by default according to one report, is enough. With anonymous access disabled, any valid account is enough, per Red Hat.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is Quay 5 affected?
&lt;/h3&gt;

&lt;p&gt;The Hacker News reports that Red Hat lists all Quay 3 and Quay 5 versions as affected. I found no fixed Quay 5 build in the sources, so ask Red Hat or check the advisory.&lt;/p&gt;

&lt;h3&gt;
  
  
  Will changing my passwords help?
&lt;/h3&gt;

&lt;p&gt;No. The attacker's signing key is separate from user passwords and robot tokens, and it has to be removed from the key store.&lt;/p&gt;

&lt;h3&gt;
  
  
  Can I just block /keys and skip patching?
&lt;/h3&gt;

&lt;p&gt;Blocking it reduces exposure, and it is Red Hat's recommended mitigation while you patch. It is not a replacement for the fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  update log
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;15 November 2026:&lt;/strong&gt; first version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To recheck on each update:&lt;/strong&gt; Red Hat's CVE page and errata for fixed versions per branch, any exploitation reports, a Quay 5 fix, and Red Hat's solution article for key removal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://access.redhat.com/security/cve/cve-2026-123710" rel="noopener noreferrer"&gt;Red Hat Customer Portal: CVE-2026-123710&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.securityweek.com/critical-red-hat-quay-vulnerability-could-expose-private-container-images/" rel="noopener noreferrer"&gt;SecurityWeek: Critical Red Hat Quay Vulnerability Could Expose Private Container Images&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://thehackernews.com/2026/11/critical-red-hat-quay-flaw-lets.html" rel="noopener noreferrer"&gt;The Hacker News: Critical Red Hat Quay Flaw Lets Attackers Read and Overwrite All Private Container Images&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gbhackers.com/critical-red-hat-quay-vulnerability/" rel="noopener noreferrer"&gt;GBHackers: Critical Red Hat Quay Vulnerability Allows Hackers to Hijack Private Container Registries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aviatrix.ai/threat-research-center/critical-red-hat-quay-flaw-cve-2026-123710-cve-2026-110697-container-registry-compromise/" rel="noopener noreferrer"&gt;Aviatrix: Critical Red Hat Quay Flaws (vendor write-up; see caveats in the checks section)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://radar.offseq.com/threat/red-hat-security-advisory-red-hat-quay-3177-4b4c484d51119e46" rel="noopener noreferrer"&gt;OffSeq Threat Radar: Red Hat Security Advisory, Red Hat Quay 3.17.7 (aggregator)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/red-hat-quay-cve-2026-123710" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>redhatquay</category>
      <category>containerregistry</category>
      <category>cve</category>
    </item>
    <item>
      <title>Nginx 502 Bad Gateway with PHP-FPM: Causes and Fixes</title>
      <dc:creator>devTalk</dc:creator>
      <pubDate>Sun, 15 Nov 2026 04:19:38 +0000</pubDate>
      <link>https://dev.to/devtalk94/nginx-502-bad-gateway-with-php-fpm-causes-and-fixes-ei6</link>
      <guid>https://dev.to/devtalk94/nginx-502-bad-gateway-with-php-fpm-causes-and-fixes-ei6</guid>
      <description>&lt;p&gt;A 502 page tells you nothing. It means Nginx asked PHP-FPM for a response and either couldn't reach it or got something it couldn't use. The browser can't tell you which, but the Nginx error log can, in one line. Most 502 problems are solved by reading that line and matching it to a cause, and this article is organized that way.&lt;/p&gt;

&lt;p&gt;Every error message below is real output. I built an Nginx 1.24.0 and PHP-FPM 8.3.6 setup on Ubuntu 24.04, caused each failure on purpose, and copied the log lines. Paths use the Ubuntu defaults (&lt;code&gt;/var/log/nginx/error.log&lt;/code&gt;, &lt;code&gt;/var/log/php8.3-fpm.log&lt;/code&gt;, &lt;code&gt;/run/php/php8.3-fpm.sock&lt;/code&gt;); adjust for your distribution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step one: read the error log
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo tail -n 20 /var/log/nginx/error.log
sudo tail -n 20 /var/log/php8.3-fpm.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the 502 request in the first file. The message after it is your cause:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Nginx error log says&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;th&gt;Go to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;connect() to unix:… failed (2: No such file or directory)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PHP-FPM isn't running, or the socket path is wrong&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;connect() … failed (111: Connection refused)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Nothing is listening there (stopped, crashed, wrong port)&lt;/td&gt;
&lt;td&gt;
1, 3
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;connect() … failed (13: Permission denied)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Nginx can't open the socket&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;recv() failed (104: Connection reset by peer) while reading response header&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The PHP worker died or was killed mid-request&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;connect() … failed (11: Resource temporarily unavailable)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;All workers busy and the queue is full&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;upstream sent too big header while reading response header&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Response headers exceed Nginx's buffer&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  1. PHP-FPM is down, or the socket path is wrong
&lt;/h2&gt;

&lt;p&gt;The most common one. With PHP-FPM stopped cleanly, the socket file is removed and Nginx logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/var/tmp/fpmtest/php.sock failed (2: No such file or directory) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(My test socket lived in &lt;code&gt;/var/tmp/fpmtest&lt;/code&gt;; yours will be under &lt;code&gt;/run/php/&lt;/code&gt;.) The same message appears when PHP-FPM is running but &lt;code&gt;fastcgi_pass&lt;/code&gt; points at a different file. Pointing at a socket that doesn't exist gives exactly the same error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/var/tmp/fpmtest/php8.2-fpm.sock failed (2: No such file or directory) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This often follows a PHP upgrade: the package installs &lt;code&gt;php8.3-fpm&lt;/code&gt; with a new socket name while the Nginx site still references the old one. The stock Ubuntu 24.04 site template even ships a commented example that still says &lt;code&gt;php7.4-fpm.sock&lt;/code&gt;, which is easy to copy by mistake. Check what is actually listening and compare it with your config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ls /run/php/
ss -xl &lt;span class="o"&gt;|&lt;/span&gt; grep php
grep -R &lt;span class="s2"&gt;"fastcgi_pass"&lt;/span&gt; /etc/nginx/sites-enabled/
grep -n &lt;span class="s2"&gt;"^listen"&lt;/span&gt; /etc/php/8.3/fpm/pool.d/www.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ss -xl | grep php
u_str LISTEN php.sock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Trimmed to the useful columns.) The correct Ubuntu pairing is &lt;code&gt;listen = /run/php/php8.3-fpm.sock&lt;/code&gt; in the pool and the same path in the site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; \&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;$ &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="n"&gt;snippets&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;fastcgi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;fastcgi_pass&lt;/span&gt; &lt;span class="n"&gt;unix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;php8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;fpm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sock&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A harder-killed PHP-FPM behaves differently. I used &lt;code&gt;kill -9&lt;/code&gt; on the master process, which doesn't clean up. The socket file stayed on disk, so the message changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/var/tmp/fpmtest/php.sock failed (111: Connection refused) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A socket file that exists but refuses connections means nobody is behind it. Start the service (&lt;code&gt;sudo systemctl restart php8.3-fpm&lt;/code&gt;), then look at &lt;code&gt;/var/log/php8.3-fpm.log&lt;/code&gt; to see why it stopped.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Permission denied on the socket
&lt;/h2&gt;

&lt;p&gt;PHP-FPM creates the socket with the owner, group and mode from the pool. The PHP manual notes that on Linux, read and write permission on the socket is required for the web server to connect, and that the mode defaults to 0660 with the owner and group set to the user running the pool. If the Nginx worker user isn't that owner or in that group, it can't connect. I broke it deliberately with &lt;code&gt;listen.owner = root&lt;/code&gt;, &lt;code&gt;listen.group = root&lt;/code&gt; and &lt;code&gt;listen.mode = 0600&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/var/tmp/fpmtest/php.sock failed (13: Permission denied) while connecting to upstream

$ ls -l /var/tmp/fpmtest/php.sock
srw------- root root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fix is to make the pool's socket settings match the user from the &lt;code&gt;user&lt;/code&gt; directive in &lt;code&gt;nginx.conf&lt;/code&gt; (&lt;code&gt;www-data&lt;/code&gt; on Ubuntu):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; /etc/php/8.3/fpm/pool.d/www.conf
&lt;/span&gt;&lt;span class="na"&gt;listen.owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
&lt;span class="na"&gt;listen.group&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
&lt;span class="na"&gt;listen.mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0660&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls -l /var/tmp/fpmtest/php.sock
srw-rw---- www-data www-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart PHP-FPM afterward. The socket is created at startup, so a reload of Nginx alone changes nothing. Also check the directory: Nginx must be able to traverse every directory in the socket's path.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. A TCP port mismatch
&lt;/h2&gt;

&lt;p&gt;If you use TCP instead of a socket, both sides must agree on the address. With Nginx pointing at &lt;code&gt;127.0.0.1:9001&lt;/code&gt; and nothing listening there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() failed (111: Connection refused) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare &lt;code&gt;fastcgi_pass 127.0.0.1:9000;&lt;/code&gt; with the pool's &lt;code&gt;listen =&lt;/code&gt; line. The PHP manual warns that an exposed FastCGI port allows arbitrary code execution, so keep TCP bound to &lt;code&gt;127.0.0.1&lt;/code&gt; and list allowed clients if you must listen on a network address. On a single host, a Unix socket is the safer choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The PHP worker dies mid-request
&lt;/h2&gt;

&lt;p&gt;This one is different: the connection succeeds, then the worker disappears before it replies. To reproduce it I had a script kill its own process with signal 11 (segmentation fault):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nginx: recv() failed (104: Connection reset by peer) while reading response header from upstream
PHP-FPM: WARNING: [pool www] child 2585 exited on signal 11 (SIGSEGV) after 1.222179 seconds from start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two logs together are the diagnosis: Nginx says the connection was reset, PHP-FPM says which worker died and from which signal. A real segfault usually comes from a PHP extension or a bug in a PHP build, so look at what changed recently. Signal 9 (SIGKILL) is different. I did not test it, but in practice it often means the kernel's out-of-memory killer, so check &lt;code&gt;dmesg&lt;/code&gt; or &lt;code&gt;journalctl -k&lt;/code&gt; for "Out of memory" around the same timestamp.&lt;/p&gt;

&lt;h3&gt;
  
  
  Slow script killed by request_terminate_timeout: a 502, not a 504
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;request_terminate_timeout&lt;/code&gt; (default 0, meaning off) kills a worker that's been serving one request too long. With it set to &lt;code&gt;2s&lt;/code&gt; and a script that sleeps six seconds, the browser sees a 502, not a timeout error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Nginx: recv() failed (104: Connection reset by peer) while reading response header from upstream
PHP-FPM: WARNING: [pool www] child 2611, script '/var/tmp/fpmtest/www/slow.php' (request: "GET /slow.php?s=6") execution timed out (2.114876 sec), terminating
PHP-FPM: WARNING: [pool www] child 2611 exited on signal 15 (SIGTERM) after 3.336074 seconds from start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PHP-FPM log names the script and request, so you know exactly what to fix. Compare that with the case where Nginx gives up first, with &lt;code&gt;fastcgi_read_timeout 2s;&lt;/code&gt; and no FPM limit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP 504
upstream timed out (110: Connection timed out) while reading response header from upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A rule of thumb from these two results: &lt;strong&gt;504 means Nginx stopped waiting, 502 with "Connection reset" means PHP-FPM ended the request or died.&lt;/strong&gt; Nginx's &lt;code&gt;fastcgi_read_timeout&lt;/code&gt; defaults to 60 seconds and applies between two successive reads, not to the whole response. Raising timeouts only hides a slow request; find out why it's slow first. For long exports and reports, queue the work instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. All workers are busy
&lt;/h2&gt;

&lt;p&gt;PHP-FPM can only serve &lt;code&gt;pm.max_children&lt;/code&gt; requests at once. Ubuntu's default pool uses &lt;code&gt;pm = dynamic&lt;/code&gt; and &lt;code&gt;pm.max_children = 5&lt;/code&gt;, which is small for a busy site. I limited the pool to one worker and sent three slow requests at once. By default, extra requests wait in the socket's backlog (the PHP manual gives 511 as the Linux default), so they don't fail at once. They time out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;slow.php?s=5 -&amp;gt; HTTP 504
slow.php?s=5 -&amp;gt; HTTP 504
slow.php?s=5 -&amp;gt; HTTP 504

Nginx: upstream timed out (110: Connection timed out) while reading response header from upstream
PHP-FPM: WARNING: [pool www] server reached pm.max_children setting (1), consider raising it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PHP-FPM warning is the confirmation. In my test the symptom was a 504. A 502 appears when the queue itself is full. I set &lt;code&gt;listen.backlog = 1&lt;/code&gt; to make that easy to see, with five simultaneous requests to a one-worker pool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;connect() to unix:/var/tmp/fpmtest/php.sock failed (11: Resource temporarily unavailable) while connecting to upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In that run two requests got a 502 with that message, two succeeded, and one timed out, so you may see a mix. On a real server the default backlog is large, so you'll normally meet the 504 form first. The fix is the same: serve requests faster, or allow more workers. For memory-based sizing, measure what one worker actually uses under your real application, not an idle one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ps --no-headers -o rss,cmd -C php-fpm8.3 &lt;span class="o"&gt;|&lt;/span&gt; grep pool \
  &lt;span class="o"&gt;|&lt;/span&gt; awk &lt;span class="s1"&gt;'{s+=$1; n++} END {printf "%d workers, average %.0f MB each\n", n, s/n/1024}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3 workers, average 13 MB each
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That 13 MB is for a bare test script; a framework application will be much larger, and the number only means something measured on your own app under load. A common rule of thumb is to divide the memory you can spare for PHP by the average worker size and keep a margin, then set &lt;code&gt;pm.max_children&lt;/code&gt; below that. Don't raise it past what the database can handle either, since more workers means more connections.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The response header is too big
&lt;/h2&gt;

&lt;p&gt;Nginx reads the start of the FastCGI response, the headers, into one buffer (&lt;code&gt;fastcgi_buffer_size&lt;/code&gt;, 4k or 8k by default according to the Nginx docs). Large cookies, long redirect URLs, or many &lt;code&gt;Set-Cookie&lt;/code&gt; headers can overflow it. A script that sends a 9,000-byte header reproduces it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;upstream sent too big header while reading response header from upstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The obvious fix doesn't work on its own. I set only &lt;code&gt;fastcgi_buffer_size 16k;&lt;/code&gt; and Nginx refused to start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[emerg] "fastcgi_busy_buffers_size" must be less than the size of all "fastcgi_buffers" minus one buffer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Nginx docs say the default &lt;code&gt;fastcgi_busy_buffers_size&lt;/code&gt; is the size of two buffers, so it grows with the header buffer. With a 16k header buffer and the default eight 4k response buffers, it no longer fits, so the response buffers have to grow too. This worked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;fastcgi_buffer_size&lt;/span&gt; &lt;span class="mi"&gt;16k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;fastcgi_buffers&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="mi"&gt;16k&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The request returned 200. This is also why you should always run &lt;code&gt;sudo nginx -t&lt;/code&gt; before reloading; the error above would have taken the site down on a restart. If your headers are huge because of cookies, consider whether the application is storing too much in them.&lt;/p&gt;

&lt;h2&gt;
  
  
  A five-command checklist
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo tail -n 20 /var/log/nginx/error.log      &lt;span class="c"&gt;# what Nginx saw&lt;/span&gt;
sudo tail -n 20 /var/log/php8.3-fpm.log       &lt;span class="c"&gt;# what PHP-FPM saw&lt;/span&gt;
ss -xl &lt;span class="o"&gt;|&lt;/span&gt; grep php                              &lt;span class="c"&gt;# is a socket listening?&lt;/span&gt;
sudo nginx -t                                  &lt;span class="c"&gt;# is the Nginx config valid?&lt;/span&gt;
sudo php-fpm8.3 -t                             &lt;span class="c"&gt;# is the pool config valid?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nginx -t -c nginx.conf
nginx: the configuration file nginx.conf syntax is ok
nginx: configuration file nginx.conf test is successful
$ php-fpm8.3 -t -y php-fpm.conf
NOTICE: configuration file php-fpm.conf test is successful
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(My test used custom config paths, hence the &lt;code&gt;-c&lt;/code&gt; and &lt;code&gt;-y&lt;/code&gt; options; on a normal install just run the commands as in the list above.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Restarting Nginx when PHP-FPM is the problem.&lt;/strong&gt; Nginx is rarely the broken part; read both logs first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Raising&lt;/strong&gt;&lt;code&gt;fastcgi_read_timeout&lt;/code&gt;&lt;strong&gt;to "fix" a 504.&lt;/strong&gt; It only hides the slow request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Changing socket permissions but only reloading Nginx.&lt;/strong&gt; The socket belongs to PHP-FPM; restart that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting the socket name after a PHP upgrade.&lt;/strong&gt; It includes the version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Setting&lt;/strong&gt;&lt;code&gt;pm.max_children&lt;/code&gt;&lt;strong&gt;from guesswork.&lt;/strong&gt; Measure real worker memory and respect the database limits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping&lt;/strong&gt;&lt;code&gt;nginx -t&lt;/code&gt;&lt;strong&gt;.&lt;/strong&gt; One bad directive can stop the whole server on restart.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Alternatives
&lt;/h2&gt;

&lt;p&gt;Unix socket versus TCP is a trade-off, not a rule. A socket avoids a network port and is controlled by file permissions, which is why the PHP manual prefers it when the web server is on the same host. TCP is needed when PHP-FPM runs in a separate container or machine. This article's examples use Nginx only; I did not test Apache with PHP-FPM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Dev Talk articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-scheduler-not-running-cron-fixes" rel="noopener noreferrer"&gt;Laravel Scheduler Not Running: Cron and schedule:run Fixes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/laravel-env-configuration-env-vs-config" rel="noopener noreferrer"&gt;Laravel .env Configuration: env() vs config() Explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev-talk.com/post/detect-fix-memory-leaks-php-applications" rel="noopener noreferrer"&gt;How to Detect and Fix Memory Leaks in PHP Applications&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the difference between 502, 503 and 504?
&lt;/h3&gt;

&lt;p&gt;In this setup, 502 means Nginx couldn't get a valid response from PHP-FPM, 504 means it waited too long (the timeout cases above), and a 500 usually comes from the application itself, such as an uncaught PHP error. I haven't covered 503 here.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is a 502 always a PHP-FPM problem?
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;fastcgi_pass&lt;/code&gt;, the upstream is PHP-FPM, so yes in practice, though the cause can be Nginx's own configuration, such as a wrong socket path or buffer size. If you proxy to another app server, the same log-reading approach applies but the messages name that server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does it only happen under load?
&lt;/h3&gt;

&lt;p&gt;Usually worker exhaustion (cause 5): too few workers, or slow requests holding them. Look for the "reached pm.max_children" warning and check what the slow requests are doing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Should I use a socket or TCP?
&lt;/h3&gt;

&lt;p&gt;A socket on a single host; TCP when PHP-FPM is elsewhere. Make sure Nginx and PHP-FPM agree, and restrict TCP to localhost or trusted addresses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/install.fpm.configuration.php" rel="noopener noreferrer"&gt;PHP Manual: FastCGI Process Manager (FPM) configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://freenginx.org/en/docs/http/ngx_http_fastcgi_module.html" rel="noopener noreferrer"&gt;Module ngx_http_fastcgi_module (documentation copy)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://dev-talk.com/post/nginx-502-bad-gateway-php-fpm-causes-fixes" rel="noopener noreferrer"&gt;DEV Talk&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>phpfpm</category>
      <category>502badgateway</category>
      <category>troubleshooting</category>
    </item>
  </channel>
</rss>
