CentOS 7 LNMP 环境安装 WordPress

网络安全侦探 2024-07-12 ⋅ 22 阅读

WordPress

简介

WordPress 是一个广泛使用的开源内容管理系统 (CMS),用于创建网站、博客和应用程序。在 LNMP 环境下安装 WordPress 可以快速搭建一个稳定且强大的网站。

本文将提供一个详细的教程,以指导您在 CentOS 7 上安装 LNMP 环境并部署 WordPress。

步骤一:安装 LNMP

1. 安装 Nginx

# 更新软件包
sudo yum update

# 安装 Nginx
sudo yum install nginx

2. 安装 MariaDB

# 安装 MariaDB
sudo yum install mariadb-server

# 启动 MariaDB
sudo systemctl start mariadb

# 设置 MariaDB 开机自启动
sudo systemctl enable mariadb

3. 安装 PHP

# 安装 PHP 和相关模块
sudo yum install php php-fpm php-mysql

# 启动 PHP-FPM
sudo systemctl start php-fpm

# 设置 PHP-FPM 开机自启动
sudo systemctl enable php-fpm

4. 配置 Nginx

# 编辑 Nginx 配置文件
sudo vi /etc/nginx/conf.d/default.conf

将以下内容粘贴到配置文件中:

server {
    listen       80;
    server_name  your_domain.com; # 替换为您的域名或 IP 地址

    root   /var/www/html;
    index  index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

保存并退出编辑器。

5. 重启 Nginx

sudo systemctl restart nginx

现在,您已成功完成 LNMP 环境的安装。

步骤二:安装 WordPress

1. 下载 WordPress

# 进入网站根目录
cd /var/www/html

# 下载最新版 WordPress
sudo wget https://wordpress.org/latest.tar.gz

# 解压缩压缩包
sudo tar -zxvf latest.tar.gz

# 重命名 WordPress 目录
sudo mv wordpress your_domain

2. 配置数据库

# 登录 MariaDB
sudo mysql -u root -p

# 在 MariaDB 中创建一个新的数据库
CREATE DATABASE your_database_name;

# 创建一个新的数据库用户
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';

# 授权数据库用户访问数据库
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';

# 刷新权限
FLUSH PRIVILEGES;

# 退出 MariaDB
EXIT;

3. 配置 WordPress

# 复制默认配置文件
sudo cp /var/www/html/your_domain/wp-config-sample.php /var/www/html/your_domain/wp-config.php

# 编辑 WordPress 配置文件
sudo vi /var/www/html/your_domain/wp-config.php

将以下内容替换到配置文件中:

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');

保存并退出编辑器。

4. 设置文件权限

# 修改所有者为 Nginx 用户
sudo chown -R nginx:nginx /var/www/html/your_domain

# 修改 WordPress 文件和目录权限
sudo chmod -R 775 /var/www/html/your_domain
sudo find /var/www/html/your_domain/ -type d -exec chmod 755 {} \;

5. 完成安装过程

在浏览器中访问您的域名或 IP 地址即可开始 WordPress 安装过程。按照屏幕上的指导完成安装。

结论

通过按照本教程的步骤,在 CentOS 7 上成功安装了 LNMP 环境并部署了 WordPress。现在,您可以开始使用 WordPress 构建自己的网站或博客了!


全部评论: 0

    我有话说: