Php-fpm seg faulting causing bad gateway - Low memory problem?

Hello, i’m totally new here and i’m facing a problem for almost 4 days now, which i can’t resolve myself anymore. This is my first time trying to install Nextcloud with no success so far, since the website is not reachable (bad gateway). PHP is showing segmentation faults.

Nextcloud: 21.0.2
OS: Debian stretch 9.13 (32-bit) with custom kernel
Apache or nginx: nginx 1.10.3
PHP-fpm: 8.0.7
redis-server: 3.2.6

Restrictions:

  • I only want to reach Nextcloud in my LAN network (IP: 192.168.178.115)
  • I’m running debian on a custom kernel for the WD Mycloud Mirror
  • System Memory is only 512MB (perhaps the main problem?) | CPU 1,2 GHz dual-core

Now the log files:

/var/log/nginx/nextcloud.error

2021/06/24 11:32:14 [error] 23006#23006: *1 open() "/var/www/nextcloud/favicon.ico" failed (2: No such file or directory), client: 192.168.178.73, server: wdmc, request: "GET /favicon.ico HTTP/1.1", host: "192.168.178.115", referrer: "http://192.168.178.115/index.php"

2021/06/24 11:32:14 [error] 23006#23006: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.178.73, server: wdmc, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.0-fpm.sock:", host: "192.168.178.115", referrer: "http://192.168.178.115/index.php"

/var/log/php8.0-fpm.log

[24-Jun-2021 11:32:14] WARNING: [pool www] child 18916 exited on signal 11 (SIGSEGV) after 972.430477 seconds from start
[24-Jun-2021 11:32:14] NOTICE: [pool www] child 23008 started

I have no idea to further debug the segmentation fault. Perhaps i’m facing a memory issue with my system? Can you suggest me how to still get it running, since it’s the only hardware I have here.

Should i save memory with:

  • downgrade Nextcloud?
  • don’t use redis-server
  • use apache2 instead of nginx
  • free up memory on the debian system somehow?

Or doesn’t it matter at all which versions i use? Nextcloud will be the only thing running on this hardware, nothing else.

Now the configs:

/etc/nginx/conf.d/nextcloud.conf

upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/run/php/php-fpm.sock;
}

server {
    listen 80;
    listen [::]:80;
    server_name wdmc;

    # Add headers to serve security related headers
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Robots-Tag none;
    add_header X-Download-Options noopen;
    add_header X-Permitted-Cross-Domain-Policies none;
    add_header Referrer-Policy no-referrer;

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains;" always;

    #I found this header is needed on Ubuntu, but not on Arch Linux. 
    add_header X-Frame-Options "SAMEORIGIN";

    # Path to the root of your installation
    root /var/www/nextcloud;

    access_log /var/log/nginx/nextcloud.access;
    error_log /var/log/nginx/nextcloud.error;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # The following 2 rules are only needed for the user_webfinger app.
    # Uncomment it if you're planning to use this app.
    #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
    # last;

    location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }
    location = /.well-known/caldav {
       return 301 $scheme://$host/remote.php/dav;
    }

    location ~ /.well-known/acme-challenge {
      allow all;
    }

    # set max upload size
    client_max_body_size 512M;
    fastcgi_buffers 64 4K;

    # Disable gzip to avoid the removal of the ETag header
    gzip off;

    # Uncomment if your server is build with the ngx_pagespeed module
    # This module is currently not supported.
    #pagespeed off;

    error_page 403 /core/templates/403.php;
    error_page 404 /core/templates/404.php;

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
       deny all;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
       deny all;
     }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
       include fastcgi_params;
       fastcgi_split_path_info ^(.+\.php)(/.*)$;
       try_files $fastcgi_script_name =404;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param PATH_INFO $fastcgi_path_info;
       #Avoid sending the security headers twice
       fastcgi_param modHeadersAvailable true;
       fastcgi_param front_controller_active true;
       fastcgi_pass unix:/run/php/php8.0-fpm.sock;
       fastcgi_intercept_errors on;
       fastcgi_request_buffering off;
    }
}

/etc/php/8.0/fpm/php.ini

output_buffering = Off
memory_limit = 384M

/var/www/nextcloud/config/config.php

