Project

General

Profile

Setting up a session save path in php » History » Version 1

Gareth Eaton, 09/20/2023 11:54 AM

1 1 Gareth Eaton
h1. Setting up a session save path in php
2
3
I recently encountered an issue with Nextcloud where I kept experiencing unwanted logouts, leading to frustrating login loops. After some research and trial-and-error, I managed to find a solution that worked for me.
4
5
6
After a few clicks in the Nextclouds Web interface, especially in the Files page, I get the message:
7
8
*"Problem loading the page, reloading in 5 seconds"*
9
After 5 seconds I am logged out and have to login again. Having a look into the log-file there you can find the following entry:
10
11
*"app":"no app in context","message":"Current user is not logged in"*
12
13
14
Solution:
15
The solution involves configuring the php.ini file, which controls how PHP handles various settings on the server. Specifically, I focused on the session.save_path setting, which determines where PHP stores temporary session data for user logins.
16
17
Create a Temporary Directory:
18
First, I created a new directory named "tmp" within my Nextcloud installation directory (/var/www/html/nextcloud). This directory is where PHP will store temporary session data.
19
20
21
Create the "tmp" Directory:
22
23
You can use the mkdir command to create the "tmp" directory in the /var directory. Open your terminal and run:
24
25
26
<pre>
27
sudo mkdir /var/tmp
28
</pre>
29
30
This will create the "tmp" directory within /var.
31
32
Set Permissions:
33
34
Set the correct permissions for the "tmp" directory using chmod 750:
35
36
37
<pre>
38
sudo chmod 750 /var/tmp
39
</pre>
40
41
This ensures that the directory is readable, writable, and executable by the owner (root) and the group.
42
43
Configure php.ini:
44
45
Open the php.ini file for editing:
46
47
48
<pre>
49
sudo nano /etc/php/<version>/apache2/php.ini
50
</pre>
51
52
Replace <version> with the PHP version you're using. For example:
53
54
<pre>
55
sudo nano /etc/php/8.1/apache2/php.ini
56
</pre>
57
58
Find the session.save_path directive and update it to use the new "/var/tmp" directory:
59
60
61
<pre>
62
session.save_path = "/var/tmp"
63
</pre>
64
65
Save your changes and exit the text editor.
66
67
Restart Apache Web Server:
68
69
Finally, restart the Apache web server to apply the changes to the PHP configuration:
70
71
72
<pre>
73
sudo service apache2 restart
74
</pre>
75
76
77
Why This Works:
78
The unwanted logouts and login loops were likely caused by issues with session management. By creating a custom temporary directory and configuring PHP's session.save_path to use it, I ensured that session data was stored reliably. This prevents Nextcloud from losing track of my authentication status, thus stopping the annoying logouts and loops.