Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Using LNMP architecture to build Discuz instance

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Using LNMP architecture to build Discuz instance

LNMP represents the web server architecture of Nginx+MySQL+PHP under the Linux system.

Linux is the general name of a kind of Unix computer operating system, and it is the most popular free operating system. Representative versions are: debian, centos, ubuntu, fedora, gentoo and so on.

Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.

Mysql is a small relational database management system.

PHP is a scripting language that embeds HTML documents executed on the server side.

These four kinds of software are all free and open source software, which are combined into a free, efficient and scalable website service system.

The general steps of this experiment are as follows:

​ install nginx → install mysql database → install php tools → set up Discuz forum

Install the nginx service

The software packages needed for this experiment will be remotely mounted in advance.

[root@localhost ~] # mount.cifs / / 192.168.10.171/rpm / mntPassword for root@//192.168.10.171/rpm: [root@localhost ~] # df-hwen parts system capacity used available mount point / dev/sda2 20G 13G 7.9G 61% / devtmpfs 7.8G 0 7.8G 0% / devtmpfs 7.8G 0 7.8G 0% / dev/shmtmpfs 7.8G 9.0M 7.8G 1% / runtmpfs 7.8G 0 7.8G 0% / sys/fs/cgroup/dev/sda5 10G 53M 10G 1% / home/dev/sda1 6.0G 174M 5.9G 3% / boottmpfs 1.6G 24K 1.6G 1% / run/user/0/dev/sr0 4.3G 4.3G 0% / run/media/root/CentOS 7 x86_64//192.168.10.171/rpm 288G 74G 215G 26% / mnt / / required for experiment

Extract and install the environment package

[root@localhost ~] # cd / mnt [root@localhost mnt] # tar zxf nginx-1.12.0.tar.gz-C / opt/ decompression package [root@localhost mnt] # useradd-M-s / sbin/nologin nginx / / create program users, no home directory [root@localhost mnt] # yum-y install\ gcc\ gcc-c++\ pcre-devel\ zlib-devel\ expat-devel\ pcre

Among them

Gcc, gcc-c++: underlying C language support package

Pcre, pcre-devel: development and Compiler of pcre language

Zlib-devel: supports compression

Expat-devel: enables newly created websites to parse files in xml format

Compilation and installation

When you are finished, move to the folder

[root@localhost mnt] # cd / opt/nginx-1.12.0/ [root@localhost nginx-1.12.0] #. / configure\ / configuration-- user=nginx\-- group=nginx\-- prefix=/usr/local/nginx\-- with-http_stub_status_ module [root @ localhost nginx-1.12.0] # make & & make install / / manually compile & install [root@localhost nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/// is convenient for the computer to recognize

Among them

-- user=nginx: specify the user to control the service

-- group=nginx: specifies the group that controls the service

-- prefix=/usr/local/nginx: specify the installation path

-- with-http_stub_status_module: status statistics module

Set up a configuration file to facilitate Systemctl & Service control (just choose one of the two)

Systemctl

[root@localhost nginx-1.12.0] # vim / lib/systemd/system/nginx.service# manually enter the following: [Unit] Description=nginxAfter= network.target [service] Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/bin/kill-s HUP $MAINPIDExecStop=/usr/bin/kill-s QUIT $MAINPIDPrivateTmp= true [install] WantedBy=multi-user.targetwq save exit [root@localhost nginx-1.12.0] # cd / service [ Root@localhost system] # chmod 754 nginx.service / / Grant control rights

Service

[root@localhost nginx-1.12.0] # vim / etc/init.d/nginx# enter the following: #! / bin/bashwenjian= "/ usr/local/nginx/sbin/nginx" pid= "/ usr/local/nginx/logs/nginx.pid" case $1 instart) $wenjian;; stop) kill-s QUIT $(cat $pid);; restart) $0 stop $0 start;;reload) kill-s HUP $(cat $pid);; *) echo "Please,try again" exit 1 Esacexit 0wq save exit [root@localhost nginx-1.12.0] # cd / etc/init.d/ [root@localhost init.d] # chmod 754 nginx / / give control permission

Start the nginx service and verify

