Search
Close this search box.

Debian12安装WordPress(LNMP环境)

一、准备工作

部分vps不允许ssh连接,需要手动开启:

				
					vi /etc/ssh/sshd_config
				
			

找到下面这行

				
					#PermitRootLogin prohibit-password
				
			

取消注释,修改为yes

				
					PermitRootLogin yes
				
			

保存后,重启ssh服务,即可使用ssh工具连接

				
					systemctl restart ssh
				
			

更新系统:

				
					apt update && apt upgrade -y
				
			

安装必要的软件包:

				
					apt install -y curl wget unzip zip
				
			

二、安装Nginx

官方安装文档:

https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/

直接使用apt install nginx安装的版本一般不是最新版,这里使用nginx官方库安装。

安装所需软件包

				
					apt install -y curl gnupg2 ca-certificates lsb-release debian-archive-keyring
				
			

导入nginx 官方 签名密钥

				
					curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
				
			

设置stable库

				
					echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/debian `lsb_release -cs` nginx" \
    | tee /etc/apt/sources.list.d/nginx.list
				
			

设置官方库优先

				
					echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | tee /etc/apt/preferences.d/99nginx
				
			

安装nginx并启用开机自启

				
					apt update && apt install -y nginx
				
			
				
					systemctl enable nginx
				
			

配置Nginx

修改Nginx用户为www-data

				
					vi /etc/nginx/nginx.conf
				
			

修改第一行的user

				
					user  nginx;
				
			

修改为

				
					user  www-data;
				
			

:wq保存退出

添加WordPress站点配置文件。

创建ssl和templates文件夹,用于存放ssl证书和一些多站点通用配置

				
					mkdir /etc/nginx/ssl
mkdir /etc/nginx/templates
				
			

申请ssl证书

修改默认配置,默认返回404

				
					cd /etc/nginx/conf.d
mv default.conf default.conf.bak
				
			
				
					cat >> /etc/nginx/conf.d/00-default.conf << 'EOF' 
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name _;

    include /etc/nginx/templates/ssl.conf;

    return 404;
}
EOF
				
			

添加ssl、php、brotli通用配置模板

				
					cat >> /etc/nginx/templates/ssl.conf << 'EOF' 
ssl_certificate /etc/nginx/ssl/fullchain.cer; 
ssl_certificate_key /etc/nginx/ssl/private.key;

ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
EOF
				
			
				
					cat >> /etc/nginx/templates/php.conf << 'EOF' 
location / {
    try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 256k;
    fastcgi_busy_buffers_size 512k;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    try_files $uri =404;
}
EOF
				
			
				
					cat >> /etc/nginx/templates/brotli.conf << 'EOF' 
brotli on;
brotli_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
EOF
				
			

添加第一个网站配置,并启动nginx

				
					cat >> /etc/nginx/conf.d/01-domain.com.conf << 'EOF' 
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.domain.com;

    include /etc/nginx/templates/ssl.conf;

    return 301 https://domain.com$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name domain.com;
    root /www/domain.com;
    index index.php index.html;

    include /etc/nginx/templates/ssl.conf;
    include /etc/nginx/templates/php.conf;
    include /etc/nginx/templates/brotli.conf;
}
EOF
				
			
				
					systemctl start nginx
				
			

三、安装MySQL

官方apt库下载页:

https://dev.mysql.com/downloads/repo/apt/

官方安装文档:

https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

重启Nginx

添加MySQL APT库

				
					wget https://dev.mysql.com/get/mysql-apt-config_0.8.33-1_all.deb
				
			
				
					dpkg -i mysql-apt-config_0.8.33-1_all.deb
				
			

保持默认,选第三个OK

更新并安装MySQL

				
					apt update
				
			
				
					apt install -y mysql-server
				
			

设置root用户密码

创建数据库

				
					mysql -uroot -p
				
			

输入密码进入数据库

				
					create database wordpress;
				
			

退出数据库

				
					exit;
				
			

四、安装PHP

安装php8.2

				
					apt install -y php8.2
				
			
				
					apt install -y php8.2-{fpm,mysqli,curl,dom,apcu,bcmath,gd,igbinary,imagick,intl,mbstring,memcached,memcache,opcache,redis,simplexml,ssh2,xml,xmlreader,zip,soap,tidy,dev}
				
			

五、安装WordPress

建立web目录,下载最新版WordPress

				
					mkdir /www && cd /www
				
			
				
					wget https://wordpress.org/latest.tar.gz
				
			

解压并修改所有者

				
					tar -xzvf latest.tar.gz
				
			
				
					chown -R www-data:www-data wordpress
				
			
				
					mv wordpress domain.com
				
			

配置都正确的话,访问https://domain.com/ 可以进入WordPress安装页。

 

下一步填写数据库信息

下一步填写站点信息和管理员信息,安装完成

Share the Post:

Related Posts