Suddenly Internal Server Error

Hallo,

my problem is that my installation suddenly stopped working.(Internal Server Error) I had version 18 installed on an Ubuntu Server 18.04. After I did an NC 19 update the problem still persists. I have no idea where to start my troubleshooting. Many thanks for your help!

My configuration: Ubuntu LTS 18.04, NC 19.0.0.2(after an update from 18), PHP 7.2, MariaDB 10.1.44, Apache

My Config:
$CONFIG = array (
‘instanceid’ => ‘xxxx’,
‘passwordsalt’ => ‘xxxxx’,
‘secret’ => ‘xxxx’,
‘trusted_domains’ =>
array (
0 => ‘xxxx.at’,
1 => ‘office’,
),
‘memcache.local’ => ‘\OC\Memcache\Redis’,
‘redis’ =>
array (
‘host’ => ‘localhost’,
‘port’ => 6379,
),
‘onlyoffice’ =>
array (
‘verify_peer_off’ => true,
),
‘integrity.check.disabled’ => true,
‘datadirectory’ => ‘/var/www/html/nextcloud/data’,
‘overwrite.cli.url’ => ‘http://office/nextcloud’,
‘dbtype’ => ‘mysql’,
‘version’ => ‘19.0.2.2’,
‘dbname’ => ‘nextcloud’,
‘dbhost’ => ‘localhost’,
‘dbport’ => ‘’,
‘dbtableprefix’ => ‘oc_’,
‘mysql.utf8mb4’ => true,
‘dbuser’ => ‘nextcloud’,
‘dbpassword’ => ‘xxxxx!’,
‘installed’ => true,
‘mail_smtpmode’ => ‘smtp’,
‘mail_from_address’ => ‘office’,
‘mail_domain’ => ‘xxxx.at’,
‘mail_smtphost’ => ‘xxxxxx’,
‘mail_smtpport’ => ‘25’,
‘maintenance’ => false,
‘theme’ => ‘’,
‘loglevel’ => 0,
‘ldapIgnoreNamingRules’ => false,
‘ldapProviderFactory’ => ‘\OCA\User_LDAP\LDAPProviderFactory’,
‘app.mail.verify-tls-peer’ => false,
‘app_install_overwrite’ =>
array (
0 => ‘files_downloadactivity’,
),
‘mail_sendmailmode’ => ‘smtp’,
);

Nextcloud.log:
“app”:“core”,“method”:“GET”,“url”:"/nextcloud/index.php/login",“message”:{“Exception”:“Exception”,“Message”:“template file not found: template:layout.guest”,“Code”:0,“Trace”:[{“file”:"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php",“line”:154,“function”:“find”,“class”:“OC\Template\TemplateFileLocator”,“type”:"->",“args”:[“layout.guest”]},{“file”:"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php",“line”:88,“function”:“findTemplate”,“class”:“OC_Template”,“type”:"->",“args”:["",“core”,“layout.guest”]},{“file”:"/var/www/html/nextcloud/lib/private/TemplateLayout.php",“line”:127,“function”:"__construct",“class”:“OC_Template”,“type”:"->",“args”:[“core”,“layout.guest”,"",false]},{“file”:"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php",“line”:185,“function”:"__construct",“class”:“OC\TemplateLayout”,“type”:"->",“args”:[“error”,""]},{“file”:"/var/www/html/nextcloud/lib/private/Template/Base.php",“line”:132,“function”:“fetchPage”,“class”:“OC_Template”,“type”:"->",“args”:[]},{“file”:"/var/www/html/nextcloud/lib/private/legacy/OC_Template.php",“line”:334,“function”:“printPage”,“class”:“OC\Template\Base”,“type”:"->",“args”:[]},{“file”:"/var/www/html/nextcloud/index.php",“line”:63,“function”:“printExceptionErrorPage”,“class”:“OC_Template”,“type”:"::",“args”:[{“class”:“Exception”},500]}],“File”:"/var/www/html/nextcloud/lib/private/Template/TemplateFileLocator.php",“Line”:57,“CustomMessage”:"–"},“userAgent”:“Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0”,“version”:“19.0.2.2”}

Hello,

Exact same problem for me.
I finally found what’s causing it.
The problem comes from lib/private/legacy/OC_Template.php, function ‘findTemplate’ (line 146).

For core templates, as the var ‘app’ is not empty, it’s the function ‘getAppTemplateDirs’ that is called and not the function ‘getCoreTemplateDirs’.

It’s inside the function ‘getAppTemplateDirs’ (file lib/private/Template/Base.php) that they manage to handle the case of a ‘core’ app value by testing the existence of the folder (“if (file_exists($app_dir.’/templates/’)) {”)

And here comes the problem.
if (file_exists($app_dir.’/templates/’)) {"

What happens if $app_dir is empty (which is the case when app=‘core’)?
The $app_dir.’/templates/’ becomes ‘/templates/’

So php test the existence of a folder ‘templates’ at the root of your server.
And indeed, earlier this month, I created such folder for another application.

Because of this, all the paths get from ‘findTemplate’ are wrongs for core templates.

2 solutions I found:

  • In the ‘findTemplate’ function, change the line:
    if ($app !== ‘’) {
    by this:
    if ($app !== ‘’ && $app !== ‘core’) {

  • do not use ‘templates’ as a name for any folder at the root of your server.

Hope this help

1 Like

Thanks for this solution. It happen to me on version 20.0.4.0. I just edit lib/private/legacy/OC_Template.php file with your solution, and then it works…

but because of this, now i have the integrity check issue… lol

[lib/private/legacy/OC_Template.php] => Array
(
[expected] => 130bdc95918c2ef6e7e38d5d12ff29761fab60f72e6634e7d50c6d0a9e446486585bcc9f213434458bfafa2afc86c1ba79d4524217d156fac943cf67d0889d7e
[current] => 52356375a4964d0a3132eebe3c4587b84bc281a64a755579e0f2054e858e9e47946dd6216bed900e13d3910800b26264eb2e908dae31df9c5efcbcd01d605cc9
)
maybe can ignore it until they release new update

update: version 20.0.8:
the problem happen everytime i update to new version. then today i re-read the solution above and he mention that root folder cannot have a folder name templates. i recheck my root folder, then somehow i got a folder name templates. i maybe did some mistake couple month back when extracting a file, i extract it on root folder… after i remove this ‘templates’ folder, it working properly now…

Welcome to the Nextcloud community!