Internal Server Error after PHP Upgrade

Nextcloud version (eg, 20.0.5): 24.0.6
Operating system and version (eg, Ubuntu 20.04): Debian 10
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.38
PHP version (eg, 7.4): 8.1

The issue you are facing:
I get the internal server error page from nextcloud after upgrading from PHP 7.4 to 8.1.

The output of your Nextcloud log in Admin > Logging:

{"reqId":"jeaLwinQGCzCh5QeUyWZ","level":3,"time":"2022-10-24T18:26:42+00:00","remoteAddr":"***","user":"--","app":"index","method":"GET","url":"/","message":"Configuration was not read or initialized correctly, not overwriting /var/www/nextcloud/config/config.php","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"","exception":{"Exception":"OCP\\HintException","Message":"Configuration was not read or initialized correctly, not overwriting /var/www/nextcloud/config/config.php","Code":0,"Trace":[{"file":"/var/www/nextcloud/lib/private/Config.php","line":143,"function":"writeData","class":"OC\\Config","type":"->"},{"file":"/var/www/nextcloud/lib/private/SystemConfig.php","line":142,"function":"setValue","class":"OC\\Config","type":"->"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_Util.php","line":906,"function":"setValue","class":"OC\\SystemConfig","type":"->"},{"file":"/var/www/nextcloud/lib/base.php","line":427,"function":"getInstanceId","class":"OC_Util","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":666,"function":"initSession","class":"OC","type":"::"},{"file":"/var/www/nextcloud/lib/base.php","line":1111,"function":"init","class":"OC","type":"::"},{"file":"/var/www/nextcloud/index.php","line":34,"args":["/var/www/nextcloud/lib/base.php"],"function":"require_once"}],"File":"/var/www/nextcloud/lib/private/Config.php","Line":258,"Hint":"Configuration was not read or initialized correctly, not overwriting /var/www/nextcloud/config/config.php","CustomMessage":"--"}}
{"reqId":"jeaLwinQGCzCh5QeUyWZ","level":3,"time":"2022-10-24T18:26:42+00:00","remoteAddr":"***","user":"--","app":"index","method":"GET","url":"/","message":"Failed to connect to the database: An exception occurred in the driver: could not find driver","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36","version":"","exception":{"Exception":"Doctrine\\DBAL\\Exception","Message":"Failed to connect to the database: An exception occurred in the driver: could not find driver","Code":0,"Trace":[{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":1519,"function":"connect","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php","line":1041,"function":"getWrappedConnection","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/Connection.php","line":261,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php","line":345,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php","line":281,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":411,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":176,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/nextcloud/lib/private/AppConfig.php","line":367,"function":"getApps","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/nextcloud/lib/private/App/AppManager.php","line":127,"function":"getValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/nextcloud/lib/private/App/AppManager.php","line":216,"function":"getInstalledAppsValues","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/nextcloud/lib/private/legacy/OC_Template.php","line":286,"function":"isEnabledForUser","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/nextcloud/index.php","line":44,"function":"printErrorPage","class":"OC_Template","type":"::"}],"File":"/var/www/nextcloud/lib/private/DB/Connection.php","Line":139,"CustomMessage":"--"}}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => ***,
  'passwordsalt' => ***,
  'secret' => ***,
  'trusted_domains' => 
  array (
    0 => ***,
    1 => ***,
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'overwrite.cli.url' => ***,
  'dbtype' => 'mysql',
  'version' => '24.0.6.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => ***,
  'installed' => true,
  'maintenance' => false,
  'theme' => '',
  "log_type" => "file",
  "logfile" => "nextcloud.log",
  "loglevel" => 4,
  "logdateformat" => "F d, Y H:i:s",
  'updater.release.channel' => 'stable',
  'mysql.utf8mb4' => true,
  'updater.secret' => ***,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'tls',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => ***,
  'mail_domain' => 'live.de',
  'mail_smtpauth' => 1,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtphost' => 'smtp-mail.outlook.com',
  'mail_smtpport' => '587',
  'mail_smtpname' => ***,
  'mail_smtppassword' => ***,
  'default_phone_region' => 'DE',
);

