Discuz forum for compiling and installing LNMP architecture

LNMP architecture

LNMP platform is the combined architecture of Linux, Nginx, MySQL and PHP. It requires Linux server, MySQL server and PHP parsing environment

LNMP schema components

Linux is a kind of Unix computer operating system, which is the most popular free operating system.
Nginx is a high-performance HTTP and reverse proxy server.
Mysql is a small relational database management system.
PHP is a script language that embeds HTML documents on the server side.

Advantages of LAMP

Nginx has stable performance, rich functions, simple operation and maintenance, fast static file processing speed, little system resources consumption, small and efficient.

Demonstration steps:

Step 1: use remote sharing on Linux to obtain the source package from Windows sharing

[root@localhost ~]# smbclient -L //192.168.235.1/  
##Remote shared access
Enter SAMBA\root's password: 

                Sharename       Type      Comment
                ---------       ----      -------
                LNMP         Disk       
[root@localhost ~]# mkdir /abc              
[root@localhost ~]# mount.cifs //192.168.235.1/LNMP /abc 
##Mount to / abc directory

Step 2: compile and install Nginx

1. Extract the source package to the / opt directory

[root@localhost ~]# cd /abc    ##Switch to mount point directory
[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   ##Extract the Nginx source package to / opt
[root@localhost abc]# cd /opt/    ##Switch to the unzipped directory
[root@localhost opt]# ls
nginx-1.12.2  rh

2. Install the environment component package required for compilation

[root@localhost opt]# yum -y install \
gcc \                                       //c language
gcc-c++ \                               //c++ language
pcre-devel \                     //pcre language tools
zlib-devel                       //Data compression function library

3. Create program user nginx and compile nginx

[root@localhost opt]# useradd -M -s /sbin/nologin nginx  ##Create program users and limit them
[root@localhost opt]# cd nginx-1.12.2/                 ##Switch to nginx directory
[root@localhost nginx-1.12.2]# ./configure \         ##Configure nginx
> --prefix=/usr/local/nginx \        ##Installation path
> --user=nginx \                         ##User name
> --group=nginx \                       ##User group
> --with-http_stub_status_module     ##Access status statistics module

4. Compile and install

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

5. Optimize the startup script of Nginx service and establish the command soft link

[root@localhost nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ 
##Create a soft connection for the system to recognize the nginx startup script
[root@localhost nginx]# nginx -t       ##Check configuration file for syntax problems
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      ##Open ngnix
[root@localhost nginx]# netstat -ntap | grep 80     ##Check the port. nginx is on
tcp   0   0 0.0.0.0:80      0.0.0.0:*   LISTEN   39620/nginx: master 
[root@localhost nginx]# systemctl stop firewalld.service    ##Turn off firewall
[root@localhost nginx]# setenforce 0 
[root@localhost nginx]# nginx                         ##Start nginx service

6. Create service management nginx script

[root@localhost nginx]# cd /etc/init.d/   ##Switch to startup profile directory
[root@localhost init.d]# ls
functions  netconsole  network  README
[root@localhost init.d]# vim nginx         ##Edit startup script file

    #!/bin/bash
    # chkconfig: - 99 20                                    ##Annotation information
    # description: Nginx Service Control Script
    PROG="/usr/local/nginx/sbin/nginx"           ##Set variable to nginx command file
    PIDF="/usr/local/nginx/logs/nginx.pid"       ##Set the variable PID file process number to 5346
    case "$1" in  
        start)
            $PROG                                              ##Opening service
            ;;
        stop)
            kill -s QUIT $(cat $PIDF)                    ##Shut down service
            ;;
        restart)                                                  ##Restart service
            $0 stop
            $0 start
            ;;
        reload)                                                  ##Heavy load service
            kill -s HUP $(cat $PIDF)
            ;;
        *)                                                           ##Error input prompt
                    echo "Usage: $0 {start|stop|restart|reload}"
                    exit 1
    esac
    exit 0
[root@localhost init.d]# chmod +x /etc/init.d/nginx    ##Grant start script execution permission
[root@localhost init.d]# chkconfig --add nginx          ##Add to service manager
[root@localhost init.d]# service nginx stop                ##Using service to stop nginx service
[root@localhost init.d]# service nginx start                ##Using service to start nginx service

7. System CTL manages nginx scripts

[root@localhost ~]# vim /lib/systemd/system/nginx.service      ##create profile

