Setting up a session save path in php » History » Version 2
Gareth Eaton, 09/20/2023 12:23 PM
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 | 2 | Gareth Eaton | | *Note* I've discovered that you may need to create the 'tmp' directory within the Nextcloud folder at '/var/www/html/nextcloud'. |
15 | This can cause issues during updates as it may flag the directory. In such cases, you'll have to remove it and reinstall it later. |
||
16 | To avoid this problem, you can install Nextcloud in the '/var' directory. While this usually works, there have been instances where it didn't work for me. | |
||
17 | |||
18 | |||
19 | |||
20 | 1 | Gareth Eaton | Solution: |
21 | 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. |
||
22 | |||
23 | 2 | Gareth Eaton | | Create a Temporary Directory: |
24 | If you're setting up Nextcloud in the '/var/' directory, you can likely skip this step. However, if you're installing it in the Nextcloud directory, you'll need to create a new folder. To do this, I initially established a fresh directory called 'tmp' within my Nextcloud installation path, which in my case was '/var/www/html/nextcloud.' This 'tmp' directory serves as the location where PHP stores temporary session data. | |
||
25 | |||
26 | |||
27 | 1 | Gareth Eaton | |
28 | |||
29 | Create the "tmp" Directory: |
||
30 | |||
31 | You can use the mkdir command to create the "tmp" directory in the /var directory. Open your terminal and run: |
||
32 | |||
33 | |||
34 | <pre> |
||
35 | sudo mkdir /var/tmp |
||
36 | </pre> |
||
37 | |||
38 | This will create the "tmp" directory within /var. |
||
39 | |||
40 | Set Permissions: |
||
41 | |||
42 | Set the correct permissions for the "tmp" directory using chmod 750: |
||
43 | |||
44 | |||
45 | <pre> |
||
46 | sudo chmod 750 /var/tmp |
||
47 | </pre> |
||
48 | |||
49 | This ensures that the directory is readable, writable, and executable by the owner (root) and the group. |
||
50 | |||
51 | Configure php.ini: |
||
52 | |||
53 | Open the php.ini file for editing: |
||
54 | |||
55 | |||
56 | <pre> |
||
57 | sudo nano /etc/php/<version>/apache2/php.ini |
||
58 | </pre> |
||
59 | |||
60 | Replace <version> with the PHP version you're using. For example: |
||
61 | |||
62 | <pre> |
||
63 | sudo nano /etc/php/8.1/apache2/php.ini |
||
64 | </pre> |
||
65 | |||
66 | Find the session.save_path directive and update it to use the new "/var/tmp" directory: |
||
67 | |||
68 | |||
69 | <pre> |
||
70 | session.save_path = "/var/tmp" |
||
71 | </pre> |
||
72 | |||
73 | Save your changes and exit the text editor. |
||
74 | |||
75 | Restart Apache Web Server: |
||
76 | |||
77 | Finally, restart the Apache web server to apply the changes to the PHP configuration: |
||
78 | |||
79 | |||
80 | <pre> |
||
81 | sudo service apache2 restart |
||
82 | </pre> |
||
83 | |||
84 | |||
85 | Why This Works: |
||
86 | 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. |