LNMP mounted separately

A lot of people in the building when a machine is used to deploy LNMP environment, but we are generally separated deployed in the actual work. That is MySQL MySQL; it is a stand-alone, isolated deploy their own to run their own services, improve efficiency!

Three machines to deploy LNMP environment, as follows:

 

OS: Centos7.3x86_64

Nginx-1.12.2 IP address: 192.168.10.101

PHP-5.5 IP address: 192.168.10.103

MySQL5.7 IP address: 192.168.10.105

IP address of NFS: 192.168.10.105

 

A: NFS installation

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

[root@localhost ~]# yum -y install nfs-utils rpcbind

[root@localhost ~]# systemctl enable nfs

[root@localhost ~]# systemctl enable rpcbind

 

(2) set the shared directory

[root@localhost ~]# mkdir -p /opt/wwwroot

[root@localhost ~]# vi /etc/exports

/opt/wwwroot   192.168.10.0/24(rw,sync,no_root_squash)

 

[root@localhost ~]# systemctl start nfs

[root@localhost ~]# systemctl start rpcbind

 

 

 

Second, install Nginx

 

1) related to the installation dependencies

[root@nginx ~]# yum install -y gcc*  zlib-devel pcre-devel

 

2) establish a user-specified id Nginx

[root@nginx ~]#useradd -u 1001 nginx

 

3) download and install the installation package Nginx Source

[root@nginx src]# tar zxf nginx-1.12.2.tar.gz   

[root@nginx src]# cd nginx-1.12.2/  

[[email protected]]#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install

 

 

4) Create a soft link and start the test Nginx access

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

 

[root@nginx nginx-1.12.2]# nginx -t  

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@nginx nginx-1.12.2]# nginx  

[root@nginx nginx-1.12.2]# netstat -anput | grep nginx  

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      27185/nginx: master   

 



 

[root@localhost ~]#mkdir /www

[root@localhost ~]# mount 192.168.10.105:/opt/wwwroot /www

 

Here Nginx already installed, then install php

 

 

Second, install PHP

 

1) related to the installation dependencies

[root@localhost ~]# yum -y install gcc* libxml2-devel pcre-devel zlib-devel

 

 

3) officially installed php

[root@localhost ~]#useradd nginx

[root@localhost ~]# tar zxvf php-5.5.38.tar.gz

[root@localhost ~]# cd php-5.5.38/

 

 

[root@localhost php-5.5.38]# ./configure --prefix=/usr/local/php --with-mysql --with-mysqli --enable-fpm && make && make install

 



 

PHP configuration file and provide service script

[root@localhost php-5.5.38]# cp php.ini-production /etc/php.ini

 

Providing php-fpm service control script

[root@php php-5.5.38]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm   

[root@localhost php-5.5.38]# chmod +x /etc/init.d/php-fpm

[root@localhost php-5.5.38]# chkconfig --add php-fpm

 

[root@localhost php-5.5.38]# chkconfig php-fpm on

 

[root@localhost php-5.5.38]# cd /usr/local/php/etc/

[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf

[root@localhost etc]# ln -s /usr/local/php/sbin/* /usr/local/sbin/

[root@localhost etc]# ln -s /usr/local/php/bin/* /usr/local/bin/

 

[root@localhost php-5.5.38]# vi /usr/local/php/etc/php-fpm.conf

Modifications are as follows:

RUN = pid / php-fpm.pid
IP address listen = 192.168.10.103:9000 // PHP Host

After editing start php Service

[root@localhost etc]# /usr/local/sbin/php-fpm

 

Here our php completed! Next, install MySQL

 

Third, the installation MySQL

NOTE: yum step can install the database, then the following is not required to install mysql

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# setenforce 0

 

[root@localhost ~]# yum -y install mariadb-server mariadb

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# mysqladmin -u root password "pwd123"

 

 

 

 

 

Fourth, configure Nginx support PHP environment

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

user  nginx;

 

location / {  

            root / www; change web directory  

            index  index.php index.html index.htm;  添加index.php

        }  

 

location ~ \.(gif|jpg|jpeg|png|bmp|swf)$ {

     root /www;

   }

 

location ~ \.php$ {  

            root / www; change directory  

            fastcgi_pass 192.168.10.102:9000; Note: Here add the PHP host IP address  

            fastcgi_index  index.php;  

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  

            include        fastcgi.conf;  

        }  

 

 

 

If you do php load balancing, nginx configuration file amended as follows:

 

upstream wordpress {

server 192.168.10.101:9000;

server 192.168.10.102:9000;

}

    server {

        listen       80;

        server_name  localhost;

             root /www;

        charset utf8;

 

 

        location / {

            index  index.html index.htm index.php;

       }

 

 

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        location ~ \.php$ {

            fastcgi_pass   wordpress;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            include        fastcgi.conf;

        }

    }

}

 

 

[root@nginx ~]# mkdir /www

[root@nginx ~]# chown nginx:nginx /www/  

[root@nginx ~]# cd /www/  

[root@nginx www]# vim index.php  

[root@nginx www]# cat index.php   

<?php  

phpinfo();  

?>  

Here we first do in the next restart Nginx PHP master operations (1.20)

 

[root@php ~]# mkdir /www  

[root@php ~]# chown -R nginx:nginx /www/  

[root@php ~]# cd /www/  

[root@php www]# vim index.php  

[root@php www]# cat index.php   

<?php  

phpinfo();  

?>  

Once created, and then we restart nginx php, access the test page

[root@nginx www]# nginx -s reload  

[root@php www]# service php-fpm restart   

 

Five: deploy wordpress website

1: in mysql

mysql> create database wordpress;  

Query OK, 1 row affected (0.00 sec)  

mysql> grant all on wordpress.* to yankerp@'%' identified by '123456';  

Query OK, 0 rows affected, 1 warning (0.00 sec)  

 

 

2: In nfs

[root@nginx ~]# tar zxf wordpress-4.9.1-zh_CN.tar.gz   

[root@nginx ~]# mv wordpress/* /opt/wwwroot

[root@nginx ~]# useradd nginx

[root@nginx ~]# chown -R nginx:nginx /opt/wwwroot

Guess you like

Origin www.cnblogs.com/lzyayw/p/11446348.html