[root@localhost init.d] # systemctl stop firewalld.service / / disable firewall [root@localhost init.d] # setenforce 0 / disable enhanced security feature [root@localhost init.d] # systemctl start nginx.service / / enable nginx service [root@localhost init.d] # systemctl enable nginx.service / / set nginx service to boot automatically [root@localhost init.d] # netstat-atnp | Egrep "(80 | nginx)" / / check whether the service starts tcp 00 0.0.0.0 tcp 80 0.0.0.0 LISTEN 1075/nginx: master II. Install the MySQL database

Extract and install the environment package

[root@localhost init.d] # cd / mnt [root@localhost mnt] # yum-y install\ cmake\ ncurses\ ncurses-devel\ bison\ expect [root@localhost mnt] # tar zxf / mnt/mysql-boost-5.7.20.tar.gz-C / opt [root@localhost mnt] # useradd-s / sbin/nologin mysql / / create program user

Among them

Cmake: compiler

Ncurses, ncurses-devel: customer character terminal processing tools

Bison: parser

Compilation and installation

[root@localhost mnt] # cd / opt/mysql-5.7.20 [root@localhost mysql-5.7.20] # 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 [root@localhost mysql-5.7.20] # make & & make install / / compile & install

Among them

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql: specify the installation path

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock: defines the path to the sock file

-DSYSCONFDIR=/etc/: configuration file directory

-DSYSTEMD_PID_DIR=/usr/local/mysql: PID file path

-DDEFAULT_CHARSET=utf8: specifies the character set (Chinese is supported)

-DDEFAULT_COLLATION=utf8_general_ci: specifies the default character set

-DWITH_INNOBASE_STORAGE_ENGINE=1: storage engine

-DMYSQL_DATADIR=/usr/local/mysql/data: database data file directory

-DWITH_BOOST=boost: underlying runtime

-DWITH_SYSTEMD=1: master-slave parameter

Configure MySQL

[root@localhost mysql-5.7.20] # chown-R mysql:mysql / usr/local/mysql/ # # adjust permissions in database directory [root@localhost mysql-5.7.20] # vim / etc/my.cnf # # adjust configuration file [client] # # client port = 3306default-character-set=utf8socket = / usr/local/mysql/mysql.sock [mysql] # # client port = 3306default-character-set=utf8socket = / usr/local/mysql/mysql.sock [mysqld] # # Server user = mysql # # user basedir = / usr/local/mysql # # set the installation directory of mysql datadir = / usr/local/mysql/data # # set the data storage of mysql database Port = 3306 # # set port 3306 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 parameter 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] # chown mysql:mysql / etc/my.cnf # # write MySQL to the local environment configuration [root@localhost mysql-5.7.20] # echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' > > / etc/profile## to the configuration file mysql master group [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 configuration file

Initialize the database and set the initial password for the 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 [root@localhost mysql] # cp usr/ Lib/systemd/system/mysqld.service / usr/lib/systemd/system/ # # facilitates systemctl management [root@localhost mysql] # systemctl enable mysqld # # Boot self-boot [root@localhost mysql] # systemctl start mysqld.service # # Open database [root@localhost mysql] # netstat-ntap | grep 3306 # # View MySQL port number enabled tcp6 0:: 3306: * LISTEN 59464/mysqld [ Root@localhost mysql] # mysqladmin-u root-p passwordEnter password: # # Space New password: # # New password Confirm new password: # # confirm password 3. Install PHP tools

Unpack & install the environment package

[root@localhost mysql] # cd / mnt # # switch to mount point [root@localhost mnt] # tar jxvf php-7.1.10.tar.bz2-C / opt # # decompress the source code package to / opt [root@localhost mnt] # yum install-y\ > libjpeg\ > libjpeg-devel\ > libpng libpng-devel\ > freetype freetype-devel\ > libxml2\ > libxml2-devel\ > zlib zlib-devel\ > curl curl-devel\ > openssl openssl-devel

Among them

Libjpeg, ibjpeg-devel: support jpeg image format and development kit

Libpng, libpng-devel: support png format and corresponding development package

Freetype, freetype-devel: font library

