You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已完成PHP、Apache、MySQL部署,phpMyAdmin会话Cookie设置失败如何解决?

Hey there, let's fix that Failed to set session cookie. Maybe you are using HTTP instead of HTTPS error you're hitting with phpMyAdmin. I’ve dealt with this exact issue a handful of times, so here are the go-to solutions that usually resolve it:

1. Tweak phpMyAdmin's Configuration File

First, locate your config.inc.php file—this is typically in /usr/share/phpmyadmin or the phpMyAdmin folder within your web root. Open it up and adjust these settings:

  • Set a valid session save path: Make sure phpMyAdmin can write to a dedicated session directory. Add or update this line:
    $cfg['SessionSavePath'] = '/var/lib/php/sessions';
    
    Then ensure the directory has the right permissions for your web server user (usually www-data):
    chown www-data:www-data /var/lib/php/sessions
    chmod 700 /var/lib/php/sessions
    
  • Disable forced HTTPS (if you're not using it yet): If you're still on HTTP, turn off the SSL enforcement:
    $cfg['ForceSSL'] = false;
    
  • Adjust cookie settings: Make sure these cookie-related configs match your setup:
    $cfg['CookieSameSite'] = 'Lax';
    $cfg['CookieSecure'] = false; // Set to true once you switch to HTTPS
    $cfg['CookieHttpOnly'] = true;
    
2. Update PHP's Session Configuration

Open your php.ini file (the path varies by PHP version and server—common locations are /etc/php/7.x/apache2/php.ini or /etc/php.ini). Check these parameters:

  • session.save_path: Confirm it points to the same writable directory you set in phpMyAdmin
  • session.cookie_secure: Set to Off if you're using HTTP; switch to On once you enable HTTPS
  • session.cookie_samesite: Set to Lax (this is the safest default for most setups)
    After making changes, restart Apache to apply them:
sudo systemctl restart apache2

If your Apache virtual host config has rules that force the Secure attribute on all cookies, that'll break session cookies over HTTP. Look for lines like this in your Apache config file:

Header edit Set-Cookie ^(.*)$ $1;Secure

If you find it, either comment it out, or wrap it in an HTTPS-only condition so it only applies when you're using secure connections:

<If "%{HTTPS} == 'on'">
    Header edit Set-Cookie ^(.*)$ $1;Secure
</If>

Restart Apache after updating the config.

4. Clear Browser Cache & Cookies

Sometimes stale browser data can cause cookie issues. Try clearing the cookies for your phpMyAdmin domain, or open phpMyAdmin in incognito/private browsing mode to see if that fixes it.

Bonus: Check SELinux (for RHEL/CentOS systems)

If you're running a system with SELinux enabled (like CentOS), it might be blocking Apache from writing to the session directory. Test this by temporarily disabling SELinux:

sudo setenforce 0

If the error goes away, you'll need to add a SELinux rule to allow Apache access to the session directory permanently:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/lib/php/sessions(/.*)?"
sudo restorecon -Rv /var/lib/php/sessions

内容的提问来源于stack exchange,提问作者Lancer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:26:24