'activity_expire_days' => 14,
'auth.bruteforce.protection.enabled' => true,
'blacklisted_files' =>
array (
0 => '.htaccess',
1 => 'Thumbs.db',
2 => 'thumbs.db',
),
'cron_log' => true,
'default_phone_region' => 'DE',
'enable_previews' => true,
'enabledPreviewProviders' =>
array (
0 => 'OC\Preview\PNG',
1 => 'OC\Preview\JPEG',
2 => 'OC\Preview\GIF',
3 => 'OC\Preview\BMP',
4 => 'OC\Preview\XBitmap',
5 => 'OC\Preview\Movie',
6 => 'OC\Preview\PDF',
7 => 'OC\Preview\MP3',
8 => 'OC\Preview\TXT',
9 => 'OC\Preview\MarkDown',
),
'filesystem_check_changes' => 0,
'filelocking.enabled' => 'true',
'htaccess.RewriteBase' => '/',
'integrity.check.disabled' => false,
'knowledgebaseenabled' => false,
'log_rotate_size' => 104857600,
'logfile' => '/var/www/nextcloud/nextcloud.log',
'loglevel' => 2,
'logtimezone' => 'Europe/Berlin',								 
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'preview_max_x' => 1024,
'preview_max_y' => 768,
'preview_max_scale_factor' => 1,
'redis' =>
array (
'host' => '/var/run/redis/redis-server.sock',
'port' => 0,
'timeout' => 0.0,
),
'quota_include_external_storage' => false,
'share_folder' => '/Shares',
'skeletondirectory' => '',
'trashbin_retention_obligation' => 'auto, 7',
'activity_expire_days' => 14,
'auth.bruteforce.protection.enabled' => true,
'blacklisted_files' =>
array (
0 => '.htaccess',
1 => 'Thumbs.db',
2 => 'thumbs.db',
),
'cron_log' => true,
'default_phone_region' => 'DE',
'enable_previews' => true,
'enabledPreviewProviders' =>
array (
0 => 'OC\Preview\PNG',
1 => 'OC\Preview\JPEG',
2 => 'OC\Preview\GIF',
3 => 'OC\Preview\BMP',
4 => 'OC\Preview\XBitmap',
5 => 'OC\Preview\Movie',
6 => 'OC\Preview\PDF',
7 => 'OC\Preview\MP3',
8 => 'OC\Preview\TXT',
9 => 'OC\Preview\MarkDown',
),
'filesystem_check_changes' => 0,
'filelocking.enabled' => 'true',
'htaccess.RewriteBase' => '/',
'integrity.check.disabled' => false,
'knowledgebaseenabled' => false,
'log_rotate_size' => 104857600,
'logfile' => '/daten/nextcloud.log',
'loglevel' => 2,
'logtimezone' => 'Europe/Berlin',								 
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'preview_max_x' => 1024,
'preview_max_y' => 768,
'preview_max_scale_factor' => 1,
'redis' =>
array (
'host' => '/var/run/redis/redis-server.sock',
'port' => 0,
'timeout' => 0.0,
),
'quota_include_external_storage' => false,
'share_folder' => '/Shares',
'skeletondirectory' => '',
'trashbin_retention_obligation' => 'auto, 7',
'trusted_domains' =>
  array (
    0 => '192.168.178.115',
  ),
);

yes. if you don’t reduce mem and cache sizes that won’t work well. tried this with version 18 or 19 as well. so downgrade nextcloud isn’t a solution.

tune everything. as you listed above.
i would remove redis first. and than try to tweak php.

which database your are using? sqlite?

add swap space? makes your system awfully slow but may prevent crashes.

It’s my first time to setup anything with nginx and php, so where can I find those options?

So i have no idea either how to safe memory on the debian system and what services are running at all. I will remove redis first now and report back.

I’m using MariaDB and i was hoping the impact wasn’t too big.

root@wdmc:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            494         163          75           6         254         313
Swap:           486          18         468

root@wdmc:~# grep Swap /proc/meminfo
SwapCached:          968 kB
SwapTotal:        498364 kB
SwapFree:         479388 kB

Is my current memory usage and I already have swapon.

you find some articles about tuning a lemp stack for low memory ← there.

