LNMP architecture to build Discuz forum
1. Compile and install Nginx
Turn off firewall
systemctl stop firewalld //关闭防火墙
setenforce 0
Install dependent environment
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
create user
useradd -M -s /sbin/nologin nginx
//创建一个不能登录且不创建家目录的用户
mkdir /data
//在根目录下创建一个data目录
wget https://nginx.org/download/nginx-1.24.0.tar.gz
//去官网下载安装包
tar xf nginx-1.24.0.tar.gz //解压安装包
Configure the compilation environment and select the compilation module
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
Install
make -j2 && make install //编译为可执行文件并拷贝到系统中
chown -R nginx.nginx /usr/local/nginx
//添加属主和属组
Create soft links so they can be completed
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
Add to system services (systemd startup)
vim /lib/systemd/system/nginx.service
//进入配置文件
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
Reload and start the program
systemctl daemon-reload
systemctl start nginx
systemctl status nginx.service
Browser view
2. Compile and install the MySQL service
Drag the mysql installation package into the data directory and
unzip the installation package.
tar xf mysql-boost-5.7.20.tar.gz
Install dependency packages
yum install -y ncurses-devel autoconf cmake
Configure compilation environment and modules
cd /data/mysql-5.7.20/
//进入到解压后的mysql文件
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
//配置编译选项
Install
make -j2 && make install
Create a user and add owners and groups
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
Write configuration file
vim /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
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
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
Set the owner and group of the configuration file, and set permissions
chown mysql:mysql /etc/my.cnf
Set the path environment variable and add it to PATH
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
//加入PATH中,使其可以补全
echo 'export PATH' >> /etc/profile
//声明这个变量为全局变量
Database initialization
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
Add mysqld system service
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
//system启动
systemctl daemon-reload //刷新识别
systemctl start mysqld.service //开启服务
ss -natp | grep 3306 //查看端口
Create mysql login user
mysqladmin -u root -p password "abc123"
Login mysql
mysql -u root -p
quit
quit; //分号不能少
3. Compile and install php
Install dependent environment
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
unzip files
cd /data //切换到data目录下
tar xf php-7.1.10.tar.bz2 //解压文件
Compile and configure environment to install modules
#编译环境检测 功能模块添加
./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-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
Detailed explanation
./configure
–prefix=/usr/local/php7 \ Specify the installation path of the PHP program
–with-mysql-sock=/usr/local/mysql/mysql.sock \ Specify the storage path of the mysql database connection file
–with-config -file-path=/usr/local/php7 Set the location where the PHP configuration file php.ini will be stored
– with-mysqli \ Add MySQL extension support #mysqli extension technology can not only call MySQL stored procedures and process MySQL transactions, but also Can make accessing the database more stable
– with-zlib \ Support zlib function, provide data compression
– with-curl \ Turn on the curl extension function, implement HTTP Get download and Post request method
– with-gd \ Activate the gd library Support
–with-jpeg-dir \ Activate jpeg support
–with-png-dir \ Activate png support
–with-freetype-dir
–with-openssl
–enable-mbstring \ Enable multi-byte string function to support Chinese, etc. Code
–enable-xml \ Enable Extensible Markup Language Module
–enable-session \ Session
–enable-ftp \ Text Transfer Protocol
–enable-pdo \ Function library
–enable-tokenizer \ Token interpreter
–enable-zip ZIP compression format
Compile and install
make -j2 && make install
Create a soft link
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
Adjust PHP configuration files
cp /data/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini #模板
vim /usr/local/php/lib/php.ini #修改主配置文件
Adjust the process service configuration file
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
Adjust extension configuration files
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
Start php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000
cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl restart php-fpm.service
Configure Nginx to support PHP parsing
vim /usr/local/nginx/conf/nginx.conf
systemctl restart nginx.service
Verify PHP test page
//创建网页文件
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
//重启nginx服务
systemctl restart nginx
//在网页测试
http://192.168.190.200/index.php
4. Install the forum
Log in to the MySQL database as the root user and configure it.
mysql -u root -p
//以 root 用户身份登录到 MySQL 数据库
mysql> CREATE DATABASE bbs; //创建一个数据库
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123'; //把bbs数据库里面所有表的权限授予给bbsuser,并设置密码
mysql>flush privileges; //刷新数据库
Unzip the Discuz source code package and configure it
unzip Discuz_X3.4_SC_UTF8.zip //解压
cd /opt/dir_SC_UTF8/
//拷贝文件到数据
cp -r upload/ /usr/local/nginx/html/bbs/
//改权限 改属组属主
cd /usr/local/nginx/html/bbs/
chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
Browser access
http://192.168.190.200/bbs/install/index.php