Beberapa log yang relevan dengan error session di nextcloud

{"reqId":"fwtrhZVBHBffHb1KZISV","level":0,"time":"2020-03-24T19:06:53+07:00","remoteAddr":"127.0.0.1","user":"jaranguda","app":"core","method":"GET","url":"/ocs/v2.php/core/getapppassword","message":"could not get login credentials because session is unavailable","userAgent":"curl/7.61.1","version":"18.0.3.0"}
 
{"reqId":"SutKHiFhPoTvMNA5AwjN","level":0,"time":"2020-03-24T19:02:00+07:00","remoteAddr":"127.0.0.2","user":"--","app":"core","method":"GET","url":"/apps/files/","message":{"Exception":"OC\\AppFramework\\Middleware\\Security\\Exceptions\\NotLoggedInException","Message":"Current user is not logged in","Code":401,"Trace":[{"file":"/var/www/nextcloud/lib/private/AppFramework/Middleware/MiddlewareDispatcher.php","line":97,"function":"beforeController","class":"OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":98,"function":"beforeController","class":"OC\\AppFramework\\Middleware\\MiddlewareDispatcher","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/App.php","line":125,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Files\\Controller\\ViewController"},"index"]},{"file":"/var/www/nextcloud/lib/private/AppFramework/Routing/RouteActionHandler.php","line":47,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Files\\Controller\\ViewController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"files.view.index"}]},{"function":"__invoke","class":"OC\\AppFramework\\Routing\\RouteActionHandler","type":"->","args":[{"_route":"files.view.index"}]},{"file":"/var/www/nextcloud/lib/private/Route/Router.php","line":299,"function":"call_user_func","args":[{"__class__":"OC\\AppFramework\\Routing\\RouteActionHandler"},{"_route":"files.view.index"}]},{"file":"/var/www/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/apps/files/"]},{"file":"/var/www/nextcloud/index.php","line":38,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/nextcloud/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php","Line":142,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36","version":"18.0.3.0"}
 
127.0.0.2 - - [24/Mar/2020:11:57:57 +0000] "GET / HTTP/2.0" 302 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"

Karena error tersebut Nextcloud menjadi login loop, tidak bisa masuk login, setelah memasukkan username/password akan kembali ke halaman login lagi.

Ketika login di Nextcloud statusnya 303
nextcloud login 303

Akar Masalah

Bila dilihat dari masalah tersebut error yang terjadi karena session tidak bisa disimpan/dipanggil. Karena Nextcloud berbasis PHP maka pada dasarnya menggunakan session dari PHP kecuali anda menggunakan redis atau memcache.

Yang harus ditelusuri adalah session PHP, cek nilai ‘session.save_path’ di php.ini atau www.conf. Di CentOS bisa dilihat di /etc/php-fpm.d/www.conf

$ grep session /etc/php-fpm.d/www.conf
;       (error_log, sessions.save_path, ...).
; at http://php.net/session.save-path
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session

bawaannya session PHP di Centos di set sebagai user apache, cek dengan ls -lah /var/lib/php/session

total 8.0K
drwxrwx--- 2 root apache 4.0K Nov 14 04:09 .
drwxr-xr-x 6 root root   4.0K Mar 24 12:49 ..

bila anda menjalankan php-fpm sebagai user lain, harus di set permissionnya sebagai user tersebut. Contoh saya menjalankan nginx dan php-fpm sebagai user www-data, maka disini saya rubah permissionnya menjadi milik user www-data dan group www-data

chown www-data:www-data -R /var/lib/php/

restart PHP FPM

systemctl restart php-fpm

coba login ke Nextcloud.

Bila anda lebih memilih login dengan cli (curl), gunakan format

curl -u user:password -H 'OCS-APIRequest: true' https://cloud.nextcloud.com/ocs/v2.php/cloud/user

contoh

curl -u jaranguda:dWdCd3NVnqoM7Cq39z4N -H 'OCS-APIRequest: true' https://cloud.jaranguda.com/ocs/v2.php/cloud/user

keterangan :
username : jaranguda
password : dWdCd3NVnqoM7Cq39z4N
domain nextcloud : cloud.jaranguda.com

output dari perintah diatas

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>ok</status>
  <statuscode>200</statuscode>
  <message>OK</message>
 </meta>
 <data>
  <storageLocation>/var/www/nextcloud/data/jaranguda</storageLocation>
...
...
...

sukses login.

Leave a comment

Your email address will not be published. Required fields are marked *