"Internal Server Error" after upgrading PHP8.2 Synology NAS

Nextcloud version: 29.0.5
Operating system and version: Synology DSM 7.2.1-69057 Update 5
Apache or nginx version: Apache/2.4.58
PHP version: 8.2.21

The issue you are facing:

After I upgraded PHP 8.2, I now get an Internal Server Error when trying to access the Nextcloud instance.

Is this the first time you’ve seen this error? (Y/N):

Steps to replicate it:

  1. Update PHP 8.2 in DSM
  2. Try to connect to Nextcloud

The output of your Nextcloud log in Admin > Logging:

NO LOG OF THE ADMIN TAB SINCE IT ISN'T ACCESSIBLE
Output of internal log file:
Error   core     Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory at lib/private/DB/Connection.php   2024-09-11T09:32:27+00:00  
                   line 167                                                                                                                                                                                                        
                                                                                                                                                                                                                                   
                    0. 3rdparty/doctrine/dbal/src/Connection.php line 453                                                                                                                                                          
                       OC\DB\Connection->connect(                                                                                                                                                                                  
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    1. 3rdparty/doctrine/dbal/src/Connection.php line 411                                                                                                                                                          
                       Doctrine\DBAL\Connection->getDatabasePlatformVersion(                                                                                                                                                       
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    2. 3rdparty/doctrine/dbal/src/Connection.php line 318                                                                                                                                                          
                       Doctrine\DBAL\Connection->detectDatabasePlatform(                                                                                                                                                           
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    3. lib/private/DB/ConnectionAdapter.php line 200                                                                                                                                                               
                       Doctrine\DBAL\Connection->getDatabasePlatform(                                                                                                                                                              
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    4. lib/private/DB/QueryBuilder/QueryBuilder.php line 121                                                                                                                                                       
                       OC\DB\ConnectionAdapter->getDatabasePlatform(                                                                                                                                                               
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    5. lib/private/AppConfig.php line 1239                                                                                                                                                                         
                       OC\DB\QueryBuilder\QueryBuilder->expr(                                                                                                                                                                      
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    6. lib/private/AppConfig.php line 264                                                                                                                                                                          
                       OC\AppConfig->loadConfig(false)                                                                                                                                                                             
                    7. lib/private/legacy/OC_App.php line 736                                                                                                                                                                      
                       OC\AppConfig->searchValues("installed_version")                                                                                                                                                             
                    8. lib/private/TemplateLayout.php line 237                                                                                                                                                                     
                       OC_App::getAppVersions(                                                                                                                                                                                     
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                    9. lib/private/legacy/OC_Template.php line 145                                                                                                                                                                 
                       OC\TemplateLayout->__construct("error", "")                                                                                                                                                                 
                   10. lib/private/Template/Base.php line 132                                                                                                                                                                      
                       OC_Template->fetchPage(                                                                                                                                                                                     
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                   11. lib/private/legacy/OC_Template.php line 320                                                                                                                                                                 
                       OC\Template\Base->printPage(                                                                                                                                                                                
                                                                                                                                                                                                                                   
                       )                                                                                                                                                                                                           
                   12. remote.php line 88                                                                                                                                                                                          
                       OC_Template::printExceptionErrorPage(["Doctrine\\DBAL\\Exception"], 500)                                                                                                                                    
                   13. remote.php line 174                                                                                                                                                                                         
                       handleException(["Doctrine\\DBAL\\Exception"])

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

<?php
$CONFIG = array (
  'instanceid' => 'IDENTIFIABLE INFORMATION',
  'passwordsalt' => 'IDENTIFIABLE INFORMATION',
  'secret' => 'IDENTIFIABLE INFORMATION',
  'trusted_domains' => 
  array (
    0 => 'IDENTIFIABLE INFORMATION',
  ),
  'datadirectory' => '/path/to/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '29.0.5.1',
  'overwrite.cli.url' => 'IDENTIFIABLE INFORMATION',
  'dbname' => 'nextcloud_database_name',
  'dbhost' => 'localhost:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'IDENTIFIABLE INFORMATION',
  'dbpassword' => 'IDENTIFIABLE INFORMATION',
  'installed' => true,
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => '6379',
    'timeout' => 0.0,
    'password' => 'IDENTIFIABLE INFORMATION',
    'dbindex' => 0,
  ),
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'IDENTIFIABLE INFORMATION',
  'mail_domain' => 'IDENTIFIABLE INFORMATION',
  'mail_smtphost' => 'IDENTIFIABLE INFORMATION',
  'mail_smtpauth' => 1,
  'mail_smtpport' => 'IDENTIFIABLE INFORMATION',
  'mail_smtpname' => 'IDENTIFIABLE INFORMATION',
  'mail_smtppassword' => 'IDENTIFIABLE INFORMATION',
  'default_phone_region' => 'IDENTIFIABLE INFORMATION',
  'twofactor_enforced' => 'true',
  'twofactor_enforced_groups' => 
  array (
    0 => 'IDENTIFIABLE INFORMATION',
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
    0 => 'admin',
  ),
  'app_install_overwrite' => 
  array (
    0 => 'backup',
  ),
  'opcache.memory_consumption' => 256,
  'opcache.interned_strings_buffer' => 10,
  'opcache.max_accelerated_files' => 100000,
  'opcache.revalidate_freq' => 0,
  'opcache.save_comments' => 1,
  'activity_expire_days' => 30,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'maintenance_window_start' => 1,
);

The output of your Apache/nginx/system log in /var/log/____:

No log files available

I made sure that the Apache 2.4 is running, Redis as well and the database is manually reachable as well.
Any ideas on how to fix this issue?

Does the php installation has all necessary modules to connect to mysql database?

Yes, the following modules are installed:

apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
ldap
libxml
mailparse
mbstring
memcached
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
random
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
ssh2
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib

I have the same problem since the last (automatic) update of the php-package (8.2.21). I figured out that php.ini and extensions.ini seems to be overwritten. I only had some memory settings etc adopted. And APCu extension hasn’t been loaded any more since not in extesions.ini anymore and running php commands on bash gives

OCP\HintException: [0]: Memcache OC\Memcache\APCu not available for local cache (Is the matching PHP module installed and enabled?)

After adding

extension = apco.so

this error was gone and php/mysql commands are possible to execute on bash (Switch to maintenance mode is also possible on command line!). However, Internal Server Error still exist when trying to access the web interface or access nextcloud on any client!? I have no idea where to look for logs or commands to test… (sorry I’m not a very experienced user)

You have redis running in your config.php file and this is what solved my internal server error. The latest synology PHP upgrade overwrites the modified php-fpm.ini that is required to use redis on a synology. Open the file /volume1/@appstore/PHP8.2/misc/php-fpm.ini (or whatever PHP version you use) and add the following lines at the very end:

[Redis]
extension = redis.so

restarted apache and my error was gone

1 Like

Here’s some details unique to a Synology implementation of Nextcloud that might be releavant to your error. Honestly I’m done with this and moving everything to Ubuntu. Every time there’s an update it’s like hunting for Easter eggs.

MEMCACHE error fix

Create the user-specific file /usr/local/etc/php82/cli/conf.d/user_settings.ini and add the content there as described below.
Provided that php 8.2 is in use, otherwise the same should also apply to other PHP versions ie.php81.

Ensure HTTP HTTP Permissions on the file below
-rw-r–r–
permission 644

The relevant entries in the new file you create called user_settings.ini should be:

extension = apcu.so
extension = redis.so

[apc]
apc.shm_size = 512M
apc.enable_cli = 1

Place this entry near the bottom (after mail password option) of config.php in the nextcloud directory

‘memcache.local’ => ‘\OC\Memcache\APCu’,

Transactional file locking - Redis

Redis improves file locking and can be used as a distributed cache. To use Redis, you need to install the “Redis” package on your DiskStation. You can find it in the community repository.

Unfortunately, it doesn’t work without a workaround under DSM 7.2 either. You now have the Redis server, but you also need the Redis client as a PHP module. Redis is delivered with the Synology PHP packages, but you cannot activate Redis in the WebStation. You have to do this via the command line.

The first change applies to Redis in the web server, without this change you will get an “Internal Server Error”. Open the file /volume1/@appstore/PHP8.2/misc/php-fpm.ini (or whatever PHP version you use) and add the following lines at the very end:

[Redis]
extension = redis.so

restart apache and all should be OK

1 Like

Hi matkinson,

thanks very much for that clear explanation AND solution.

Is the php-fpm.ini overwritten at the next automatic update of the php package? Do you know why this is suddenly necessary to add?

(… and you are totally right: this installation on Synology DSM is like hunting for Easter eggs :rofl: :sob:)

Hi DrPrat,

It appears that this time when updating the PHP packages it overwrote that critical file and didn’t append any new additions that you had made to the new file. What I’ve found with the synology is that if it’s not an option in the GUI and files have been manually modified via SSH, then always assume that any update will overwrite and cause you to have to re-enter any new values. I keep a running log of changes so that I don’t forget when the time comes to modify files. The Nextcloud config.php is a quick place to start as you can remark out any values you’ve added and test as usually that provides the quickest hint of issues without hunting for logs within the labyrinth of synology’s system.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.