目录
概念
搭建论坛的架构: lnmp+DISCUZ
l 表示linux操作系统
n 表示nginx前端页面的web服务
m 表示 mysql 数据库 用来保存用户和密码以及论坛的相关内容
p 表示php 动态请求转发的中间件
步骤
(已经提前安装了nginx)
1.关闭防火墙
安装mysql8.0.30
2.安装mysql
3.创建程序用户管理、修改mysql目录和配置文件的权限
4.修改配置文件
vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
5.设置环境变量,申明/宣告mysql命令便于系统识别
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
6.初始化数据库
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
7.设置系统识别,进行操作
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload
systemctl restart mysqld
查看mysqld的3306端口是否开启
8.初始化数据库密码
mysqladmin -u root -p password "123456"
直接回车即可
9.进入数据库
mysql -u root -p123456
创建用户并设置密码
create user 'root'@"%" identified by '123456';
赋予远程连接的权限
grant all privileges on *.* to 'root'@'%';
刷新生效
flush privileges;
修改加密方式,可以进行远程连接
alter user 'root'@'%' identified with mysql_native_password by "123456";
刷新生效
flush privileges;
exit 退出
安装php
10.安装php环境依赖包
cd /opt
yum -y install epel-release(需要先安装epel源)
yum -y install gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
oniguruma-devel \
sqlite-devel
安装php8.1.27
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-pdo-mysql \
--with-openssl \
--with-sqlite-devel \
--with-oniguruma-devel \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
make -j 4 && make install
11.路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
12.调整PHP配置文件
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
调整主配置文件
cp /opt/php-8.1.27/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
--1181行--修改 (set nu 显示行号)
mysqli.default_socket = /usr/local/mysql/mysql.sock
--976行--取消注释,修改
date.timezone = Asia/Shanghai
验证安装的模块 php -m
调整进程服务配置文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
--17行--去掉";"注释
pid = run/php-fpm.pid
调整扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
13.启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000 (查看php 9000 端口是否开启)
添加系统配置
cd /opt/php-8.1.27/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl restart php-fpm.service
14.配置nginx转发动态请求
cd /usr/local/nginx/conf
vim nginx.conf
取消注释并修改
systemctl restart nginx
15.vim index.php
<?php
phpinfo();
?>
16.访问192.168.233.10/index.php
17进入数据库创建专门用来保存论坛信息的用户和库
mysql -u root -p123456
show databases;
创建库和用户并设置密码
create database bbs;
create user 'bbsuser'@'%' identified by 'admin123';
赋权
grant all privileges on bbs.* to 'bbsuser'@'%';
flush privileges;
创建本地连接的用户
create user 'bbsuser'@'localhost' identified by 'admin123';
grant all privileges on bbs.* to 'bbsuser'@'localhost';
flush privileges;
exit 退出
18.尝试php能否访问数据库
vim index.php
<?php
$link=mysqli_connect('192.168.233.10','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
安装Discuz
19.安装论坛
安装Discuz_X3.5_SC_UTF8.zip
复制目录
cp -r upload/ /usr/local/nginx/html/bbs/
赋权
chown -R nginx.nginx bbs/
chmod -R 777 bbs/
访问 http://192.168.233.10/bbs/install/index.php
访问192.168.233.10/bbs/index.php