there are tools like mysqltuner.pl or php-fpm memory calculators.

this is just a snapshot. you should run watch free -m and observe the memory usage over some time. (of course there are nicer tools to do this. this is just a starting point.)

#### I found the Solution #####
I had to enable SSL like in this post ([solved] Can't login via web after fresh install) for apache, which did somehow fixed being stuck on the login and finished the installation.

– Question was: –

I made some progress so far. What I did was:

  • Upgrading Debian 9 to Debian 10
  • Moving to apache2 2.4.38 instead of nginx
  • enable php-fpm for apache2 as suggest by apt
  • and probably most important, moving to SQL lite v3

I managed to view the page now and create an admin account, but i got redirected to a wrong page (only started with index.php and missing the wdmc part).

After going back to http://wdmc/, when i try to login with the correct credentials, the login button spins and redirects me again to the login page, so i can’t login…

Some more infos about the problem, seems like a permissions problem, but they should be fine, i overwrote them again for all folders:

{
  "reqId": "mviNr65Lqb6ReyVZHUvN",
  "level": 3,
  "time": "2021-06-25T16:01:34+00:00",
  "remoteAddr": "192.168.178.73",
  "user": "--",
  "app": "index",
  "method": "GET",
  "url": "/index.php/apps/accessibility/css/user-a82fd95db10ff25dfad39f07372ebe37",
  "message": {
    "Exception": "OCP\\Files\\NotPermittedException",
    "Message": "Could not create folder",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/lib/private/Files/AppData/AppData.php",
        "line": 157,
        "function": "newFolder",
        "class": "OC\\Files\\Node\\Folder",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Template/IconsCacher.php",
        "line": 90,
        "function": "newFolder",
        "class": "OC\\Files\\AppData\\AppData",
        "type": "->"
      },
      {
        "function": "__construct",
        "class": "OC\\Template\\IconsCacher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 101,
        "function": "newInstanceArgs",
        "class": "ReflectionClass",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 109,
        "function": "buildClass",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 126,
        "function": "resolve",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/ServerContainer.php",
        "line": 162,
        "function": "query",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/DependencyInjection/DIContainer.php",
        "line": 434,
        "function": "query",
        "class": "OC\\ServerContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 87,
        "function": "query",
        "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
        "type": "->"
      },
      {
        "function": "OC\\AppFramework\\Utility\\{closure}",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 101,
        "function": "array_map"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 109,
        "function": "buildClass",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php",
        "line": 126,
        "function": "resolve",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/DependencyInjection/DIContainer.php",
        "line": 459,
        "function": "query",
        "class": "OC\\AppFramework\\Utility\\SimpleContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/DependencyInjection/DIContainer.php",
        "line": 431,
        "function": "queryNoFallback",
        "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 144,
        "function": "query",
        "class": "OC\\AppFramework\\DependencyInjection\\DIContainer",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 302,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 993,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 37,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/var/www/nextcloud/lib/private/Files/Node/Folder.php",
    "Line": 176,
    "CustomMessage": "--"
  },
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
  "version": "21.0.3.0"
}
root@wdmc:/var/www/nextcloud# ls -l data/appdata_oc87ztvrzwu2/
total 20
drwxr-xr-x 2 www-data www-data 4096 Jun 25 17:58 appstore
drwxr-xr-x 4 www-data www-data 4096 Jun 25 18:01 css
drwxr-xr-x 3 www-data www-data 4096 Jun 25 18:30 js
drwxr-xr-x 2 www-data www-data 4096 Jun 25 18:00 preview
drwxr-xr-x 3 www-data www-data 4096 Jun 25 18:01 theming
root@wdmc:/var/www/nextcloud# ls -l data/
total 1040
drwxr-xr-x 3 www-data www-data    4096 Jun 25 17:58 admin
drwxr-xr-x 7 www-data www-data    4096 Jun 25 18:30 appdata_oc87ztvrzwu2
-rw-r--r-- 1 www-data www-data       0 Jun 25 17:58 index.html
-rw-r----- 1 www-data www-data   13755 Jun 25 18:40 nextcloud.log
-rw-r--r-- 1 www-data www-data 1040384 Jun 25 18:45 owncloud.db