部署LNMP及Discuz论坛

部署LNMP及Discuz论坛

LNMP: Linux+nginx+mysql+php

环境说明

# 永久关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
[root@localhost ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted


[root@localhost ~]# reboot


# 配置阿里云源和epel源
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@localhost ~]# yum clean all
0 files removed
[root@localhost ~]# yum makecache
[root@localhost ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@localhost ~]# sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@localhost ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@localhost ~]# yum makecache

nginx的安装与配置
# 参加系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

# 安装依赖包
[root@localhost ~]# yum -y install gcc gcc-c++ openssl-devel openssl gd-devel --allowerasing
[root@localhost ~]# yum -y install  pcre-devel

# 创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx/

[root@localhost nginx]# ll
drwxr-xr-x  2 nginx  nginx       6 Oct 18 02:24 nginx

# 下载nginx软件包
[root@localhost ~]# cd /usr/src
[root@localhost src]# wget http://nginx.org/download/nginx-1.22.1.tar.gz

# 解压软件包
[root@localhost src]# tar -xf nginx-1.22.1.tar.gz 
[root@localhost src]# ll
total 1052
drwxr-xr-x. 2 root root       6 Jun 22  2021 debug
drwxr-xr-x. 2 root root       6 Jun 22  2021 kernels
drwxr-xr-x  8 1001 1001     158 Oct 19  2022 nginx-1.22.1
-rw-r--r--  1 root root 1073948 Oct 19  2022 nginx-1.22.1.tar.gz
[root@localhost src]# 

# 编译安装
[root@localhost src]# cd nginx-1.22.1
[root@localhost nginx-1.22.1]# ./configure --prefix=/usr/local/nginx --user=nginx > --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log 

[root@localhost nginx-1.22.1]# yum -y install make 
[root@localhost nginx-1.22.1]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
......编译过程省略

nginx安装后配置
# 配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# source /etc/profile.d/nginx.sh

# 设置开机自启配置文件
[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service
[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start nginx 
[root@localhost ~]# 

# 查看端口
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q        Local Address:Port         Peer Address:Port    Process    
LISTEN    0         511                 0.0.0.0:80                0.0.0.0:*                  
LISTEN    0         128                 0.0.0.0:22                0.0.0.0:*                  
LISTEN    0         128                    [::]:22                   [::]:*                  
[root@localhost ~]# 

页面访问测试

在这里插入图片描述

mysql的部署
# 安装mariadb和mariadb-server
[root@localhost ~]# yum -y install mariadb mariadb-server

# 开启mariadb服务并开机自启  
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# 

# 设置密码
[root@localhost ~]# mysql 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> set password = password('123456');
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye
[root@localhost ~]# 

# 查看端口
[root@localhost ~]# ss -antl
State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0          511                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                       [::]:22                     [::]:*                    
LISTEN     0          80                           *:3306                      *:*                    
[root@localhost ~]# 

PHP部署与配置
# 下载依赖包
[root@localhost php-8.2.9]# yum -y install libxml2-devel sqlite-devel libcurl-devel libzip-devel
[root@localhost php-8.2.9]# yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@localhost php-8.2.9]# yum -y reinstall readline 
[root@localhost php-8.2.9]# yum -y install readline-devel



# 下载php的软件包
[root@localhost src]# wget https://www.php.net/distributions/php-8.2.9.tar.gz

# 解压php包
[root@localhost src]# tar xf php-8.2.9.tar.gz 
[root@localhost src]# ll
total 19668
drwxr-xr-x.  2 root root        6 Jun 22  2021 debug
drwxr-xr-x.  2 root root        6 Jun 22  2021 kernels
drwxr-xr-x   9 1001 1001     4096 Oct 18 02:29 nginx-1.22.1
-rw-r--r--   1 root root  1073948 Oct 19  2022 nginx-1.22.1.tar.gz
drwxr-xr-x  16 root root     4096 Aug  3 07:39 php-8.2.9
-rw-r--r--   1 root root 19052910 Aug  3 08:10 php-8.2.9.tar.gz
[root@localhost src]# 

# 进入目录并进行编译安装
[root@localhost php-8.2.9]# ./configure --prefix=/usr/local/php8 --with-config-file-path=/etc --enable-fpm --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --enable-gd --with-jpeg --with-zlib-dir --with-freetype --with-gettext --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --with-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --disable-debug 

[root@localhost php-8.2.9]# make && make install

配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh
[root@localhost ~]# source /etc/profile.d/php8.sh
[root@localhost ~]# which php
/usr/local/php8/bin/php
[root@localhost ~]# php -v
PHP 8.2.9 (cli) (built: Oct 18 2023 03:44:21) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.9, Copyright (c) Zend Technologies
[root@localhost ~]# 

配置php-fpm
[root@localhost php-8.2.9]# cp php.ini-production /etc/php.ini
[root@localhost php-8.2.9]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.2.9]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-8.2.9]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@localhost php-8.2.9]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
[root@localhost php-8.2.9]# 

