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

How to build LNMP Architecture in centos 7 system

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

Share

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

We all know that LAMP platform is the most widely used web server architecture at present, in which "A" corresponds to the Apache of web service software, but now, with the passage of time, more and more enterprises begin to use the dark horse of Nginx, and LNMP or LEMP architecture is favored by more and more operation and maintenance engineers.

If you have nothing to do, just write about the construction of LNMP architecture.

1. Preparatory work:

Centos7 server 1 and system image; install mysql database, refer to blog post: https://blog.51cto.com/14154700/2394026; deploy Nginx website server, refer to blog article: https://blog.51cto.com/14154700/2411362 to prepare PHP software package, network disk extraction address: link: https://pan.baidu.com/s/1PIipn9e494XbJnclSCCgvg extraction code: z2zx

2. After the preparation work is completed, you can start to install the PHP parsing environment:

1. Installation

The dependency packages required for [root@localhost ~] # yum-y install gd libxml2-devel libjpeg-devel libpng-devel # installation are provided in the system image. [root@localhost media] # tar zxf php-5.5.38.tar.gz-C / usr/src # decompress the downloaded php package [root@localhost media] # cd / usr/src/php-5.5.38/ [root@localhost php-5.5.38] #. / configure-- prefix=/usr/local/php5-- with-gd-- with-zlib-- with-mysql=/usr/local/mysql-- with-mysqli=/usr/local/mysql/bin/mysql _ config--with-config-file-path=/usr/local/php5-- enable-mbstring-- enable-fpm--with-jpeg-dir=/usr/lib & & make & & make install# configuration and compilation installation (long process Need to wait patiently)

2. Adjustment after installation:

[root@localhost php-5.5.38] # cp php.ini-production / usr/local/php5/php.ini [root@localhost php-5.5.38] # ln-s / usr/local/php5/bin/* / usr/local/bin/ [root@localhost php-5.5.38] # ln-s / usr/local/php5/sbin/* / usr/local/sbin/

3. Install ZendGuardLoader:

[root@localhost media] # tar zxf zend-loader-php5.5-linux-x86_64_update1.tar.gz-C / usr/src# unpack [root@localhost src] # cd / usr/src/zend-loader-php5.5-linux-x86_64/ [root @ localhost zend-loader-php5.5-linux-x86_64] # cp ZendGuardLoader.so / usr/local/php5/lib/php/ [root@localhost zend-loader-php5.5-linux-x86_64] # cd [root @ localhost ~] # vim / usr/local/php5/php.ini # write the following two lines [PHP] zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.sozend_loader.enable=1 under [PHP] in the configuration file.

4. Configure Nginx to support PHP environment

There are two ways to enable Nginx to parse PHP pages: first, to act as an intermediary, transferring web requests to access PHP pages to other servers (LAMP) for processing; and second, to invoke the native PHP environment by using PHP's FPM module.

① enables the php-pfm process (which listens on port 9000 by default):

[root@localhost ~] # cd / usr/local/php5/etc/ [root@localhost etc] # cp php-fpm.conf.default php-fpm.conf [root@localhost etc] # useradd-M-s / sbin/nologin php [root@localhost etc] # vim php-fpm.conf.. pid = run/php-fpm.pid # confirm the pid file location user = php # Runtime user group = php # Rungroup pm.start_servers = 20 # number of processes opened at startup pm.min_spare_servers = 5 # minimum number of idle processes pm.max_spare_servers = 35 # maximum number of idle processes pm.max_children = 50 # maximum number of child processes

In the above configuration file, the pid configuration item indicates the location of the PID information, corresponding to the actual path: / usr/local/php5/var/run/php-fpm.pid. According to the above configuration, you can modify the Nginx service script to start / stop the php-fpm process automatically when you start / stop the Nginx server.

