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

ArchLinux本地部署WordPress遇403禁止访问异常求助

我之前在Arch Linux上搭WordPress的时候,完完全全碰到过和你一样的403问题——安装时得手动敲install.php的完整路径,登录后台点个菜单还跳403,折腾了好一阵才搞定。给你列几个最关键的排查和修复步骤,按顺序来应该能解决:

1. 先把文件权限掰正(最常见的坑)

Arch上的Apache是以http用户和组运行的,WordPress目录的权限不对会直接导致403:

  • 先确认Apache的运行用户:ps aux | grep httpd,输出里应该能看到http用户
  • 给WordPress目录设置正确的所有者:
    sudo chown -R http:http /srv/http/wordpress
    
  • 统一目录和文件的权限(避免过松或过严):
    sudo find /srv/http/wordpress -type d -exec chmod 755 {} \;
    sudo find /srv/http/wordpress -type f -exec chmod 644 {} \;
    

2. 启用Apache的mod_rewrite并配置目录规则

WordPress的伪静态跳转依赖这个模块,没启用的话就没法自动跳转到install.php,后台访问也会出问题:

  • 编辑Apache主配置文件/etc/httpd/conf/httpd.conf,找到下面这行,把前面的#删掉:
    #LoadModule rewrite_module modules/mod_rewrite.so
    
  • 接着在配置文件里(或者/etc/httpd/conf/extra/httpd-vhosts.conf)添加WordPress目录的规则,允许.htaccess生效:
    <Directory "/srv/http/wordpress">
        AllowOverride All
        Require all granted
    </Directory>
    
  • 重启Apache生效:sudo systemctl restart httpd

3. 检查/生成WordPress的.htaccess文件

安装完成后WP会自动生成这个文件,但如果权限不足可能生成失败,导致跳转失效:

  • 如果/srv/http/wordpress下没有.htaccess,手动创建一个,内容如下:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
    </IfModule>
    # END WordPress
    
  • 给这个文件设置正确的所有者:sudo chown http:http /srv/http/wordpress/.htaccess

4. 确认Apache根目录的访问规则

有时候根目录的配置会限制子目录访问,检查httpd.conf里的DocumentRoot相关配置:

DocumentRoot "/srv/http"
<Directory "/srv/http">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

确保Require all granted是开启的,否则/srv/http下的所有子目录都会被禁止访问。

做完这些之后,重启Apache(sudo systemctl restart httpd),清一下浏览器缓存,再访问localhost/wordpress试试——不管是安装跳转还是后台访问,应该都不会再跳403了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:54:08