<!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"> <link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" /> <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"> </head> <body> <div class="container text-start"> <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" style="position:sticky;top:0px;"> <h1 class="display-3 logo" style="font-weight:700;" id="logo"> <span style="color:#282828;background-color:#ebdbb2;">ac</span> </h1> <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="/til" class="text-decoration-none"> TIL </a> </h4> </div> <div class="col"> <h4> <a href="/projects" class="text-decoration-none"> PROJECTS </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" style="font-family: Arial, Helvetica, sans-serif;"> <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> <a rel="me" href="/feed.xml" target="_blank"><i class="fas fa-square-rss"></i></a> </span> </div> </h4> </div> <hr class="menu"> </div> </div> <div class="col col-md-9" style="position: relative;top: 90px;"> <h1 style="font-weight: 500;"> Fixing php errors in a Nextcloud docker-compose configuration </h1> <p> </p> <p style="font-family:Fira Code;font-weight:500;"> <i class="fas fa-calendar"></i> 01 Mar 2023 | <i class="fas fa-clock"></i> 2 minutes </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>