[root@localhost etc] # vim / etc/init.d/nginx #! / bin/bash# chkconfig:-99 20PROG = "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" PROG_FPM= "/ usr/local/sbin/php-fpm" PIDF_FPM= "/ usr/local/php5/var/run/php-fpm.pid" case "$1" in start) $PROG $PROG_FPM Stop) kill-s QUIT $(cat $PIDF) kill-s QUIT $(cat $PIDF_FPM);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) kill-s HUP $(cat $PIDF_FPM) *) echo "USAGE:$0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost etc] # systemctl daemon-reload # reload the daemon Otherwise, there will be a message [root@localhost etc] # systemctl restart nginx # restart the Nginx service to confirm that the script is correct [root@localhost etc] # netstat-anpt | grep 80 # check whether the Nginx service port is listening on tcp 00 0.0.0.0 Nginx 80 0.0.0.0 LISTEN 64032/nginx: master [root@localhost etc] # netstat-anpt | grep 9000 # check whether the fpm service port is listening on tcp 00 127.0.0.1 LISTEN 64036/php-fpm 9000 0.0.0.0 LISTEN 64036/php-fpm: mast

With the above configuration, once the Nginx service is started or shut down, the php-fpm program starts or closes with it, and there is no need to start or shut down php-fpm.

② configures Nginx to support PHP resolution:

Whether you leave the PHP page to the LAMP server to parse, or call the native php-fpm process for operation, you need to add the location setting in the "server {}" configuration section to specify which action to take when visiting the php page.

The configuration items for both methods can be found at the end of the configuration file. Copy it to the appropriate location and make changes available.

For the first method, you can not perform the configuration of the php-fpm above (transferred to another web server for processing, using the configuration statement in the following format):

For example, it is handed over to the LAMP server with IP address 192.168.1.3, so that Nginx is responsible for static pages and LAMP is responsible for the separation of dynamic pages:

[root@localhost etc] # vim / usr/local/nginx/conf/nginx.conf. # omit part of the content server {.location ~\ .php$ {# access to the configuration segment proxy_pass http://192.168.1.3:80; of the .php page # listener address of apache server}. # omit part of the content}

I use the second method (calling the native php-fpm process) here, and the configuration is as follows:

[root@localhost etc] # vim / usr/local/nginx/conf/nginx.conf. # omit some content server {.location ~\ .php$ {root / var/www/test1 # set the php web page root directory fastcgi_pass 127.0.0.1 fastcgi_index index.php; include fastcgi.conf; 9000; copy the template, you need to change the line. }. # omit some content}

③, write a php script file, test whether you can successfully access the PHP page, and connect to the database:

1) write a php script:

[root@localhost etc] # vim / var/www/test1/test.php

2) client access:

At this point, the LNMP environment has been built. Deploy a web application on the way, collect a community forum on the Internet, and talk about it (the program code is in the package linked to the network disk at the beginning of the blog post):

1. Deployment program code:

[root@localhost media] # cp Discuz_X3.3_SC_UTF8.zip / usr/src [root@localhost media] # cd / usr/src/ [root@localhost src] # unzip Discuz_X3.3_SC_UTF8.zip # unpack [root@localhost src] # mv upload/ / var/www/test1/bbs # move the extracted files to the root directory of the website [root@localhost src] # chown-R php:php / var/ Www/test1/bbs/ # adjust permissions

2. Create a database:

[root@localhost src] # mysql-uroot-pEnter password: # verify database user password mysql > create database bbs; # create dedicated database Query OK, 1 row affected (0.00 sec) mysql > grant all on bbs.* to runbbs@localhost identified by 'pwd@123'; # authorized user is runbbsQuery OK, 0 rows affected (0.01 sec)

3. Install the web application:

When the ① client accesses www.test1.com/bbs, it will open Discuz! Installer of:

The pages under the ② must be writable. If there is a red "X" sign, there is something wrong with the permissions of the directory. Check the directory permissions of the source files.

③ chooses a fresh installation:

④ sets database-related configuration and application backend management password:

Visit www.test1.com/bbs/admin.php and log in to the background to have a look:

So far ok

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