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

Theory and practice of LNMP deployment and Application

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

LNMP deployment and Application LNMP Architecture interpretation

LNMP platform is the combination of Linux, Ngnix, MySQL and PHP.

Architecture, which requires Linux server, MySQL database, PHP parsing environment

MySQL installation configuration

In order to be consistent with the Nginx and PHP environment, we choose to install the MySQL component by compiling the source code here.

Method of MySQL deployment

Compile and install MySQL

Optimization and adjustment

Initialize the database

Start the mysql service and set the password for the root database account

There are two ways to configure static and dynamic separation of web pages and parse PHP

Use the FPM module of PHP to transfer the Web request to access the PHP page to the Apache server for processing

Newer versions of PHP already have their own FPM module, which is used to parse the real PHP.

Example to manage and optimize the efficiency of analysis

FastCGIl separates Http Server from dynamic scripting languages

Nginx specializes in handling static requests and forwarding dynamic requests

PHP FPM specializes in parsing PHP dynamic requests

Single-server LNMP architecture usually uses FPM to parse PHP

PHP compilation and installation steps

Compile and install PHP

Add "--enable-fpm" when compiling options to enable this module

The adjustment after installation is mainly the establishment of the configuration file and the path optimization of the corresponding command tools, the installation of ZendGuardLoader (to improve the efficiency of PHP parsing), and the loading configuration.

Call the native php-fpm process configuration method

Establish FPM configuration file php-fpm.conf, and modify configuration options, such as PID file running users, number of service processes, etc.

Start the php-fpm process

The server {} configuration section in the configuration file of Nginx configures the web page request of PHP to be processed by the FPM module

The Server {} configuration section in the configuration file of Nginx configures the web page request of PHP to be processed by the FPM module

[root@localhost ~] # vim / usr/local/nginx/conf/nginx.conf