[Unit]
Description=nginx                                            ##describe
After=network.target                                        ##Describe service type
[Service]
Type=forking                                                    ##Background operation form
PIDFile=/usr/local/nginx/logs/nginx.pid            ##PID file location
ExecStart=/usr/local/nginx/sbin/nginx              ##Startup service
ExecReload=/usr/bin/kill -s HUP $MAINPID    ##Overload configuration according to PID
ExecStop=/usr/bin/kill -s QUIT $MAINPID       ##Terminate process according to PID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

[root@localhost ~]# chmod 754 /lib/systemd/system/nginx.service     ##Set execution permission
[root@localhost ~]# systemctl stop nginx.service       ##Close nginx 
[root@localhost ~]# systemctl start nginx.service       ##open

Step 4: compile and install MySQL

1. Install environment components

[root@localhost ~]# yum install -y \     ##Install environment components
> ncurses \
> ncurese-devel \          ##Control terminal screen display library
> bison \                 ##Parsing tools
> cmake                 ##cmake tools
[root@localhost ~]# useradd -s /sbin/nologin mysql     ##Create program user

2. Decompress the source package to / opt

[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/       ##Switch to MySQL directory
[root@localhost mysql-5.7.20]# cmake \     ##cmake configuration
-DCMAKE_INSTALL_PREFIX=/usr/localmysql \            ##Installation path
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ ##Define a sock file to connect to a database file
-DSYSCONFDIR=/etc \                                                   ##Profile directory
-DSYSTEMD_PID_DIR=/usr/local/mysql \                      ##PID file directory
-DDEFAULT_CHARSET=utf8 \                                       ##Specify character set
-DDEFAULT_COLLATION=utf8_general_ci \                 ##Specify character set defaults
-DWITH_INNOBASE_STORAGE_ENGINE=1 \            ##Storage engine
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \                 ##Database data file directory
-DWITH_BOOST=boost \                                               ##Underlying runtime
-DWITH_SYSTEMD=1                                                   ##Master slave parameter

4. Compilation and installation

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

5. Modify mysql configuration file

[root@localhost mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/   
##Database directory for permission adjustment
[root@localhost mysql-5.7.20]# vim /etc/my.cnf     
##Adjust profile

    [client]                            ##Client
    port = 3306
    default-character-set=utf8
    socket = /usr/local/mysql/mysql.sock

    [mysql]                           ##Client     
    port = 3306
    default-character-set=utf8
    socket = /usr/local/mysql/mysql.sock

    [mysqld]                         ##The server        
    user = mysql                  ##user
    basedir = /usr/local/mysql      ##Set the installation directory of mysql
    datadir = /usr/local/mysql/data    ##Set the storage directory of mysql database data
    port = 3306                    ##Set 3306 port
    character_set_server=utf8            ##Chinese character set
    pid-file = /usr/local/mysql/mysqld.pid     ##pid file path
    socket = /usr/local/mysql/mysql.sock     ##sock file path
    server-id = 1                                           ##Master slave service parameters

    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
##Support module

[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
    ##Write MySQL command to local host environment configuration
[root@localhost mysql-5.7.20]# echo 'export PATH' >> /etc/profile   
     ##Set global environment configuration
[root@localhost mysql-5.7.20]# source /etc/profile    
    ##Restart profile

6. Initialize mysql database

[root@localhost mysql-5.7.20]# cd /usr/local/mysql/
[root@localhost mysql]# bin/mysqld \
> --initialize-insecure \        ##Initialization
> --user=mysql \                 ##user
> --basedir=/usr/local/mysql \      ##Installation directory
> --datadir=/usr/local/mysql/data   ##Database data file directory

7. Copy mysql service configuration file to / usr/lib/systemd/system / for system CTL management

[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 
    ##S ystemctl management
[root@localhost mysql]# systemctl enable mysqld   ##Power on self start
[root@localhost mysql]# systemctl start mysqld.service     ##Open database
[root@localhost mysql]# netstat -ntap | grep 3306              ##View the opening status of MySQL port number
tcp6  0  0 :::3306    :::*       LISTEN   59464/mysqld   

8. Set mysql password

[root@localhost mysql]# mysqladmin -u root -p password
Enter password:               ##Enter
New password:                ##Enter new password
Confirm new password:       ##Confirm password

Step 5: compile and install PHP

1. Install environment dependency package

[root@localhost mysql]# yum install -y \
> libjpeg \                              ##jpeg image format and development package
> libjpeg-devel \
> libpng libpng-devel \                 ##png picture and development package
> freetype freetype-devel \             ##Font library
> libxml2 \                             ##xml file library
> libxml2-devel \
> zlib zlib-devel \                     ##Compression library 
> curl curl-devel \                     ##Support data file download tool
> openssl openssl-devel                 ##Secure access connection

2. Decompress the source package

[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                        
##Installation path
--with-mysql-sock=/usr/local/mysql/mysql.sock   
##Connecting files to build communication bridge
--with-mysqli                                    
##Client support library
--with-zlib                                         
##Compression module
--with-curl                                        
##Support upload and download function
--with-gd                                          
##gd image support image processing library
--with-jpeg-dir                                  
##jpeg image support image processing library
--with-png-dir                                   
##png image support image processing library
--with-freetype-dir                            
##Font Format Library
--with-openssl                                  
##Secure access connection
--enable-fpm                                    
##fpm supports dynamic request module
--enable-mbstring                            
##Multi byte string support
--enable-xml                                    
##xml file
--enable-session                             
##Session support session
--enable-ftp                                     
##ftp services
--enable-pdo                                   
##Drive connection management
--enable-tokenizer                          
##PHP function library
--enable-zip                                    
##zip compression

4. Compilation and installation

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

5. Configure the core configuration file

(php.ini core configuration file, php-fpm.conf process service configuration file, www.conf extension configuration file)

[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini   
##Copy to the installation directory lib Library
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini  
##Configure core profile

mysqli.default_socket = /usr/local/mysql/mysql.sock     
##Default connection file
date.timezone = Asia/Shanghai                          
##time zone

[root@localhost php-7.1.10]# /usr/local/php/bin/php -m   
##Verify installed modules

6. Configure and optimize FPM module

[root@localhost php-7.1.10]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf   ##Optimize replication of default process service profiles
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf   ##Optimize replication extension profiles
[root@localhost php-fpm.d]# cd /usr/local/php/etc/  
[root@localhost etc]# vim php-fpm.conf      ##Start fpm.pid process
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     ##View port information
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/   ##Create PHP command soft link to system command
[root@localhost etc]# ps aux | grep -c "php-fpm"                    ##View PHP FPM module process information           
4

7. Configure Nginx to support PHP functions

[root@localhost etc]# vim /usr/local/nginx/conf/nginx.conf    ##Configure nginx profile
    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;   ##Site path
        include        fastcgi_params;
    }       
[root@localhost etc]# vim /usr/local/nginx/html/index.php               ##Testing php web pages
<?php
phpinfo();
?>

[root@localhost etc]# nginx -s stop
##Stop nginx service
[root@localhost etc]# nginx 
##Start nginx service

8. Test web page

9. Enter database to create bbs database and set administrator and password

[root@localhost etc]# mysql -u root -p
Enter password:      ##Enter the database with the password of abc23
mysql> CREATE DATABASE BBS;   ##Create bbs database
Query OK, 1 row affected (0.00 sec)

mysql> GRANT all ON bbs.* TO 'bbsusers'@'%' IDENTIFIED BY 'admin123';  
##bbsuser is the administrator and sets the password
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;         ##Refresh database
Query OK, 0 rows affected (0.00 sec)

mysql> quit       ##Sign out

[root@localhost etc]# vim /usr/local/nginx/html/index.php   ##Test database connection status
<?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     ##Restart service

10. Test the web page again

Step 6: install the Discuz forum package

1. Decompress the forum package to / opt, and copy the contents of the directory to the bbs site

[root@localhost etc]# cd /abc                   
[root@localhost abc]# unzip  Discuz_X3.4_SC_UTF8.zip -d /opt    ##Unzip to / 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  Explain.htm
[root@localhost opt]# cd dir_SC_UTF8/          ##Cut into the forum directory
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/     
##Copy everything in the / opt directory to the bbs site directory

2. Access to the site and give rights to program users

[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/          ##Cut into bbs site directory
[root@localhost bbs]# chown -R root:nginx ./config/                   ##Right withdrawing procedure user right withdrawing
[root@localhost bbs]# chown -R root:nginx ./data/                     ##Modify nginx genus group
[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/                            ##Modify all permissions
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/

3. Enter 192.168.235.158/bbs/install/index.php into the Discuz forum wizard

4. Set up the operation environment and conduct a new installation

5. Install database

Data server: 192.168.235.158 (enter IP address of creating database host here)
Database name: bbs
 Database user name: bbsusers (user name can be modified at the command line)
Database password: admin123 (password can be modified at the command line)
Administrator account: admin (default)
Password: 123123 (the password can be set directly on the web page)

Seven, visit the forum and start posting!!!

Tags: Linux Nginx MySQL PHP Database

Posted on Tue, 05 Nov 2019 14:06:38 -0800 by ejames13