启动php-fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# ss -antl
State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0          511                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          2048                 127.0.0.1:9000                0.0.0.0:*                    
LISTEN     0          128                       [::]:22                     [::]:*                    
LISTEN     0          80                           *:3306                      *:*                    
[root@localhost ~]# 

# 加入systemctl管理

[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm server daemon
After=network.targe

[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/php-fpm start
ExecStop=/etc/rc.d/init.d/php-fpm stop
ExecReload=/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl start php-fpm.service  (先停止php服务)
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable php-fpm.service 
Synchronizing state of php-fpm.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# 


让nginx支持php功能
# 编辑主配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
 42 
 43         location / {
 44             root   html;
 45             index  index.html index.htm index.php; //添加index.php
 46         }

 65         location ~ \.php$ {  //取消注释
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }
 
 wq!
# 写一个php文件
[root@localhost ~]# vim /usr/local/nginx/html/index.php
[root@localhost ~]# cat /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

# 重启nginx
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# ss -antl
State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0          511                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          2048                 127.0.0.1:9000                0.0.0.0:*                    
LISTEN     0          128                       [::]:22                     [::]:*                    
LISTEN     0          80                           *:3306                      *:*                    
[root@localhost ~]# 

在网页测试

在这里插入图片描述

部署Discuz论坛系统

下载Discuz论坛系统代码包

去官网下载: https://www.discuz.vip/download.html

然后上传到虚拟机中

[root@localhost ~]# ls
anaconda-ks.cfg  Discuz_X3.5_SC_UTF8_20231001.zip

# 创建一个目录存放网站文件
[root@localhost ~]# mkdir /usr/local/nginx/html/Discuz

# 解压dicuz
[root@localhost ~]# yum -y install unzip
[root@localhost ~]# unzip Discuz_X3.5_SC_UTF8_20231001.zip -d /usr/local/nginx/html/Discuz/
[root@localhost html]# ls
50x.html  Discuz  index.html  index.php
[root@localhost html]# cd Discuz/
[root@localhost Discuz]# ls
LICENSE  qqqun.png  readme  readme.html  upload  utility.html
[root@localhost Discuz]# cd upload/
[root@localhost upload]# ls
admin.php  connect.php      group.php   misc.php    source
api        crossdomain.xml  home.php    plugin.php  static
api.php    data             index.php   portal.php  template
archiver   favicon.ico      install     robots.txt  uc_client
config     forum.php        member.php  search.php  uc_server
[root@localhost upload]# 


# 修改权限
[root@localhost upload]# pwd
/usr/local/nginx/html/Discuz/upload
[root@localhost upload]# chown -R nginx config/
[root@localhost upload]# chown -R nginx data/
[root@localhost upload]# chown -R nginx uc_client/
[root@localhost upload]# chown -R nginx uc_server/
[root@localhost upload]# chmod -R 777 config/
[root@localhost upload]# chmod -R 777 data/
[root@localhost upload]# chmod -R 777 uc_client/
[root@localhost upload]# chmod -R 777 uc_server/
[root@localhost upload]# mysql -uroot -p123456 -e "create database Discuz;"
[root@localhost upload]# 

# 进入数据库查看是否创建成功
[root@localhost upload]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| Discuz             |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.028 sec)

MariaDB [(none)]> 

配置虚拟主机
# 编辑nginx配置文件,创建一个虚拟主机,可以用域名访问
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

.........
 34 
 35     server {
 36         listen       80;
 37         server_name  www.tqloh.com; //修改为自己的域名
 
 43         location / {
 44             root   html/Discuz/upload; //改为网站的目录
 45             index index.php index.html index.htm;
 46         }
 65         location ~ \.php$ {
 66             root           html/Discuz/upload; //改为网站目录
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 70             include        fastcgi_params;
 71         }

# 重启nginx服务和php-fpm
[root@localhost ~]# systemctl restart nginx.service 
[root@localhost ~]# systemctl restart php-fpm.service 
[root@localhost ~]# 

记得去映射ip和域名
安装Discuz论坛
# 测试域名是否可以ping通

[root@localhost ~]# ping www.tqloh.com
PING tq.com (62.100.206.44) 56(84) bytes of data.
64 bytes from dragon1.tqloh.com (62.100.206.44): icmp_seq=1 ttl=128 time=210 ms
64 bytes from dragon1.tqloh.com (62.100.206.44): icmp_seq=2 ttl=128 time=189 ms
^Z
[1]+  Stopped                 ping www.tqloh.com
[root@localhost ~]# 

可以用域名访问,不过后面要加/install/

在这里插入图片描述

也可以用IP

在这里插入图片描述在这里插入图片描述在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

安装完毕
访问站点

在这里插入图片描述

创建一个用户

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值