Server {

.

Location ~ .php ${

Root

/ var/www/kgc

Fastcgi pass 127.0.0.1 9000; / / FPM port number: 9000

Fastcgi index index.php

Include

Fastcgi.conf

.

Discuz

A set of general community forum software launched by Kangsheng Chuangxiang (Beijing) Technology Co., Ltd.

Tong, since its introduction in June 2001, has been the theory with the highest maturity and the highest coverage in the world.

The altar software system-

PHPWind

PHPWind (PW for short) is a forum program based on PHP and MySQL.

Is one of the most popular universal forum programs in China. The predecessor of PHPWind is

Ofstar, released in 2004, PHPWind by Hangzhou Detian Information Technology Co., Ltd.

Company development, software comprehensive open source free of charge

WordPress

A blog platform developed in PHP language that allows users to support PHP and PHP

Set up your own blog on the server of the MySQL database. You can also put

WordPress is used as a content management system (CMS).

WordPress is a free open source project under the GNU General Public license

Authorized release

SKYUC

A VOD video-on-demand system developed by Sky Network for many years, with perfect support

QVOD, Webplayer9 and other streaming media software

LNMP architecture practice 1. Remotely mount the compressed software package required by LNMP to the local

[root@localhost ~] # mkdir / abc / / create mount point

[root@localhost ~] # mount.cifs / / 192.168.100.10/LAMP-C7 / mnt / / remotely mount the required software packages to the local / mnt directory

II. Compile and install Nginx

1. Decompress the source code package to / opt directory

[root@localhost ~] # cd / mnt / / switch to the mount point directory

[root@localhost mnt] # ls

Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz

Mysql-boost-5.7.20.tar.gz php-7.1.20.tar.gz

[root@localhost mnt] # tar zxvf nginx-1.12.2.tar.gz-C / opt / / decompress the Nginx source code package to / opt

[root@localhost mnt] # cd / opt/ switch to the decompressed directory

[root@localhost opt] # ls

Nginx-1.12.2 rh

2. Install the environment package needed to compile Nginx

[root@localhost opt] # yum-y install\

Gcc\ / / c language

Gcc-c++\ / / C++ language

Pcre-devel\ / / pcre language tool

Zlib-devel / / function libraries for data compression

3. Create the program user nginx and compile Nginx

[root@localhost opt] # useradd-M-s / sbin/nologin nginx / / create program user, secure non-login status

[root@localhost opt] # id nginx

Uid=1001 (nginx) gid=1001 (nginx) group = 1001 (nginx)

[root@localhost opt] # cd nginx-1.12.0/ switch to the nginx directory

[root@localhost nginx-1.12.0] #. / configure\ / / configure nginx

-- prefix=/usr/local/nginx\ / / installation path

-- user=nginx\ / / user name

-- group=nginx\ / / user group

-- with-http_stub_status_module / / status statistics module

4. Compile and install

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

5. Path optimization

[root@localhost nginx] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/

/ / create a soft connection to let the system recognize the nginx startup script

[root@localhost nginx] # nginx-t / / check the syntax of the configuration file

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 / / enable ngnix

[root@localhost nginx] # netstat-ntap | grep 80 / / View port. Nginx has been enabled.

Tcp 0 0 0.0.0 0 master 80 0.0.0 0. 0. 0 master

[root@localhost nginx] # systemctl stop firewalld.service / / turn off the firewall

[root@localhost nginx] # setenforce 0

[root@localhost nginx] # nginx / / enable nginx service

[root@localhost nginx] # cd / etc/init.d/ switch to the startup configuration file directory [root@localhost init.d] # lsfunctions netconsole network README [root@localhost init.d] # vim nginx / / Edit startup script file #! / bin/bash # chkconfig:-99 20 / / comment Information # description: Nginx Service Control Script PROG= "/ usr/local/nginx/sbin/nginx" / / set the variable to the nginx command file PIDF= "/ usr/local/nginx/logs/nginx.pid" / / set the variable PID file process number is 5346 case "$1" in start) $PROG / / start the service ; stop) kill-s QUIT $(cat $PIDF) / / disable the service;; restart) / / restart the service $0 stop $0 start Reload) / / overloaded service kill-s HUP $(cat $PIDF) *) / / incorrectly enter the prompt echo "Usage: $0 {start | stop | restart | reload}" exit 1 esac exit 0 [root@localhost init.d] # chmod + x / etc/init.d/nginx / / Grant startup script execution permission [root@localhost init.d ] # chkconfig-- add nginx / / add to service Manager [root@localhost init.d] # service nginx stop / / stop nginx service using service [root@localhost init.d] # service nginx start / / start nginx service using service [root@localhost ~] # vim / lib/systemd/system/nginx.service / / create configuration file [Unit] Description=nginx / / describe After=network.target / / describe the service type [Service] Type=forking / / background running form PIDFile=/usr/local/nginx/logs/nginx.pid / / PID file location ExecStart=/usr/local / nginx/sbin/nginx / / start the service ExecReload=/usr/bin/kill-s HUP $MAINPID / / configure ExecStop=/usr/bin/kill-s QUIT $MAINPID according to PID overload / / terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root@localhost ~] # chmod 754 / lib/systemd/system/nginx.service / / set execution permissions [root@localhost ~] # systemctl stop nginx.service / / off according to PID Close nginx [root@localhost] # systemctl start nginx.service / / Open nginx 3. Install MySQL

1. Install the environment components

[root@localhost ~] # yum install-y\ / / install environment components

Ncurses\

Ncurese-devel\ / / the library that controls the terminal screen display

Bison\ / / parsing tool

Cmake / / cmake tool

[root@localhost ~] # useradd-s / sbin/nologin mysql / / create program user

2. Decompress the source code package to / opt directory

[root@localhost ~] # cd / mnt [root@localhost mnt] # tar zxvf mysql-boost-5.7.20.tar.gz-C / opt # # decompress the source code package to / opt [root@localhost mnt] # cd / opt [root@localhost opt] # lsmysql-5.7.20 nginx-1.12.2 rh

3. Cmake configuration

[root@localhost opt] # cd mysql-5.7.20/ switch to [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 sock file connection database file-DSYSCONFDIR=/etc\ under the MySQL directory / / configuration file directory-DSYSTEMD_PID_DIR=/usr/local/mysql\ / / PID file directory-DDEFAULT_CHARSET=utf8\ / / specified character set-DDEFAULT_COLLATION=utf8_general_ci\ / / specified character set default-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 parameters

4. Compilation and installation

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

5. Modify the configuration file of Mysql

[root@localhost mysql-5.7.20] # chown-R mysql:mysql / usr/local/mysql/ Database directory to adjust permissions [root@localhost mysql-5.7.20] # vim / etc/my.cnf / / adjust configuration file [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] / / Server user = mysql/ / user basedir = / usr/local/mysql/ / set mysql installation directory datadir = / usr/local/mysql/data / / set the data storage directory of the 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 service 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] # echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' > > / etc/profile / / write MySQL commands to the 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 configuration file

6. Initialize 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

7. Copy the MySQL service configuration file to / usr/lib/systemd/system/ for easy management using systemctl

[root@localhost mysql] # cp usr/lib/systemd/system/mysqld.service / usr/lib/systemd/system/ facilitate 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

8. Set the mysql password

[root@localhost mysql] # mysqladmin-u root-p passwordEnter password: New password: / / New password Confirm new password: / / confirm password 4. Compile and install PHP

1. Install the environment dependency package

[root@localhost mysql] # yum install-y\ > libjpeg\ / / jpeg image format and development kit > libjpeg-devel\ > libpng libpng-devel\ / / png picture and development kit > 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 code package to / opt directory

[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 parameters

[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 # # connection file to build communication bridge-- with-mysqli / / client support Library-- with-zlib / / Compression-- with-curl / / support upload and download function-- with-gd / / gd Image support Image processing Library-- with-jpeg-dir / / jpeg--with-png-dir / / png--with-freetype-dir / / Font-with-openssl / / secure access connection-enable-fpm / / fpm support Dynamic request module-enable-mbstring / / supports multi-byte strings-- enable-xml / / xml files-- enable-session / / session support sessions-- enable-ftp / / ftp services-- Enable-pdo / / driver connection management-- enable-tokenizer / / PHP comes with a function-- enable-zip / / zip compressed package

4. Compilation and installation

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

5. Configure the core configuration file

(php.ini core profile, php-fpm.conf process service profile, www. Conf extension profile)

[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 [root@localhost php-7.1.10] # / usr/local/php/bin/php-m / / verify the installed module

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 / / 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 for the system to identify [root@localhost etc] # ps aux | grep-c "php-fpm" 4

7. Configure Nginx to support PHP function

[root@localhost etc] # vim / usr/local/nginx/conf/nginx.conf # # configure the nginx configuration file location ~\ .php$ {root html; fastcgi_pass 127.0.0.1 location 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 web page [root@localhost etc] # nginx-s stop / / stop nginx service [root@localhost etc] # nginx/ / start nginx service

8. Use the testing machine to test the web page

Enter http://192.168.35.134/index.php in the browser

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

[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 'bbsusers'@'%' IDENTIFIED BY' admin123' / / 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 '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 / / exit [root@localhost etc] # vim / usr/local/nginx/html/index.php / / Test database connection status [root@localhost etc] # systemctl restart nginx.service / / restart service 5. Install Discuz Forum

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

[root@localhost etc] # cd / mnt [root@localhost mnt] # unzip Discuz_X3.4_SC_UTF8.zip-d / opt / / decompress to / opt [root@localhost mnt] # cd / opt [root@localhost opt] # lsdir_SC_UTF8 mysql-5.7.20 nginx-1.12.2 php-7.1.10 rh description .htm [root@localhost opt] # cd dir_SC_UTF8/ / / enter the forum directory [root@localhost dir_SC_UTF8] # cp-r upload/ / usr/local/nginx/html/bbs/ copy the contents of / opt directory to the bbs directory of the html site

2. Enter the site and give rights to users of the program

[root@localhost dir_SC_UTF8] # cd / usr/local/nginx/html/bbs/ enter the bbs site directory [root@localhost bbs] # chown-R root:nginx. / config/ subscriber rights [root@localhost bbs] # chown-R root:nginx. / data/ modify nginx 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 the 192.168.131.129/bbs/install/index.php site in the browser and enter the Discuz Forum installation wizard

4. The operating environment is a new installation.

5. Install the database

6. Create successfully and visit the forum

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