linux

如何在LNMP中部署WordPress网站

小樊
48
2025-03-06 00:53:10
栏目: 云计算

在Linux系统下,LNMP代表的是Nginx、MySQL、PHP这种网站服务器架构。以下是在LNMP中部署WordPress网站的步骤:

准备工作

  1. 安装Nginx
sudo apt update
sudo apt install nginx
sudo yum install epel-release
sudo yum install nginx
  1. 安装MySQL/MariaDB
sudo apt install mysql-server
sudo yum install mariadb-server mariadb
  1. 安装PHP
sudo apt install php libapache2-mod-php php-mysql php-cli
sudo yum install php php-mysqlnd php-fpm php-cli

部署WordPress

  1. 下载并解压WordPress
  1. 配置Nginx
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;

    root /usr/share/nginx/html; # 或者 /var/www/html
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据你的PHP版本调整
    }

    location ~ /\.ht {
        deny all;
    }
}
sudo systemctl restart nginx
  1. 配置MySQL
sudo mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
  1. 配置WordPress
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpressuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
  1. 完成部署

以上步骤是在LNMP环境中部署WordPress的基本流程。在实际操作中,可能还需要进行一些额外的配置,例如设置SSL证书以实现HTTPS访问、配置邮件发送功能、优化数据库性能等。此外,确保所有软件和依赖都是最新版本,以获得更好的性能和安全性。

0
看了该问题的人还看了