Compile and install Discuz framework of the forum LNMP

LNMP architecture

LNMP平台就是Linux,Nginx,MySQL,PHP的组合架构,需要Linux服务器,MySQL服务器,PHP解析环境

Here Insert Picture Description

LNMP architectural components

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。
Nginx是一个高性能的HTTP和反向代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

LAMP advantage

Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少,小巧高效。

Demo steps:

The first step: using a remote share acquisition on Linux from Windows shared source package

[root@localhost ~]# smbclient -L //192.168.235.1/  
##远程共享访问
Enter SAMBA\root's password: 

                Sharename       Type      Comment
                ---------       ----      -------
                LNMP         Disk       
[root@localhost ~]# mkdir /abc              
[root@localhost ~]# mount.cifs //192.168.235.1/LNMP /abc 
##挂载到/abc目录下

Step two: compile and install Nginx

1, the source packet to extract the directory / opt

[root@localhost ~]# cd /abc    ##切换到挂载点目录
[root@localhost abc]# ls
Discuz_X3.4_SC_UTF8.zip    nginx-1.12.2.tar.gz
mysql-boost-5.7.20.tar.gz  php-7.1.10.tar.gz
[root@localhost abc]# tar zxvf nginx-1.12.2.tar.gz -C /opt   ##解压Nginx源码包到/opt下
[root@localhost abc]# cd /opt/    ##切换到解压的目录下
[root@localhost opt]# ls
nginx-1.12.2  rh

2, the installation environment of the compiler need Package

[root@localhost opt]# yum -y install \
gcc \                                       //c语言
gcc-c++ \                               //c++语言
pcre-devel \                     //pcre语言工具
zlib-devel                       //数据压缩函数库

3. Create a user program and compile Nginx nginx

[root@localhost opt]# useradd -M -s /sbin/nologin nginx  ##创建程序用户,限定其
[root@localhost opt]# cd nginx-1.12.2/                 ##切换到nginx目录下
[root@localhost nginx-1.12.2]# ./configure \         ##配置nginx
> --prefix=/usr/local/nginx \        ##安装路径
> --user=nginx \                         ##用户名
> --group=nginx \                       ##用户组
> --with-http_stub_status_module     ##访问状态统计模块

4, compile and install

[root@localhost nginx-1.12.2]#make && make install

5, optimization Nginx service startup script, and the establishment of command soft links

[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 
##创建软连接让系统识别nginx启动脚本
[root@localhost nginx]# nginx -t       ##检查配置文件的语法问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# nginx      ##开启ngnix
[root@localhost nginx]# netstat -ntap | grep 80     ##查看端口,nginx已经开启
tcp   0   0 0.0.0.0:80      0.0.0.0:*   LISTEN   39620/nginx: master 
[root@localhost nginx]# systemctl stop firewalld.service    ##关闭防火墙
[root@localhost nginx]# setenforce 0 
[root@localhost nginx]# nginx                         ##开启nginx 服务

6, making service management script nginx

[root@localhost nginx]# cd /etc/init.d/   ##切换到启动配置文件目录
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx         ##编辑启动脚本文件

    #!/bin/bash
    # chkconfig: - 99 20                                    ##注释信息
    # description: Nginx Service Control Script
    PROG="/usr/local/nginx/sbin/nginx"           ##设置变量为nginx命令文件
    PIDF="/usr/local/nginx/logs/nginx.pid"       ##设置变量PID文件 进程号为5346
    case "$1" in  
        start)
            $PROG                                              ##开启服务
            ;;
        stop)
            kill -s QUIT $(cat $PIDF)                    ##关闭服务
            ;;
        restart)                                                  ##重启服务
            $0 stop
            $0 start
            ;;
        reload)                                                  ##重载服务
            kill -s HUP $(cat $PIDF)
            ;;
        *)                                                           ##错误输入提示
                    echo "Usage: $0 {start|stop|restart|reload}"
                    exit 1
    esac
    exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx    ##授予启动脚本执行权限
[root@localhost init.d]# chkconfig --add nginx          ##添加到service管理器
[root@localhost init.d]# service nginx stop                ##使用service停止nginx服务
[root@localhost init.d]# service nginx start                ##使用service启动nginx服务

7, systemctl management script nginx

[root@localhost ~]# vim /lib/systemd/system/nginx.service      ##创建配置文件

[Unit]
Description=nginx                                            ##描述
After=network.target                                        ##描述服务类型
[Service]
Type=forking                                                    ##后台运行形式
PIDFile=/usr/local/nginx/logs/nginx.pid            ##PID文件位置
ExecStart=/usr/local/nginx/sbin/nginx              ##启动服务
ExecReload=/usr/bin/kill -s HUP $MAINPID    ##根据PID重载配置
ExecStop=/usr/bin/kill -s QUIT $MAINPID       ##根据PID终止进程
PrivateTmp=true
[Install]
WantedBy=multi-user.target

