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

Debian 9 Stretch下Nginx部署phpMyAdmin遇404错误求助

解决Debian Stretch下Nginx访问phpMyAdmin的404问题

我来帮你排查下这个问题——在Debian Stretch环境里,Nginx访问phpMyAdmin出现404但日志无报错,大概率是配置里漏了关键的路径映射规则,下面是几个常见的解决方向:

  • 添加phpMyAdmin的Nginx位置配置
    Debian Stretch中phpMyAdmin默认安装路径是/usr/share/phpmyadmin/,你需要在default配置文件中添加对应的location块,让Nginx能正确找到这个目录并处理PHP文件:

    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
    
        # 处理PHP文件
        location ~ ^/phpmyadmin/(.+\.php)$ {
            root /usr/share/;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; # Debian Stretch默认是php7.0-fpm
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        # 处理静态资源
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }
    

    注意:如果你的PHP版本不是7.0,要对应修改fastcgi_pass的socket路径(比如php7.1的话是/var/run/php/php7.1-fpm.sock)。

  • 验证配置并重启服务
    修改配置后,先检查Nginx语法是否正确:

    sudo nginx -t
    

    若提示test is successful,再重启Nginx服务:

    sudo systemctl restart nginx
    

    同时确认PHP-FPM服务处于运行状态:

    sudo systemctl status php7.0-fpm
    

    如果未运行,执行sudo systemctl start php7.0-fpm启动它。

  • 检查文件权限
    确保phpMyAdmin目录的权限让Nginx的运行用户(www-data)可以访问:

    sudo chown -R www-data:www-data /usr/share/phpmyadmin/
    sudo find /usr/share/phpmyadmin/ -type d -exec chmod 755 {} \;
    sudo find /usr/share/phpmyadmin/ -type f -exec chmod 644 {} \;
    
  • 确认PHP处理规则生效
    如果你全局的Nginx配置里没有处理.php文件的规则,那上面phpMyAdmin专属的location块里必须包含完整的fastcgi参数配置,这一点在第一个步骤里已经覆盖到了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:04:14