温馨提示×

如何在Ubuntu LNMP中部署WordPress

小樊
48
2025-07-23 12:55:57
栏目: 智能运维

在Ubuntu上使用LNMP(Linux, Nginx, MySQL/MariaDB, PHP)部署WordPress的步骤如下:

1. 更新系统

首先,确保你的Ubuntu系统是最新的。

sudo apt update sudo apt upgrade -y 

2. 安装Nginx

安装Nginx web服务器。

sudo apt install nginx -y 

启动并启用Nginx服务。

sudo systemctl start nginx sudo systemctl enable nginx 

3. 安装MySQL/MariaDB

安装MySQL或MariaDB数据库服务器。

sudo apt install mysql-server -y # 安装MySQL # 或者 sudo apt install mariadb-server -y # 安装MariaDB 

启动并启用数据库服务。

sudo systemctl start mysql sudo systemctl enable mysql # 或者 sudo systemctl start mariadb sudo systemctl enable mariadb 

运行安全脚本以提高数据库安全性。

sudo mysql_secure_installation 

4. 安装PHP

安装PHP及其常用扩展。

sudo apt install php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-snmp php-soap -y 

启动并启用PHP-FPM服务。

sudo systemctl start php7.4-fpm # 根据你的PHP版本调整命令 sudo systemctl enable php7.4-fpm 

5. 配置Nginx

编辑Nginx配置文件以支持PHP。

sudo nano /etc/nginx/sites-available/default 

将以下内容粘贴到文件中(根据需要调整域名和路径):

server { listen 80; server_name yourdomain.com www.yourdomain.com; root /var/www/html/wordpress; 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:/run/php/php7.4-fpm.sock; # 根据你的PHP版本调整命令 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } } 

保存并退出编辑器,然后测试Nginx配置。

sudo nginx -t 

重新加载Nginx以应用更改。

sudo systemctl reload nginx 

6. 下载并安装WordPress

创建WordPress目录并下载WordPress。

sudo mkdir /var/www/html/wordpress cd /var/www/html/wordpress sudo wget https://wordpress.org/latest.tar.gz sudo tar -xzvf latest.tar.gz sudo rm latest.tar.gz 

设置正确的权限。

sudo chown -R www-data:www-data /var/www/html/wordpress 

7. 配置WordPress

通过浏览器访问你的域名,按照WordPress安装向导完成安装。

8. 完成

现在,你应该能够通过浏览器访问你的WordPress网站了。

额外提示

  • 确保你的域名解析正确指向你的服务器IP。
  • 考虑使用SSL证书来加密你的网站流量,可以使用Let’s Encrypt免费获取。
  • 定期备份你的网站数据以防万一。

通过以上步骤,你应该能够在Ubuntu上成功部署一个WordPress网站。

0