192 lines
8.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:image" content="https://andrewconl.in/assets/images/og-image-template.jpg">
<title>andrew conlin</title>
<link href="https://use.fontawesome.com/releases/v6.0.0/css/all.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/assets/css/default.css" rel="stylesheet">
<style>
code {
color: #ed0;
}
pre {
color: #ed0
}
::selection {
background-color: #ed0;
color: black
}
</style>
</head>
<body>
<div class="container text-start">
<h1 class="display-3" style="font-weight:700;position:sticky;top:0;backdrop-filter:blur(10px);z-index:1000;" id="logo">
<span style="color:black;background-color:#ed0;">ac</span>
</h1>
<div class="row row-cols-1 row-cols-md-2">
<div class="col col-md-3">
<div class="row row-cols-1 g-0" id="nav">
<div class="col">
<h4>
<a href="/" class="text-decoration-none"> about </a>
</h4>
</div>
<div class="col">
<h4>
<a href="/blog" class="text-decoration-none"> blog </a>
</h4>
</div>
<div class="col">
<h4>
<a href="http://andrewconlinphotography.co.uk" class="text-decoration-none"> photos↗ </a>
</h4>
</div>
<div class="col gy-2">
<h4>
<div>
<span>
<a rel="me" href="https://mastodon.scot/@andrwcnln" target="_blank"><i class="fab fa-mastodon"></i></a>
<a rel="me" href="https://instagram.com/conlinsta" target="_blank"><i class="fab fa-instagram"></i></a>
<a rel="me" href="https://github.com/andrwcnln" target="_blank"><i class="fab fa-github"></i></a>
<a rel="me" href="https://www.strava.com/athletes/57896512" target="_blank"><i class="fab fa-strava"></i></a>
<a rel="me" href="https://open.spotify.com/user/1135508731?si=61zWbsqmT92LdT0JA5bAKw" target="_blank"><i class="fab fa-spotify"></i></a>
<a href="https://letterboxd.com/andrewconlin/" target="_blank"><img class="letterboxd" src="/assets/images/letterboxd.png"></a>
<a rel="me" href="mailto:andrew@andrewconl.in" target="_blank"><i class="fas fa-envelope"></i></a>
</span>
</div>
</h4>
</div>
<hr class="menu">
</div>
</div>
<div class="col col-md-9">
<h1 style="font-weight: 500;">
Fixing php errors in a Nextcloud docker-compose configuration
</h1>
<p style="font-family:Rubik;font-weight:500;">
<i class="fas fa-calendar"></i>&nbsp;01 Mar 2023
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<i class="fas fa-clock"></i>&nbsp;2 minutes
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<span style="background-color:#ed0;color:black;">&nbsp;<a class="text-decoration-none" style="color:black" href="/til/"><i class="fas fa-folder"></i>&nbsp;til</a>&nbsp;</span>
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<i class="fas fa-tag"></i>
<span style="background-color:#171717;color:white;font-family:Rubik;padding:3px;border-radius:10px;"><a class="text-decoration-none" href="/blog/tag/php">php</a></span>
,
<span style="background-color:#171717;color:white;font-family:Rubik;padding:3px;border-radius:10px;"><a class="text-decoration-none" href="/blog/tag/nextcloud">nextcloud</a></span>
,
<span style="background-color:#171717;color:white;font-family:Rubik;padding:3px;border-radius:10px;"><a class="text-decoration-none" href="/blog/tag/docker">docker</a></span>
,
<span style="background-color:#171717;color:white;font-family:Rubik;padding:3px;border-radius:10px;"><a class="text-decoration-none" href="/blog/tag/docker-compose">docker-compose</a></span>
</p>
<hr>
<p>I was trying to rescan the files in my Nextcloud server (running on Raspberry Pi 4 with DietPi), and kept running into some weird <code class="language-plaintext highlighter-rouge">php</code> errors.</p>
<h3 id="first-error---could-not-find-driver">First error - “could not find driver”</h3>
<p>I was trying using the following syntax to call <code class="language-plaintext highlighter-rouge">occ</code> and scan the files:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo -u www-data php /path/to/nextcloud/occ files:scan --all
</code></pre></div></div>
<p>but I kept running into a PHP error. Specifically this error:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: could not find driver in /path/to/nextcloud/lib/private/DB/Connection.php:139
</code></pre></div></div>
<p>followed by a long, verbose stack trace.</p>
<p>It took me a decent amount of time to diagnose the exact issue, but eventually I found <a href="https://docs.nextcloud.com/server/20/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation">this list</a> of required PHP modules in the Nextcloud admin manual.</p>
<p>Running <code class="language-plaintext highlighter-rouge">php -m</code> will print out the list of currently installed PHP modules. I noticed I was missing quite a few of the required modules, but the one that was causing my issue was the missing <code class="language-plaintext highlighter-rouge">pdo_mysql</code> module.
This can be installed by running:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install php7.4-mysql
</code></pre></div></div>
<p><strong>Note: This command will change based on your OS, PHP version and database type</strong></p>
<p>This resolved the error! However (as is always the case), this only meant I got a shiny new error instead:</p>
<h3 id="second-error---name-or-service-not-known">Second error - “Name or service not known”</h3>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/nextcloud/lib/private/DB/Connection.php:139
</code></pre></div></div>
<p>From first glance, this looks like something wrong in the DNS name resolution. This sent me a long way down the wrong path, changing a whole bunch of things in my docker-compose.yml file.
Eventually however, after a long and perilous journey over the high seas of Nextcloud forums and StackOverflow, I found <a href="https://techoverflow.net/2020/07/17/how-to-run-nextcloud-php-occ-in-a-docker-compose-configuration/">this example</a> of running <code class="language-plaintext highlighter-rouge">php occ</code> in a docker-compose configuration.
This led me to running this command:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker-compose exec -u www-data nextcloud-app php occ files:scan --all
</code></pre></div></div>
<p><strong>Note: replace nextcloud-app with the name of your Nextcloud container. Also, this command must be run from the directory of your Nextcloud docker-compose.yml</strong></p>
<p>….aaaaaand, <em>voila!</em> The command runs, the files are scanned and everything is up to date.</p>
<p><img src="/assets/images/occ.png" alt="terminal output showing the files that have been successfully been scanned" /></p>
<br>
<br>
</div>
</div>
</body>
</html>