一、相关概念
- l:linux操作系统
- n:nginx 前端页面
- m:mysql数据库 账号密码等都是保存在这个数据库里面
- p:php-------nginx擅长处理静态页面,页面登录账户需要请求到数据库,通过php把动态请求转发到数据库
二、搭建简易论坛的步骤
1.安装数据库
#安装数据库的依赖环境
apt install -y libaio1 libncurses5
#解压myseq的压缩包到/usr/local,改名为mysql
tar xf mysql-8.0.30-el7-x86_64.tar.gz -C /usr/local
mv mysql-8.0.30-el7-x86_64 mysql
#创建mysql用户
useradd -s /sbin/nologin mysql
#修改mysql文件的所有者
chown mysql.mysql -R /usr/local/mysql/
vim /etc/my.cnf #mysql的主配置文件
[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
#保存退出
chown mysql.mysql /etc/my.cnf#添加mysql路径到全局变量
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
#对数据库进行初始化
cd /usr/local/mysql/bin
./mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data
#把mysql.server移动到 /etc/init.d/mysqld下,并赋予执行权限
cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#重启使配置生效
systemctl daemon-reload
systemctl restart mysqld
#查看musql服务是否启动
netstat -antp | grep 3306
#添加用户名和密码
mysqladmin -u root -p password "123456"
不输入密码,直接回车
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';#修改加密方式
2.安装php
php的配置文件
- php.ini 主配置文件
- php-fpm.conf 进程服务端的配置文件
- www.conf 扩展配置文件
- php-fpm:是一个fastcgi的管理工具,nginx的动态请求实际上是由php-fpm来处理
#解压
tar xf php-8.1.27.tar.gz
#安装依赖环境
apt-get install -y libgd-dev libjpeg8-dev libpng-dev libfreetype6-dev libxml2-dev zlib1g-dev libcurl4-openssl-dev libssl-dev libonig-dev libsqlite3-dev
groupadd nobody#创建一个组
cd /opt/php-8.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
#设置软链接
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
#修改配置文件
cd /opt/php-8.1.27
cp php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#set nu
#976gg-->找到第976行
date.timezone = Asia/Shanghai
#1181gg-->找到第1181行
mysqli.default_socket = /usr/local/mysql/mysql.sock
#保存退出
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
pid = /var/log/php-fpm.pid
error_log = /var/log/php-fpm.log
#保存退出
cd /usr/local/php/etc/php-fpm.d
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
cd /opt/php-8.1.27/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl restart php-fpm.service
netstat -antp | grep 9000
3.修改nginx配置
nginx同样用源码包编译安装完成
mkdir -p /var/www/html
cd /usr/local/nginx/conf
cp nginx.conf nginx.conf.bak.2024.12.9
vim nginx.conf
#添加到server块里的内容如下图所示
systemctl restart nginx
#创建数据库,数据库的用户和密码,过程如下图所示
cd /usr/local/nginx/html
vim index.php
<?php link=mysqli_connect('192.168.206.60','bbsuser','admin123'); if(link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; ?>
4.安装论坛
unzip Discuz_X3.5_SC_UTF8.zip -d /opt/dis
cp -r upload/ /usr/local/nginx/html/bbs
cd /usr/local/nginx/html
mv bbs/ /var/www/html/
cd bbs/config/
cp config_global_default.php config_global.php
cp config_ucenter_default.php config_ucenter.php
chmod 777 -R /var/www/html/bbs/
chown nginx.nginx -R /var/www/html/bbs/
systemctl restart nginx.service