Generally whenever you start to get internal server errors after messing with PHP it means you’re missing a PHP module that Nextcloud requires to function.

In this case your problem is:

{"reqId":"jeaLwinQGCzCh5QeUyWZ","level":3,"time":"2022-10-24T18:26:42+00:00","remoteAddr":"***","user":"--","app":"index","method":"GET","url":"/","message":"Failed to connect to the database: An exception occurred in the driver: could not find driver",

Either you are missing the PHP extension for whatever database you’re using for Nextcloud or your installation is messed up somehow.

MariaDB/MySQL databases need the “mysql” extension.

Per the admin manual Nextcloud requires the following extensions to run:

ctype
curl
dom
GD
json (should be included with PHP >=8.0)
libxml
mbstring
openssl (should be included with PHP >=8.0)
posix
session
simplexml
xmlreader
xmlwriter
zip
zlib

Database connector:

mysql (MariaDB/MySQL)
sqlite (SQLite)
pgsql (PostgreSQL)

In addition these modules need to be enabled in php.ini. Make sure all these modules and your database connector are enabled with “extension=module name.”

Nextcloud 24 will run fine on PHP 8.1 provided the modules it needs are installed and are enabled. My install uses the latest stable version 8.1.11 with no issues.

I have installed all the extensions. I activated some of them in

/etc/php/8.1/apache2/php.ini

and in

/etc/php/8.1/cli/php.ini

by uncommenting the lines but not for all the modules there were lines with extension=modulename. Do I have to activate all the others by adding lines to my php.ini files?

As for mysql I uncommented pdo_mysql and mysqli. Does Nextcloud use them both?

After activating the modules I got this error message when running php -m

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20210902/pdo_mysql (/usr/lib/php/20210902/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20210902/pdo_mysql.so (/usr/lib/php/20210902/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0

So I did a complete reinstall of php (following this post, additionally I installed libapache2-mod-php8.1) but I still get the same error (driver could not be found).

I removed all the PHP stuff, upgraded to Debian 11 and installed PHP 7.4.

Still getting the database driver could not be found error.

My PHP.ini uses these lines and Nextcloud works fine. Try sticking this in there:

extension=apcu
extension=bcmath
;extension=bz2
;extension=calendar
extension=curl
;extension=dba
;extension=enchant
;extension=exif
;extension=ffi
;extension=ftp
extension=gd
;extension=gettext
extension=gmp
;extension=iconv
extension=igbinary
;extension=imap
extension=imagick
extension=intl
;extension=ldap
extension=mysqli
;extension=odbc
zend_extension=opcache
;extension=pdo_dblib
extension=pdo_mysql
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=pspell
extension=redis
;extension=shmop
;extension=snmp
;extension=soap
extension=sockets
;extension=sodium
extension=sqlite3
;extension=sysvmsg
;extension=sysvsem
;extension=sysvshm
;extension=tidy
;extension=xsl
extension=zip

You don’t need pdo_sqlite, that’s for another web app I have running on the same server.

What database are you using?

When modules are enabled with extension= in PHP.ini, PHP will load them from the default install directory /usr/lib/php/modules. If the module isn’t in there and there’s no other path specified it’ll fail to load the module.

I notice PHP is trying to load the MySQL driver from /usr/lib/php/20210902, not /usr/lib/php/modules. Check that pdo_mysql.so is actually in that directory or whatever directory you’re using to store PHP modules.

As I type this, on that note, here’s your problem:

(/usr/lib/php/20210902/pdo_mysql: cannot open shared object file: No such file or directory)

The MySQL driver isn’t in that directory. You may need to find where pdo_mysql.so is located on your system and manually move it to the right place. Debian should be installing automatically to /usr/lib/php/modules AFAIK – not sure where you’re getting /usr/lib/php/20210902.

Edit: Run php-config --extension-dir and that will tell you where all your modules need to be stored.