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

LNMP architecture deployment-you can do the following

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

Share

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

LAMP differs from LNMP in:

Advantages of the 1.LNMP approach:

It takes up less resources, and Nginx is relatively simple to configure. Fast-cgi is used to dynamically parse PHP scripts. Disadvantages: the load capacity of php-fpm components is limited, when the traffic is large, the php-fpm process is easy to freeze, prone to 502 bad gateway errors.

two。 The design based on LAMP architecture has the characteristics of low cost, flexible deployment, rapid development, security and stability, and is an excellent combination of Web network applications and environment.

If the server configuration is relatively low for personal websites, LNMP architecture is of course the first choice. Of course, when there is a lot of traffic. It is also a good choice to combine Apache with Nginx.

In 3.LNMP architecture, php starts the service php-fpm, while php in LAMP only exists as a module of Apache.

Nginx will pass the user's dynamic request to the php service for processing, and the php service will interact with the database. Users' static requests will be processed directly by Nginx, and Nginx handles static requests much faster than Apache, so there is little difference between apache and Nginx in dynamic request processing, but if it is static processing, you will find that Nginx is faster than apache, and Nginx can withstand more concurrency than apache, and can withstand tens of thousands of concurrent connections, so larger websites will use Nginx as the web server.

The difference between Apache+php and nginx+php:

1. Apache generally starts php as a module of its own, while nginx forwards http request variables to the php process, that is, php independent process, to communicate with Nginx, which is called fast-cgi operation mode, so php compiled by apache cannot be used in nginx.

Brief description:

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

Details

Linux is a kind of Unix computer operating system, which is the most popular free operating system at present. Nginx is a high-performance HTTP and reverse proxy server, lightweight, with high concurrent processing power Mysql is a small relational database management system. PHP is a scripting language that embeds HTML documents executed on the server side.

The experiment begins.

1. Use remote sharing on Linux to obtain the source code package from Windows sharing

[root@localhost ~] # smbclient-L / / 192.168.235.1 / # # remote share 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 Install nginx

2. Decompression

[root@localhost ~] # cd / abc # # switch to the mount point directory [root@localhost abc] # lsDiscuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gzmysql-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 # # decompress the Nginx source code package to [root@localhost abc] # cd under / opt / opt/ # # switch to [root@localhost opt] # lsnginx-1.12.2 rh under the decompressed directory

3. Install the environment package

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

4. Create program users and configuration file parameters

[root@localhost opt] # useradd-M-s / sbin/nologin nginx # # Creator user Limit its [root@localhost opt] # cd nginx-1.12.2/ # # switch to [root@localhost nginx-1.12.2] #. / configure\ # # configure nginx >-- prefix=/usr/local/nginx\ # # installation path >-- user=nginx\ # # user name >-- group=nginx\ # # user groups >-- with-http_stub_status_module # # access status Statistics Module

5. Compile and install

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

6. Optimize the Nginx service startup script and establish command soft links

[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 problems of the configuration file nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost nginx] # nginx # # Open ngnix [root@localhost nginx] # netstat-ntap | grep 80 # # View port Nginx has enabled tcp 0 0 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 # # enable nginx service

7. Make service management nginx script

[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 the 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) # # reload service kill-s HUP $(cat $PIDF) *) # # incorrect 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 startup script execution permission [root@localhost init.d ] # chkconfig-- add nginx # # add to service Manager [root@localhost init.d] # service nginx stop # # stop the nginx service using service [root@localhost init.d] # service nginx start # # start the nginx service using service

8. Systemctl manages nginx scripts

[root@localhost ~] # vim / lib/systemd/system/nginx.service # # create a profile [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 to terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root@localhost ~] # chmod according to PID 754 / lib/systemd/system/nginx.service # # set execution permission [root@localhost ~] # systemctl stop nginx.service # # close nginx [root@localhost ~] # systemctl start nginx.service # # enable 2. Install MySQL

9. Install the environment components

[root@localhost ~] # yum install-y\ # installation Environment components > ncurses\ > ncurese-devel\ # # Control Terminal screen display Library > bison\ # # Syntax parsing tool > cmake # # cmake tool [root@localhost ~] # useradd-s / sbin/nologin mysql # # Creator user

10. Decompression

[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] # lsmysql-5.7.20 nginx-1.12.2 rh

11. Configure server parameters

[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 the sock file connection database file-DSYSCONFDIR=/etc\ # # configuration file directory-DSYSTEMD_PID_DIR=/usr/local/mysql\ # # PID file directory-DDEFAULT_CHARSET=utf8\ # # specify character set-DDEFAULT_COLLATION=utf8_general_ci\ # # specify 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

12. Compile, install

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

13. Modify the configuration file of 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 = 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 mysql database data storage directory 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 the global environment configuration [root@localhost mysql-5.7.20] # source / etc/profile # # restart configuration file

14. Initialize the 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

15. 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/ # # stemctl 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

16. Set the mysql password

[root@localhost mysql] # mysqladmin-u root-p passwordEnter password: # # enter New password: # # enter the new password Confirm new password: # # confirm the password 3. Install PHP

17. Install the environment 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

18. Decompression

[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

19. Configure the parameters of 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 # # connection file to build communication bridge-- with-mysqli # # client support Library-- with-zlib # # Compression Module-- with-curl # # supports upload and download-- 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 # # supports multi-byte strings-enable-xml # # xml files-enable-session # # session supports sessions-enable-ftp # # ftp service-- enable-pdo # # driver connection management-- enable-tokenizer # # PHP comes with a function library-- enable-zip # # zip compression feature

20. Compile and install

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

21. Configure the core profile

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

22. Configure and optimize the 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 ln 9000 0.0.0.0 root@localhost etc * LISTEN 69371/php-fpm: mast [root@localhost etc] # ln-s / usr/local/php/bin/* / usr/local/bin/ # # create a PHP command soft link to the system command [root@localhost etc] # ps aux | grep-c "php-fpm" # # View php-fpm module process information 4

23. Configure Nginx to support PHP function

[root@localhost etc] # vim / usr/local/nginx/conf/nginx.conf # # configure nginx configuration file 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 web page [root@localhost etc] # nginx-s stop## stop nginx service [root@localhost etc] # nginx # # start nginx service

24. Use the host to test the web page

25. 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

26. Refresh and test the web page again

At this point, the deployment of LNMP architecture is complete!

Install Discuz forums

1. Unzip 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 # # extract to / opt [root@localhost abc] # 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/ # # cut into the forum directory [root@localhost dir_SC_UTF8] # cp-r upload/ / usr/local/nginx/html/bbs/ # # copy all the contents in the / opt directory to the bbs site directory

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

[root@localhost dir_SC_UTF8] # cd / usr/local/nginx/html/bbs/ # # cut into 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.235.158/bbs/install/index.php site in the browser and enter the Discuz Forum installation wizard

4. New installation forum

5. Install the database and enter the information

Data server: 192.168.235.158 (enter the IP to create the database host here) Database name: bbs Database user name: bbsusers (user name can be changed on the command line) Database password: admin123 (password can be changed on the command line) Administrator account: admin (this account is the default) password: 123123 (password can be set directly on the web page)

6. Visit 192.168.235.158/bbs/index.php to enter the management interface

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