500 Internal Server Error, The server encountered an internal

Hi
I’m getting an error when trying to access newly installed NextCloud.

Page displays the following:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Config.php:

<?php
$CONFIG = array (
  'instanceid' => 'XX',
  'passwordsalt' => 'XX',
  'secret' => 'XX',
  'trusted_domains' => 
  array (
    0 => 'XXX.net',
  ),
  'datadirectory' => '/var/www/ncdata',
  'dbtype' => 'mysql',
  'version' => '19.0.3.1',
  'overwrite.cli.url' => 'https://XXX.net/',
  'htaccess.RewriteBase' => 'var/www/html',
  'installed' => true,
  'maintenance' => false,
  'app_install_overwrite' => 
  array (
    0 => 'recommendation_assistant',
    1 => 'caniupdate',
    2 => 'admin_notifications',
    3 => 'end_to_end_encryption',
  ),
  'filelocking.enabled' => true,
  'memcache.locking' => '\\OC\\Memcache\\APCu',
  'redis' => 
  array (
    'host' => 'localhost',
    'port' => 6379,
    'timeout' => 0.0,
    'password' => '',
  ),
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'XX',
  'dbpassword' => 'XX',
  'updater.secret' => 'XXX',
  'theme' => '',
  'loglevel' => 2,
  'mysql.utf8mb4' => true,
  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
    0 => 'admin',
  ),
);

.htaccess

> <IfModule mod_headers.c>
>   <IfModule mod_setenvif.c>
>     <IfModule mod_fcgid.c>
>        SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
>        RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
>     </IfModule>
>     <IfModule mod_proxy_fcgi.c>
>        SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
>     </IfModule>
>   </IfModule>
> 
>   <IfModule mod_env.c>
>     # Add security and privacy related headers
> 
>     # Avoid doubled headers by unsetting headers in "onsuccess" table,
>     # then add headers to "always" table: https://github.com/nextcloud/server/pull/19002
>     Header onsuccess unset Referrer-Policy
>     Header always set Referrer-Policy "no-referrer"
> 
>     Header onsuccess unset X-Content-Type-Options
>     Header always set X-Content-Type-Options "nosniff"
> 
>     Header onsuccess unset X-Download-Options
>     Header always set X-Download-Options "noopen"
> 
>     Header onsuccess unset X-Frame-Options
>     Header always set X-Frame-Options "SAMEORIGIN"
> 
>     Header onsuccess unset X-Permitted-Cross-Domain-Policies
>     Header always set X-Permitted-Cross-Domain-Policies "none"
> 
>     Header onsuccess unset X-Robots-Tag
>     Header always set X-Robots-Tag "none"
> 
>     Header onsuccess unset X-XSS-Protection
>     Header always set X-XSS-Protection "1; mode=block"
> 
>     SetEnv modHeadersAvailable true
>   </IfModule>
> 
>   # Add cache control for static resources
>   <FilesMatch "\.(css|js|svg|gif)$">
>     Header set Cache-Control "max-age=15778463"
>   </FilesMatch>
> 
>   # Let browsers cache WOFF files for a week
>   <FilesMatch "\.woff2?$">
>     Header set Cache-Control "max-age=604800"
>   </FilesMatch>
> </IfModule>
> <IfModule mod_php7.c>
>   php_value mbstring.func_overload 0
>   php_value default_charset 'UTF-8'
>   php_value output_buffering 0
>   <IfModule mod_env.c>
>     SetEnv htaccessWorking true
>   </IfModule>
> </IfModule>
> <IfModule mod_rewrite.c>
>   RewriteEngine on
>   RewriteCond %{HTTP_USER_AGENT} DavClnt
>   RewriteRule ^$ /remote.php/webdav/ [L,R=302]
>   RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
>   RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
>   RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
>   RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
>   RewriteRule ^\.well-known/nodeinfo /public.php?service=nodeinfo [QSA,L]
>   RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
>   RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
>   RewriteRule ^remote/(.*) remote.php [QSA,L]
>   RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
>   RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
>   RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
> </IfModule>
> <IfModule mod_mime.c>
>   AddType image/svg+xml svg svgz
>   AddEncoding gzip svgz
> </IfModule>
> <IfModule mod_dir.c>
>   DirectoryIndex index.php index.html
> </IfModule>
> AddDefaultCharset utf-8
> Options -Indexes
> <IfModule pagespeed_module>
>   ModPagespeed Off
> </IfModule>