Libxml2, libxml2-devel: xml File Library

Zlib, zlib-devel: compression library

Curl, curl-devel: supports data file download tools

Openssl openssl-devel: secure access connection

Compilation and installation

[root@localhost mnt] # cd / opt/php-7.1.10/ [root@localhost php-7.1.10] #. / configure\-- prefix=/usr/local/php\-- with-mysql-sock=/usr/local/mysql/mysql.sock\-- with-zlib\-- with-mysqli\-- 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 [root@localhost php-7.1.10] # make & & make install / / compile & install

Among them

-- prefix=/usr/local/php: specify the installation path

-- with-mysql-sock=/usr/local/mysql/mysql.sock: specify the path to the sock file

-- with-zlib: supports compression

-- with-mysqli: supports uploading and downloading

-- with-curl: client support library

-- with-gd: gd graphical interface

-- with-jpeg-dir: supports jpeg

-- with-png-dir: supports png

-- with-freetype-dir: font

-- with-openssl: secure access connection

-- enable-fpm: open the fpm dynamic resource processing module

-- enable-mbstring: string that supports multi-byte

-- enable-xml: xml files are supported

-- enable-session: session supports sessions

-- enable-ftp: supports ftp services

-- enable-pdo: driver connection management

-- enable-tokenizer: php has its own function library

-- enable-zip: supports zip compression format

Modify php core configuration file

There are three ​: php.ini core profile, php-fpm.conf process service profile, and www.conf extension profile.

Php.ini

[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 the core configuration file mysqli.default_socket = / usr/local/mysql/mysql.sock # # default connection file date.timezone = Asia/Shanghai # # time

Php-fpm.conf 、 www.conf

[root@localhost php-7.1.10] # cd / usr/local/php/etc/ [root@localhost etc] # cp php-fpm.conf.default php-fpm.conf # # optimized replication default process service profile [root@localhost etc] # cd / usr/local/php/etc/php-fpm.d/ [root@localhost php-fpm.d] # cp www.conf.default www.conf # # optimized replication extension profile [root@localhost Php-fpm.d] # cd / usr/local/php/etc/ [root@localhost etc] # vim php-fpm.conf # # start the 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 00 127.0.0.1 : 9000 0.0.0.0 root@localhost etc * LISTEN 69104/php-fpm: mast [root@localhost etc] # ln-s / usr/local/php/bin/* / usr/local/bin/ # # create a soft connection to facilitate system identification

Let nginx support PHP function

[root@localhost etc] # vim / usr/local/nginx/conf/nginx.conf # # configure the nginx configuration file to uncomment the following location ~\ .php$ {root html; fastcgi_pass 127.0.0.1 usr/local/nginx/conf/nginx.conf 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 # # Test php pages to add the following content

Establish bbs database

[root@localhost etc] # mysql-u root-pEnter password: # # enter the database with the password of abc23mysql > CREATE DATABASE BBS; # # create bbs database Query OK, 1 row affected (0.00 sec) mysql > GRANT all ON bbs.* TO 'zhy'@'%' IDENTIFIED BY' zhy94666' # # upgrade database user bbsuser as administrator and set password Query OK, 0 rows affected, 1 warning (0.00 sec) mysql > GRANT all ON bbs.* TO 'zhy'@'localhost' IDENTIFIED BY' zhy94666';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 # # exit [root@localhost etc] # systemctl restart nginx.service # # restart service 4. Install Discuz forum

Decompression

[root@localhost etc] # cd / mnt/ [root@localhost mnt] # unzip Discuz_X3.4_SC_UTF8.zip-d / tmp [root@localhost mnt] # cd / tmp/dir_SC_UTF8/ [root @ localhost dir_SC_UTF8] # cp-r upload/ / usr/local/nginx/html/bbs/

Raise the right of a document

[root@localhost dir_SC_UTF8] # cd / usr/local/nginx/html/bbs/ [root@localhost bbs] # chown-R root:nginx. / config/ [root@localhost bbs] # chown-R root:nginx. / data/ [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/

Visit

Enter 192.168.116.171/bbs/install/index.php in the browser to proceed with the installation process.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report