“Containerized PHP应用程序会话目录为空”

huangapple go评论94阅读模式
英文:

Containerized PHP application sessions directory is empty

问题

我们正在将一个PHP网站从旧主机迁移到容器中。旧代码直接在虚拟机上运行,现在我们建立了一个容器来支持PHP网站。新旧PHP网站都在Apache HTTPD上运行,PHP版本为5.4.16。

然而,这个网站有一个特性,它将用户会话保存在/var/lib/php/session下,但在我们的新容器版本中无法正常工作。即使有活动会话,这个目录似乎总是空的。我们已经检查了以下内容:

  • 旧站点和新站点之间的session配置似乎相同(以下是配置信息)
  • 我们已验证apache用户是/var/lib/php/session目录的所有者
  • 在PHP错误日志中,似乎没有任何指示为什么会话没有保存的信息

我对PHP不太熟悉,不知道如何进一步调试,只是想看看是否可以得到一些帮助。

  • 有没有可能忘记安装任何允许会话持久化的模块?
  • 为什么没有任何指示会话未保存的日志?我是否需要启用更多日志记录来观察发生了什么?
  • 会话是否未保存,还是超时并被删除?是否有某个设置可以导致这种情况?

我们的配置:

  1. 会话支持:已启用
  2. 已注册的保存处理程序:文件 用户
  3. 已注册的序列化处理程序:php php_binary
  4. session.auto_start:已关闭
  5. session.cache_expire180
  6. session.cache_limiternocache
  7. session.cookie_domain:没有值
  8. session.cookie_httponly:已关闭
  9. session.cookie_lifetime0
  10. session.cookie_path:/
  11. session.cookie_secure:已关闭
  12. session.entropy_file:/dev/urandom
  13. session.entropy_length32
  14. session.gc_divisor1000
  15. session.gc_maxlifetime1440
  16. session.gc_probability1
  17. session.hash_bits_per_character5
  18. session.hash_function0
  19. session.namePHPSESSID
  20. session.referer_check:没有值
  21. session.save_handler:文件
  22. session.save_path:/var/lib/php/session
  23. session.serialize_handlerphp
  24. session.upload_progress.cleanup:已启用
  25. session.upload_progress.enabled:已启用
  26. session.upload_progress.freq1%
  27. session.upload_progress.min_freq1
  28. session.upload_progress.namePHP_SESSION_UPLOAD_PROGRESS
  29. session.upload_progress.prefixupload_progress_
  30. session.use_cookies:已启用
  31. session.use_only_cookies:已启用
  32. session.use_trans_sid0
英文:

We are migrating a PHP website from an old host to a container. The old code runs on VM directly, now we built a container that facilitate the PHP website. Both old and new PHP website run on top of apache httpd with php version 5.4.16.

However, there's a feature of this website that saves user session under /var/lib/php/session that does not work in our new, containerized version. The directory seems to always be empty even if there are active sessions. We have checked the following:

  • The session configuration seems identical between the old and new site (pasting the config below)
  • We verified apache user is the owner of /var/lib/php/session directory
  • In php error logs, there doesn't seem to be anything indicating why the sessions are not saved

I am not familiar with PHP and don't know how I could debug this further, just checking if I can get some help on this.

  • Any chance we forgot to install any module that would allow session persistent?
  • Why would there not be any logs indicating the sessions not being saved? Do I need to somehow enable more logging to observe what is happening?
  • Was the session not saved or did it timeout and get wiped? Is there such setting somewhere that can cause this?

Our configuration

  1. Session Support: enabled
  2. Registered save handlers: files user
  3. Registered serializer handlers: php php_binary
  4. session.auto_start: Off
  5. session.cache_expire: 180
  6. session.cache_limiter: nocache
  7. session.cookie_domainno value
  8. session.cookie_httponly: Off
  9. session.cookie_lifetime: 0
  10. session.cookie_path: /
  11. session.cookie_secure: Off
  12. session.entropy_file: /dev/urandom
  13. session.entropy_length: 32
  14. session.gc_divisor: 1000
  15. session.gc_maxlifetime: 1440
  16. session.gc_probability: 1
  17. session.hash_bits_per_character: 5
  18. session.hash_function: 0
  19. session.name: PHPSESSID
  20. session.referer_check: no value
  21. session.save_handler: files
  22. session.save_path: /var/lib/php/session
  23. session.serialize_handler: php
  24. session.upload_progress.cleanup: On
  25. session.upload_progress.enabled: On
  26. session.upload_progress.freq: 1%
  27. session.upload_progress.min_freq: 1
  28. session.upload_progress.name: PHP_SESSION_UPLOAD_PROGRESS
  29. session.upload_progress.prefix: upload_progress_
  30. session.use_cookies: On
  31. session.use_only_cookies: On
  32. session.use_trans_sid: 0

答案1

得分: 0

我们的脚本在将容器以root用户运行后修复了/var/lib/php/session的权限问题。

英文:

Turns out our script messed around the permission of /var/lib/php/session after having the container run as root it straighten things out

huangapple
  • 本文由 发表于 2023年3月21日 03:31:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794539-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定