Wordpress建站问题记录

从一月到七月因为工作的情况没有进行太深入的开发,想着整理一下把做一个独立站把博客多个渠道发布一下,遇到几个问题在这里记录一下.

先写一下我的配置
系统: centos7
php: 7.4
wordpress: 6.6.1
mysql:8.0.6

1. HTTP 500 Internal

这个问题出现在我将wordpress的文件夹全部删除然后重新解压,并且将文件夹及文件的权限全部放开的情况下出现,之后查看httpd的错误报告发现是权限错误,

sudo tail -f  /var/log/httpd/ssl_error_log

排查之后觉得应该是selinux的问题,查看selinux的状态

sestatus

觉得是selinux的策略问题导致,所以将enforece修改为0之后所有的页面都可以访问

sudo setenforce 0

所以如果排查了上面的动作之后可以和我一样首先查看log然后selinux,下面是修改方式(来源于chatgpt):

1.
sudo ausearch -m avc -ts today
2. 我在普通文件夹中保存权限问题报错,后来全部放到tmp文件下,这种文件最好也是在一个同一个地方保存
sudo grep httpd /var/log/audit/audit.log | audit2allow -M mywordpresspolicy
3.
sudo semodule -i mywordpresspolicy.pp
4.
sudo chcon -R -t httpd_sys_content_t /var/www/html/wordpress
5.
sudo chcon -R -t httpd_sys_rw_content_t /var/www/html/wordpress/wp-content/uploads
6.
sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/wordpress(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress/wp-content/uploads(/.*)?"

2. 站点位置与实际位置不一致

在这里插入图片描述
就像上面你的两个希望在最后的网站中不需要额外的增加wordpress,直接修改过后查看文章会出现 404的情况并且查看日志可以看到index.php定向没有将wordpress自动加上,所以下面重新将官网的内容梳理了一遍,修改过后文章链接与访问均正常.
修改 index.php 文件
你需要将 WordPress 的 index.php 文件复制到站点根目录(即 /var/www/html),并更新其内容,使其指向实际的 WordPress 安装目录:

2.1 复制 index.php 文件:

cp /var/www/html/wordpress/index.php /var/www/html/

编辑复制后的 index.php 文件:

2.2 找到代码,6.6.1此处DIR为FILE

require( dirname( __DIR__ ) . '/wp-blog-header.php' );

修改为:

require( dirname( __DIR__ ) . '/wordpress/wp-blog-header.php' );

保存文件并退出编辑器。

2.3 确保 .htaccess 文件配置正确
在根目录 /var/www/html 和 WordPress 目录 /var/www/html/wordpress 中,检查 .htaccess 文件的配置。

编辑 .htaccess 文件(如果没有,创建一个)
查看隐藏文件的命令为

ls -a

查看文件:

sudo nano /var/www/html/.htaccess

2.4 确保 .htaccess 文件内容如下(如果你启用了自定义永久链接):

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wordpress/wp-blog-header.php';

然后保存并关闭文件。

2.5 编辑 /var/www/html/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 . /index.php [L]
</IfModule>
# END WordPress

2.6. 更新永久链接,修改完成后,重置永久链接结构:
登录到 WordPress 管理后台。
转到设置 > 永久链接
选择其他永久链接结构并保存,然后再改回原来的结构并保存,以刷新 URL 路径。
5. 检查服务器配置
确保 Apache 或 Nginx 配置没有阻止对新站点地址的访问,并且重写模块已经启用。路径/etc/httpd/conf/httpd.conf

Include conf.modules.d/*.conf
LoadModule php7_module modules/libphp7.so

LoadModule rewrite_module modules/mod_rewrite.so

3. wordpress更改的位置

3.1 ssl
存储位置

/etc/httpd/ssl/bimath.com_apache/

ssl.conf /etc/httpd/conf.d/ssl.conf

DocumentRoot "/var/www/html"
ServerName bimath.com:443

3.2 httpd.conf /etc/httpd/conf/httpd.conf

Include conf.modules.d/*.conf
LoadModule php7_module modules/libphp7.so
LoadModule rewrite_module modules/mod_rewrite.so
# serverName
ServerName www.bimath.com:443
# wordpress
<Directory /var/www/html/wordpress>
    AllowOverride All
    Require all granted
</Directory>

3.3 wp-config.php

/** WordPress 目录的绝对路径。 */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
 define("FS_CHMOD_FILE", 0777);

/** 设置 WordPress 变量和包含的文件。 */
require_once ABSPATH . 'wp-settings.php';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值