[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service     ##设置执行权限
[root@localhost ~]# systemctl stop nginx.service       ##关闭nginx 
[root@localhost ~]# systemctl start nginx.service       ##开启

Step four: compile and install MySQL

1, the mounting assembly environment

[root@localhost ~]# yum install -y \     ##安装环境组件
> ncurses \
> ncurese-devel \          ##控制终端屏幕显示的库
> bison \                 ##语法分析工具
> cmake                 ##cmake工具
[root@localhost ~]# useradd -s /sbin/nologin mysql     ##创建程序用户

2, packets to extract the source / opt under

[root@localhost ~]# cd /abc
[root@localhost abc]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt   
[root@localhost abc]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20  nginx-1.12.2  rh

3, cmake configuration

[root@localhost opt]# cd mysql-5.7.20/       ##切换到MySQL目录下
[root@localhost mysql-5.7.20]# cmake \     ##cmake配置
-DCMAKE_INSTALL_PREFIX=/usr/localmysql \            ##安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ ##定义sock文件连接数据库文件
-DSYSCONFDIR=/etc \                                                   ##配置文件目录
-DSYSTEMD_PID_DIR=/usr/local/mysql \                      ##PID文件目录
-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                                                   ##主从参数

4, compile and install

[root@localhost mysql-5.7.20]#make && make install

5, modify the configuration file mysql

[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/   
##数据库目录进行权限调整
[root@localhost mysql-5.7.20]# 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      ##设置mysql的安装目录
    datadir = /usr/local/mysql/data    ##设置mysql数据库的数据的存放目录
    port = 3306                    ##设置3306端口
    character_set_server=utf8            ##中文字符集
    pid-file = /usr/local/mysql/mysqld.pid     ##pid文件路径
    socket = /usr/local/mysql/mysql.sock     ##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
##支持模块

[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
    ##将MySQL命令写到本地主机环境配置中
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile   
     ##设置全局环境配置
[root@localhost mysql-5.7.20]# source /etc/profile    
    ##重启配置文件

6, initialize the mysql database

[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \        ##初始化
> --user=mysql \                 ##用户
> --basedir=/usr/local/mysql \      ##安装目录
> --datadir=/usr/local/mysql/data   ##数据库数据文件目录

7 systemctl management easy to use, copy service profile to mysql / usr / lib / systemd / system / lower

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 
    ##ystemctl管理
[root@localhost mysql]# systemctl enable mysqld   ##开机自启动
[root@localhost mysql]# systemctl start mysqld.service     ##开启数据库
[root@localhost mysql]# netstat -ntap | grep 3306              ##查看MySQL端口号开启情况
tcp6  0  0 :::3306    :::*       LISTEN   59464/mysqld   

8, set the mysql password

[root@localhost mysql]# mysqladmin -u root -p password
Enter password:               ##回车
New password:                ##输入新密码
Confirm new password:       ##确认密码

Step five: compiling and installing PHP

1, the installation environment dependencies

[root@localhost mysql]# yum install -y \
> libjpeg \                              ##jpeg图片格式和开发包
> libjpeg-devel \
> libpng libpng-devel \                 ##png图片和开发包
> freetype freetype-devel \             ##字体库
> libxml2 \                             ##xml文件库
> libxml2-devel \
> zlib zlib-devel \                     ##压缩库 
> curl curl-devel \                     ##支持数据文件下载工具
> openssl openssl-devel                 ##安全访问连接

2, extract the source packet

[root@localhost mysql]# cd /abc   
[root@localhost abc]# tar jxvf php-7.1.10.tar.bz2 -C /opt    
[root@localhost abc]# cd /opt
[root@localhost opt]# ls   
mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh

3. Configure PHP

[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10]# ./configure 
--prefix=/usr/local/php                        
##安装路径
--with-mysql-sock=/usr/local/mysql/mysql.sock   
##连接文件建立通信桥梁
--with-mysqli                                    
##客户端支持库
--with-zlib                                         
##压缩模块
--with-curl                                        
##支持上传下载功能
--with-gd                                          
##gd图像支持图片处理库
--with-jpeg-dir                                  
##jpeg图像支持图片处理库
--with-png-dir                                   
##png图像支持图片处理库
--with-freetype-dir                            
##字体格式库
--with-openssl                                  
##安全访问连接
--enable-fpm                                    
##fpm支持动态请求模块
--enable-mbstring                            
##支持多字节的字符串
--enable-xml                                    
##xml文件
--enable-session                             
##session支持会话
--enable-ftp                                     
##ftp服务
--enable-pdo                                   
##驱动连接管理
--enable-tokenizer                          
##PHP自带函数库
--enable-zip                                    
##zip压缩功能

4, compile and install

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

5, the core configuration profiles

(Php.ini core configuration file, php-fpm.conf process service profile, www.conf extended configuration file)

[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini   
##复制到安装目录lib库中
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini  
##配置核心配置文件

mysqli.default_socket = /usr/local/mysql/mysql.sock     
##默认连接文件
date.timezone = Asia/Shanghai                          
##时区

[root@localhost php-7.1.10]# /usr/local/php/bin/php -m   
##验证安装的模块

6, module configuration and optimization FPM

[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf   ##优化复制默认进程服务配置文件
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf   ##优化复制扩展配置文件
[root@localhost php-fpm.d]# cd /usr/local/php/etc/  
[root@localhost etc]# vim php-fpm.conf      ##开启fpm.pid进程
pid = run/php-fpm.pid
[root@localhost etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini
[root@localhost etc]# netstat -ntap | grep 9000     ##查看端口信息
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      69371/php-fpm: mast 
[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/   ##创建PHP命令软链接到系统命令
[root@localhost etc]# ps aux | grep -c "php-fpm"                    ##查看php-fpm模块进程信息           
4

7, Nginx configuration to support PHP function

[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf    ##配置nginx配置文件
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;   ##站点路径
        include        fastcgi_params;
    }       
[root@localhost etc]# vim /usr/local/nginx/html/index.php               ##测试php网页
<?php
phpinfo();
?>

[root@localhost etc]# nginx -s stop
##停止nginx服务
[root@localhost etc]# nginx 
##启动nginx服务

8, test page

Here Insert Picture Description

9, enter the database administrator to create a database and set bbs and password

[root@localhost etc]# mysql -u root -p
Enter password:      ##进入数据库,密码为之前设定的abc23
mysql> CREATE DATABASE BBS;   ##创建bbs数据库
Query OK, 1 row affected (0.00 sec)

mysql> GRANT all ON bbs.* TO 'bbsusers'@'%' IDENTIFIED BY 'admin123';  
##提权数据库用户bbsuser为管理员并设定密码
Query OK, 0 rows affected, 1 warning (0.00 sec)       

mysql> GRANT all ON bbs.* TO 'bbsusers'@'localhost' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;         ##刷新数据库
Query OK, 0 rows affected (0.00 sec)

mysql> quit       ##退出

[root@localhost etc]# vim /usr/local/nginx/html/index.php   ##测试数据库连接状态
<?php
$link=mysqli_connect('192.168.235.158','bbsusers','admin123');
if($link) echo "<h1>Success!</h1>";
else echo "Fail!!";
?>
[root@localhost etc]# systemctl restart nginx.service     ##重启服务

10, once again test page

Here Insert Picture Description

Step Six: Install Discuz forum archive

1. Unzip the forum package under / opt, and copy the directory contents to the site bbs

[root@localhost etc]# cd /abc                   
[root@localhost abc]# unzip  Discuz_X3.4_SC_UTF8.zip -d /opt    ##解压到/opt下
[root@localhost abc]# cd /opt
[root@localhost opt]# ls
dir_SC_UTF8  mysql-5.7.20  nginx-1.12.2  php-7.1.10  rh  说明.htm
[root@localhost opt]# cd dir_SC_UTF8/          ##切入论坛目录
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/     
##复制/opt目录中的所有内容到bbs站点目录中

2, the user enters the site and to provide the right program

[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/          ##切入bbs站点目录
[root@localhost bbs]# chown -R root:nginx ./config/                   ##提权程序用户提权
[root@localhost bbs]# chown -R root:nginx ./data/                     ##修改nginx属组
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/                            ##修改所有权限
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

3, the browser input 192.168.235.158/bbs/install/index.php site, enter Discuz Forum Guide

Here Insert Picture Description

4, set up and run a new installation environment

Compile and install Discuz framework of the forum LNMP

5, install the database

数据服务器:192.168.235.158(此处输入创建数据库主机的IP)
数据库名:bbs
数据库用户名:bbsusers(用户名可在命令行修改)
数据库密码:admin123(密码可在命令行修改)
管理员账号:admin(该账号为默认)
密码:123123(密码可直接在网页设定)

Here Insert Picture Description

Seven, visit the forum start posting it !!!

Here Insert Picture Description

Guess you like

Origin blog.51cto.com/14449521/2448023