centos lnmp如何部署WordPress
导读:在CentOS上使用LNMP(Linux, Nginx, MySQL/MariaDB, PHP)部署WordPress的步骤如下: 1. 安装Nginx 首先,确保你的CentOS系统已经更新到最新状态: sudo yum update -...
在CentOS上使用LNMP(Linux, Nginx, MySQL/MariaDB, PHP)部署WordPress的步骤如下:
1. 安装Nginx
首先,确保你的CentOS系统已经更新到最新状态:
sudo yum update -y
然后安装Nginx:
sudo yum install nginx -y
启动Nginx并设置开机自启动:
sudo systemctl start nginx
sudo systemctl enable nginx
2. 安装MySQL/MariaDB
安装MariaDB(CentOS 8默认使用MariaDB):
sudo yum install mariadb-server mariadb -y
启动MariaDB并设置开机自启动:
sudo systemctl start mariadb
sudo systemctl enable mariadb
运行安全脚本以提高安全性:
sudo mysql_secure_installation
3. 安装PHP
安装PHP及其常用扩展:
sudo yum install php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-pear php-bcmath -y
启动PHP-FPM并设置开机自启动:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
4. 配置Nginx
编辑Nginx配置文件以支持PHP:
sudo vi /etc/nginx/conf.d/default.conf
将以下内容添加到server块中:
server {
listen 80;
server_name your_domain.com www.your_domain.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-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存并退出编辑器,然后重新加载Nginx配置:
sudo systemctl reload nginx
5. 下载并安装WordPress
创建WordPress目录并下载WordPress:
sudo mkdir -p /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
6. 配置WordPress
将WordPress文件的所有权更改为Nginx用户(通常是nginx):
sudo chown -R nginx:nginx /var/www/html/wordpress
编辑WordPress的wp-config.php文件以配置数据库连接:
cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo vi wp-config.php
在wp-config.php文件中添加以下内容:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
7. 完成WordPress安装
打开浏览器并访问你的域名(例如http://your_domain.com),按照WordPress安装向导完成安装。
8. 配置防火墙
确保防火墙允许HTTP和HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
9. 配置SSL(可选)
你可以使用Let’s Encrypt免费获取SSL证书:
sudo yum install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain.com -d www.your_domain.com
按照提示完成SSL证书的安装和配置。
完成以上步骤后,你的WordPress网站应该已经成功部署在CentOS上使用LNMP环境。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: centos lnmp如何部署WordPress
本文地址: https://pptw.com/jishu/761318.html
