通过LNMP环境搭建网站-博客网站wordpress(ubt)

1. 说明

  • LNMP经典网站环境, Linux系统,Nginx网站服务,MySQL数据库(Mariadb),PHP(运行环境)
  • WordPress PHP代码.

2. 建议的搭建顺序

  • MySQL数据库(mariadb)
  • PHP环境 php 7.x
  • Nginx 直接安装即可

3.部署

3.1 部署数据库

apt update && sudo apt upgrade -y
#1.安装
apt install mysql-server -y
#2.初始化(安装后进行一次即可)
mysql_secure_installation
#第一次 回车
#第二次 n
#之后全Y即可


#3.进入数据库
mysql  -uroot -p



#4.创建库和所有者
create database wordpress;
create user 'wordpress'@'localhost' IDENTIFIED BY 'password';
grant all  privileges on  wordpress.* to 'wordpress'@'localhost';
flush privileges;
exit;

#5.检查是否创建成功

MariaDB [(none)]> show databases; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.000 sec)


MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------
| mariadb.sys | localhost |
| mysql       | localhost |
| root        | localhost |
| wordpress   | localhost |
+-------------+-----------+
4 rows in set (0.002 sec)



#6.测试
mysql  -uwordpress   -p
输入密码
show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| wordpress          |            
+--------------------+
2 rows in set (0.000 sec)
登陆后表中有wordpress才对
CTRL +D 退出

3.2部署php

#1.apt安装php软件包(php版本可能不同 把8.3改成当下版本即可)
apt install -y php8.3-bcmath php8.3-bz2 php8.3-cgi php8.3-cli php8.3-common php8.3-curl php8.3-fpm php8.3-gd php8.3-intl \
php8.3-mbstring php8.3-mysql php8.3-opcache php8.3-readline php8.3-soap \
php8.3-xml php8.3-zip php8.3-apcu php8.3-redis php8.3-snmp


#2.修改配置文件
egrep '^(user|group|listen)' /etc/php/8.3/fpm/pool.d/www.conf
user = www-data
group = www-data
listen = 127.0.0.1:9000      #主要修改这里
listen.owner = www-data
listen.group = www-data

#3.检查 
php-fpm8.3 -t
NOTICE: configuration file /etc/php/8.3/fpm/php-fpm.conf test is successful
#重启
systemctl enable  --now php8.1-fpm 
systemctl  restart php8.1-fpm
#检查端口和进程
ps -ef |grep php 
ss -lntup |grep php 

3.3安装部署nginx

#检查是否安装apache 
dpkg -l |grep -i apache 

#关闭 apache2服务
 #如果有则关闭 systemctl  stop  apache httpd  
 
#删除apache
apt autoremove  apache2 apache2-bin
#1.安装
apt update 
apt install -y nginx 
#2.检查
 dpkg -l|grep nginx 

#3.修改配置
/etc/nginx/nginx.conf  #主配置文件
/etc/nginx/conf.d 
/etc/nginx/conf.d/default.conf  #子配置文件

#4. 修改nginx用户为www-data
grep ^user /etc/nginx/nginx.conf
user  www-data;

##删除旧的的文件
rm -f /etc/nginx/sites-enabled/default

#5.添加新文件
vim /etc/nginx/conf.d/default.conf

server {
    listen       80 default_server;
    server_name  localhost;
    root /app/code/blog/;
    location / {
        index  index.php;
    }
    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;
    }
}

#6.检查
nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#重启
 systemctl enable  --now nginx 
 systemctl restart nginx

3.4部署代码

#1.创建代码目录
mkdir -p /app/code/blog/
#2.下载代码(wordpress官网下载最新版)
wget https://cn.wordpress.org/latest-zh_CN.zip
#3.解压代码
unzip latest-zh_CN.zip 
mv wordpress/* /app/code/blog/
#4.修改所有者 
chown  -R www-data.www-data  /app/code/blog/

4.浏览器访问(自己DNS云解析处配置的域名)

注意安全组开放80端口

进入后按照提示填写信息即可

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注