error.log

[Fri Nov 13 20:58:11.406448 2020] [mpm_prefork:notice] [pid 290546] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Nov 13 20:58:11.406737 2020] [core:notice] [pid 290546] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 13 20:58:21.579410 2020] [mpm_prefork:notice] [pid 290546] AH00169: caught SIGTERM, shutting down
[Fri Nov 13 20:58:21.785240 2020] [mpm_prefork:notice] [pid 315074] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Nov 13 20:58:21.785572 2020] [core:notice] [pid 315074] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 13 21:01:45.866731 2020] [mpm_prefork:notice] [pid 315074] AH00169: caught SIGTERM, shutting down
[Fri Nov 13 21:01:46.055713 2020] [mpm_prefork:notice] [pid 340590] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Nov 13 21:01:46.056555 2020] [core:notice] [pid 340590] AH00094: Command line: '/usr/sbin/apache2'
[Fri Nov 13 21:15:56.055317 2020] [mpm_prefork:notice] [pid 340590] AH00169: caught SIGTERM, shutting down
[Fri Nov 13 21:15:56.260286 2020] [mpm_prefork:notice] [pid 444367] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Nov 13 21:15:56.260602 2020] [core:notice] [pid 444367] AH00094: Command line: '/usr/sbin/apache2'

I already tried to:

  • Purge and reinstall php and all modules
  • Changed permissions of all files to 640, directories to 750

If you want to find the root cause of the problem you should check he content of the Nextcloud log file and search for any related error message :wink:

Nextcloud log:

{"reqId":"xanhPrTTGZsHKzQaBIYv","level":3,"time":"2020-11-13T19:32:05+00:00","remoteAddr":"37.120.211.213","user":"--","app":"PHP","method":"GET","url":"/index.php/csrftoken","message":"touch(): Utime failed: Permission denied at /var/www/html/lib/private/Config.php#242","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","version":""}
{"reqId":"xanhPrTTGZsHKzQaBIYv","level":3,"time":"2020-11-13T19:32:05+00:00","remoteAddr":"37.120.211.213","user":"--","app":"PHP","method":"GET","url":"/index.php/csrftoken","message":"fopen(/var/www/html/config/config.php): failed to open stream: Permission denied at /var/www/html/lib/private/Config.php#243","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","version":""}
{"reqId":"xanhPrTTGZsHKzQaBIYv","level":3,"time":"2020-11-13T19:32:05+00:00","remoteAddr":"37.120.211.213","user":"--","app":"PHP","method":"GET","url":"/index.php/csrftoken","message":"chmod(): Operation not permitted at /var/www/html/lib/private/Config.php#246","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","version":""}
{"reqId":"xanhPrTTGZsHKzQaBIYv","level":3,"time":"2020-11-13T19:32:05+00:00","remoteAddr":"37.120.211.213","user":"--","app":"index","method":"GET","url":"/index.php/csrftoken","message":{"Exception":"OC\\HintException","Message":"Can't write into config directory!","Code":0,"Trace":[{"file":"/var/www/html/lib/private/Config.php","line":134,"function":"writeData","class":"OC\\Config","type":"->"},{"file":"/var/www/html/lib/private/SystemConfig.php","line":111,"function":"setValue","class":"OC\\Config","type":"->"},{"file":"/var/www/html/lib/private/legacy/OC_Util.php","line":1146,"function":"setValue","class":"OC\\SystemConfig","type":"->"},{"file":"/var/www/html/lib/base.php","line":420,"function":"getInstanceId","class":"OC_Util","type":"::"},{"file":"/var/www/html/lib/base.php","line":650,"function":"initSession","class":"OC","type":"::"},{"file":"/var/www/html/lib/base.php","line":1095,"function":"init","class":"OC","type":"::"},{"file":"/var/www/html/index.php","line":35,"args":["/var/www/html/lib/base.php"],"function":"require_once"}],"File":"/var/www/html/lib/private/Config.php","Line":250,"Hint":"This can usually be fixed by giving the webserver write access to the config directory.","CustomMessage":"--"},"userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","version":""}
{"reqId":"xanhPrTTGZsHKzQaBIYv","level":3,"time":"2020-11-13T19:32:05+00:00","remoteAddr":"37.120.211.213","user":"--","app":"index","method":"GET","url":"/index.php/csrftoken","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: could not find driver","Code":0,"Trace":[{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":889,"function":"connect","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/lib/private/DB/Connection.php","line":194,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":200,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->"},{"file":"/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":216,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->"},{"file":"/var/www/html/lib/private/AppConfig.php","line":331,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->"},{"file":"/var/www/html/lib/private/AppConfig.php","line":109,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/lib/private/AppConfig.php","line":287,"function":"getApps","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/lib/private/App/AppManager.php","line":136,"function":"getValues","class":"OC\\AppConfig","type":"->"},{"file":"/var/www/html/lib/private/App/AppManager.php","line":225,"function":"getInstalledAppsValues","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/html/lib/private/legacy/OC_Template.php","line":286,"function":"isEnabledForUser","class":"OC\\App\\AppManager","type":"->"},{"file":"/var/www/html/index.php","line":45,"function":"printErrorPage","class":"OC_Template","type":"::"}],"File":"/var/www/html/lib/private/DB/Connection.php","Line":67,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36","version":""}

Meines Erachtens ist es Nextcloud nicht möglich die Konfigurationsdatei zu öffen, sodass das Programm dann in einem Fehler läuft. Stelle sicher, dass der Dateipfad und die Datei durch den Webserver-User geöffnet bzw. gelesen werden kann.

Hello everyone !!
Yes, I think the same thing, can you try ls -l /your/server/path/ and giv us the result ?
Thank you.

1 Like
drwxr-x--- 41 root     www-data  4096 Oct 22 12:18 3rdparty
drwxr-x--- 52 www-data www-data  4096 Nov  6 20:19 apps
drwxr-x---  2 www-data www-data  4096 Nov 13 20:09 assets
-rw-r-----  1 root     www-data 16522 Nov  6 20:36 AUTHORS
drwxr-x---  2 www-data www-data  4096 Nov 13 21:16 config
-rw-r-----  1 root     www-data  3967 Nov  6 20:36 console.php
-rw-r-----  1 root     www-data 34520 Nov  6 20:36 COPYING
drwxr-x--- 23 root     www-data  4096 Nov  6 20:36 core
-rw-r-----  1 root     www-data  5140 Nov  6 20:36 cron.php
drwxr-x---  2 www-data www-data  4096 Nov 13 20:26 data
-rw-r-----  1 root     www-data   156 Nov  6 20:36 index.html
-rw-r-----  1 root     www-data  2960 Nov  6 20:36 index.php
-rw-r-----  1 root     www-data    20 Oct 12 15:59 info.php
drwxr-x---  6 root     www-data  4096 Oct 22 11:52 lib
drwxr-x---  2 root     www-data  4096 Nov 13 20:13 ncdata
-rwxr-x--x  1 root     www-data   283 Nov  6 20:36 occ
drwxr-x---  2 root     www-data  4096 Oct 22 11:55 ocm-provider
drwxr-x---  2 root     www-data  4096 Oct 22 11:55 ocs
drwxr-x---  2 root     www-data  4096 Oct 22 11:55 ocs-provider
-rw-r-----  1 root     www-data  3102 Nov  6 20:36 public.php
-rw-r-----  1 root     www-data  5332 Nov  6 20:36 remote.php
drwxr-x---  4 root     www-data  4096 Oct 22 11:55 resources
-rw-r-----  1 root     www-data    26 Nov  6 20:36 robots.txt
-rw-r-----  1 root     www-data  1033 Nov 13 20:09 script.sh
-rw-r-----  1 root     www-data  2379 Nov  6 20:36 status.php
drwxr-x---  3 www-data www-data  4096 Oct 22 11:55 themes
drwxr-x---  2 www-data www-data  4096 Oct 22 11:55 updater
-rw-r-----  1 root     www-data   362 Nov  6 20:36 version.php

Ok, If you try : chown -R www-data:www-data /your/server/path/

ls -l

drwxr-x--- 41 www-data www-data  4096 Oct 22 12:18 3rdparty
drwxr-x--- 52 www-data www-data  4096 Nov  6 20:19 apps
drwxr-x---  2 www-data www-data  4096 Nov 13 20:09 assets
-rw-r-----  1 www-data www-data 16522 Nov  6 20:36 AUTHORS
drwxr-x---  2 www-data www-data  4096 Nov 13 21:16 config
-rw-r-----  1 www-data www-data  3967 Nov  6 20:36 console.php
-rw-r-----  1 www-data www-data 34520 Nov  6 20:36 COPYING
drwxr-x--- 23 www-data www-data  4096 Nov  6 20:36 core
-rw-r-----  1 www-data www-data  5140 Nov  6 20:36 cron.php
drwxr-x---  2 www-data www-data  4096 Nov 13 20:26 data
-rw-r-----  1 www-data www-data   156 Nov  6 20:36 index.html
-rw-r-----  1 www-data www-data  2960 Nov  6 20:36 index.php
-rw-r-----  1 www-data www-data    20 Oct 12 15:59 info.php
drwxr-x---  6 www-data www-data  4096 Oct 22 11:52 lib
drwxr-x---  2 www-data www-data  4096 Nov 13 20:13 ncdata
-rwxr-x--x  1 www-data www-data   283 Nov  6 20:36 occ
drwxr-x---  2 www-data www-data  4096 Oct 22 11:55 ocm-provider
drwxr-x---  2 www-data www-data  4096 Oct 22 11:55 ocs
drwxr-x---  2 www-data www-data  4096 Oct 22 11:55 ocs-provider
-rw-r-----  1 www-data www-data  3102 Nov  6 20:36 public.php
-rw-r-----  1 www-data www-data  5332 Nov  6 20:36 remote.php
drwxr-x---  4 www-data www-data  4096 Oct 22 11:55 resources
-rw-r-----  1 www-data www-data    26 Nov  6 20:36 robots.txt
-rw-r-----  1 www-data www-data  1033 Nov 13 20:09 script.sh
-rw-r-----  1 www-data www-data  2379 Nov  6 20:36 status.php
drwxr-x---  3 www-data www-data  4096 Oct 22 11:55 themes
drwxr-x---  2 www-data www-data  4096 Oct 22 11:55 updater
-rw-r-----  1 www-data www-data   362 Nov  6 20:36 version.php

Page still displays:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

Have you tried to restart the server with :sudo systemctl restart apache2 in case you use apache and can we have the log again to see if it’s the same error.
Thank you

Still displays the same error page.

So, if I understand correctly, you mean that you never received any page other than an internal server error?

Did you follow a tutorial? and which one if yes.

That’s correct. I followed instructions from the main Nextcloud guide. I installed it through snap, then copied files etc step by step.

Perhaps I should just erase everything and try again.

I’ve been having good experience with nextcloud previously on CentOS. It’s the first time I’m using Ubuntu server.

Yes, maybe you should.

Try it and tell us.

I did everything again and I got database access not permitted error. I removed everything and used this manual instead and got no errors. Everything is working fine now.

I’m guessing now that my previous problem might have been related to database permissions as well? Although I don’t see any database problems in logs.

Either way, thanks a lot for everyones help.

1 Like

Hum… Yeah, I don’t know.

Cool if you don’t have a problem now. It’s a snap installation ?

I’d try to just delete the generated htaccess in the Nextcloud installation. Those lines do not seem common for me.
NC generates its own htaccess file. If you want to add extra features, you have to do that in the httpd config. But be sure to avoid doubling since this disables security for some rules. You can an add IF … in your hosting system to avoid this.
You can also try to put the NC installation in maintenance by editing the config file. Sometimes this will give more insight in problems.

I just struggled over a instead of a ' in the config.php:

‘allow_local_remote_servers’ => true, --> leads to this error
'allow_local_remote_servers' => true, --> works as expected
1 Like