Cent OS 安装 WordPress

本文最后更新于:2021年11月18日 晚上

正文

WordPress 需要运行在 PHP 环境中,请确保你已经在系统中安装好了 PHP 并且已启动了 php-fpm 服务。另外还需要 MySQL 作为数据库使用,所以也需要安装并启用 MySQL。

下载 WordPress

首先我们进入 WordPress 官网:https://cn.wordpress.org/ ,点击右上角 获取WordPress 进入下载页面,然后点击 下载WordPress x.x.x 就可以下载到中文版的 WordPress。

上传 WordPress 到服务器

下载完成后,我们解压下载好的压缩包,将里面的 wordpress 文件夹上传到服务器,至于上传的目录自己决定,我上传到 /data/www/ 目录下了。

设置 WordPress 权限

  1. wordpress 目录的所有者设为 web 访问用户,皮皮使用的 web服务器是 Nginx,用户默认为 nginx:
1
chown -R nginx:nginx /data/www/wordpress
  1. 设置 wordpress 目录权限:
1
chmod -R 775 /data/www/wordpress
  1. 设置 wp-content 目录权限:
1
chmod -R 777 /data/www/wordpress/wp-content/
  1. wordpress 根目录下的配置文件 wp-config.php 中添加以下字段:
1
2
3
define("FS_METHOD", "direct");  
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);

注意:在 wordpress 目录下增加了文件后记得设置权限,否则会出现无法访问到文件的情况!

配置 Web 服务器

这里只给大家展示如何配置 Nginx

/etc/nginx/conf.d 目录下新建 wordpress.conf 文件,向文件添加以下内容:

server { 
    listen  80; # 监听 80 端口
    server_name   localhost ; # 指定 IP 地址或域名
    # 匹配访问路径为以 / 开始的 URI。
    location / {
        root /data/www/wordpress;  
        index index.php index.html index.htm;  
    }
    
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ .php$ {  
        root /data/www/wordpress;  
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.php;  
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
        include        fastcgi_params;  
    }
}

添加完成后刷新 nginx 配置:

1
nginx -s reload

创建 WordPress 的数据库

  1. 登录 MySQL
1
mysql -uroot -p

回车后输入密码,再回车。

  1. 创建数据库
1
CREATE DATABASE wordpress;
  1. 退出 MySQL
1
EXIT;

登录设置 WordPress

在浏览器的地址栏中输入我们的服务器ip或者域名就可以开始设置我们的 WordPress 了。


Cent OS 安装 WordPress
https://chenpipi.cn/post/centos-install-wordpress/
作者
陈皮皮
发布于
2019年2月11日
更新于
2021年11月18日
许可协议