Based on centos 7 architecture to build LNMP

We all know that when the LAMP platform the most widely used web server architecture, where the "A" corresponds to the Apache web server software, but now as time goes on, more and more companies start using Nginx this horse dark horse, LNMP or LEMP architecture also received an increasing number of operation and maintenance siege lion's favor.

Nothing else to write about architecture LNMP build it!

First, the preparatory work:

Second, the preparatory work is complete, you can begin installing PHP parsing environment:

1, the installation

[root@localhost ~]# yum -y install gd libxml2-devel libjpeg-devel libpng-devel     
#安装所需的依赖包,在系统镜像中有提供。
[root@localhost media]# tar zxf php-5.5.38.tar.gz -C /usr/src     #将下载的php包解压
[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
#配置及编译安装(过程较长,需耐心等待)

2, after the installation and adjustment:

[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, installation ZendGuardLoader:

[root@localhost media]# tar zxf zend-loader-php5.5-linux-x86_64_update1.tar.gz -C /usr/src
#解包
[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            #在配置文件的 [ PHP ]下写入下面两行
[PHP]
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
             .......................

4, Nginx configuration to support PHP environment

To make Nginx can parse PHP pages, there are two ways to choose: first, acts as an intermediary, will visit the web PHP page request to the other server (LAMP) to deal with; secondly, through the use of FPM PHP module to call native PHP environment.

① Enable php-pfm process (the process default listening port 9000):

[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            #确认pid文件位置
user = php                            #运行用户
group = php                         #运行组
pm.start_servers = 20                    #启动时开启的进程数
pm.min_spare_servers = 5            #最少空闲进程数
pm.max_spare_servers = 35         #最多空闲进程数
pm.max_children = 50                   #最大子进程数

Storage location in the above configuration file, pid configuration items noted PID information, corresponding to the actual path is: /usr/local/php5/var/run/php-fpm.pidAccording to the above configuration, you can modify Nginx service scripts to start / stop Nginx server when the php-fpm process also automatic start / stop.

[root@localhost etc]# vim /etc/init.d/nginx 
#!/bin/bash
# chkconfig: - 99 20
PROG="/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 1
esac
exit 0

[root@localhost etc]# systemctl daemon-reload     #重新加载守护进程,否则会有提示信息
[root@localhost etc]# systemctl restart nginx         #重启Nginx服务以确认脚本无误
[root@localhost etc]# netstat -anpt | grep 80    #查看Nginx服务端口是否在监听
tcp        0      0 0.0.0.0:80     0.0.0.0:*         LISTEN      64032/nginx: master 
[root@localhost etc]# netstat -anpt | grep 9000           #查看fpm服务端口是否在监听
tcp        0      0 127.0.0.1:9000     0.0.0.0:*      LISTEN      64036/php-fpm: mast 

After the above configuration, once started or shut down service Nginx, php-fpm program will also start or shut down, restart or shut down no additional php-fpm.

② configure Nginx support PHP parsing:

Whether the PHP page to the LAMP server to resolve, or call php-fpm process of the machine to operate, requires the "server {}" What kind of operation when using the configuration section to add location settings to specify when the visit php page .

Both methods of configuration items can be found at the end of the corresponding template configuration file. Copied to the appropriate position, it can be changed by changing.

For the first method, you may not perform the above configuration php-fpm (treatment transferred to other web servers, using the following format configuration statement):

For example: to the IP address 192.168.1.3 LAMP server processing, enabling Nginx responsible for static pages, dynamic pages LAMP responsible for separation of:

server {
                ...................
location ~ \.php$ {         #访问.php页面的配置段
            proxy_pass   http://192.168.1.3:80;            #apache服务器的监听地址
        }
                        ...................
}

I am here to use the second method (call php-fpm process of the machine), configuration is as follows:

server {
                ...................
location ~ \.php$ {
            root           /var/www/test1;             #设置php网页根目录
            fastcgi_pass   127.0.0.1:9000;          
            fastcgi_index  index.php;
            include        fastcgi.conf;                #复制过来的模板,需要更改该行。
        }   

                        ...................
}

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

1) write php script:

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

<?php
$link=mysqli_connect('localhost','root','123');
if($link) echo "恭喜你,数据库连接成功!!!";
mysqli_close($link);
?>

2) client access:

Based on centos 7 architecture to build LNMP

OKKKKKKKKKKKKKKKKKKKKKKK 了 ................

So far, LNMP environment has been set up is complete, take the opportunity to deploy a web application bar, collecting an online community forum, said it took things (network disk linking to blog posts at the beginning of the program code package includes):

1, the deployment of the 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          #解包
[root@localhost src]# mv upload/ /var/www/test1/bbs          #将解压后的文件移动到网站根目录下
[root@localhost src]# chown -R php:php /var/www/test1/bbs/         #调整权限

2, create the database:

[root@localhost src]# mysql -uroot -p
Enter password:            #验证数据库用户密码
mysql> create database bbs;        #创建专用的数据库
Query OK, 1 row affected (0.00 sec)
mysql> grant all on bbs.* to runbbs@localhost identified by 'pwd@123';  #授权用户为runbbs
Query OK, 0 rows affected (0.01 sec)

3, install web applications:
① Client Access to www.test1.com/bbs will open Discuz! Setup:

Based on centos 7 architecture to build LNMP

② The following pages are writable state must, if the red "X" number, it indicates a problem with the directory permissions to view the files in the source directory permissions it!

Based on centos 7 architecture to build LNMP

③ select a new installation:

Based on centos 7 architecture to build LNMP

④ set the database configuration and application Admin Password:
Based on centos 7 architecture to build LNMP

Based on centos 7 architecture to build LNMP

Based on centos 7 architecture to build LNMP

Log in to access www.test1.com/bbs/admin.php backstage look at:

Based on centos 7 architecture to build LNMPBased on centos 7 architecture to build LNMP

OK !!!!!!!!!!!!!!!!!

Guess you like

Origin blog.51cto.com/14154700/2411422