TP6 cannot save session under Linux

When I launched the project today, I found that the login function failed to verify the verification code no matter what. The preliminary judgment should be that there is a problem with session storage. After simple debugging, it was found that the problem was indeed session failure.

There are several possibilities for session failure:

  1. The session storage path (directory) does not exist, so naturally the temporary session file cannot be generated.
  2. Is there any permission under the session storage path? If not, it will be impossible to store session data.
  3. There is no middleware for opening sessions in the tp6 framework.

solution:

       1. For the first case, the temporary files of the session in the Tp6 framework are stored in the runtime-session folder. For the stable operation of the program in the future, just give 777 permissions to the runtime and the following directories. This is the pitfall I encountered this time. After turning on the permissions, it ran perfectly.

        2. For the second case, create the phpinfo.php file in the project directory, write phpinfo() in the file, run this file, and view the page to find the session storage path. (The configuration path seen by directly checking the configuration file may not be correct). Secondly, enter Linux to check whether the session storage path exists. If it does not exist, create a storage directory and assign permissions. If there is a
session storage path, check whether it has permissions. If not, assign permissions.

        3. In the third case, there are very detailed tutorials in official documents and on the Internet. In short, open the middleware.php file in the app directory and open the comments of the following code.

\think\middleware\SessionInit::class

Guess you like

Origin blog.csdn.net/baidu_36095053/article/details/121019503