LNMP all-in-one

0.原理:

1.fastCGI是nginx和php之间的一个通信接口,该接口实际处理过程通过启动php-cgi进程来解析php动态脚本,spawn-fcgi相当于一个动态应用服务器用来启动和运行php-cgi进程,从而实现nginx解析php。

2.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接纳到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。

LNMP all-in-one

1.环境的配置

使用的软件:VMware workstation 12.5.6 链接:http://pan.baidu.com/s/1kUPoqkn 密码:1cqk

安装的系统:CentOS-7-x86_64-Minimal-1511.iso  链接:http://pan.baidu.com/s/1gffB0xt 密码:49tu

虚拟机配置:内存:1GB  处理器:1  硬盘:20GB 

虚拟机网络:NAT模式

LNMP all-in-one

LNMP all-in-one

2.网络配置

[[email protected] home]# cd /etc/sysconfig/network-scripts/

[[email protected] network-scripts]# vi ifcfg-eno16777736 修改网络配置文件

TYPE=Ethernet 网卡类型
BOOTPROTO=dhcp 获取地址的方式
NAME=eno16777736 网卡名称
PEERDNS=yes 启动网络时是否修改/etc/resolv.conf
HWADDR=00:0c:29:cd:c1:73 MAC地址
DEVICE=eno16777736 设备名称
ONBOOT=yes 是否启用网卡

[[email protected] network-scripts]# systemctl restart network

[[email protected] home]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:cd:c1:73 brd ff:ff:ff:ff:ff:ff
    inet 192.168.17.130/24 brd 192.168.17.255 scope global dynamic eno16777736
       valid_lft 1674sec preferred_lft 1674sec
    inet6 fe80::8d16:1719:41d0:1577/64 scope link 
       valid_lft forever preferred_lft forever

3.软件安装

[[email protected] ~]# yum -y update
[[email protected] ~]# yum -y install wget net-tools vim unzip

[[email protected] ~]# yum -y install php-mysql php maridb mariadb-server

用xftp传输文件 nginx-1.8.0-1.el7.ngx.x86_64.rpm spawn-fcgi-1.6.3-5.el7.x86_64.rpm 链接:http://pan.baidu.com/s/1c2Cl8yc 密码:an0u

[[email protected] ~]# rpm -ivh nginx-1.8.0-1.el7.ngx.x86_64.rpm

[[email protected] ~]# rpm -ivh spawn-fcgi-1.6.3-5.el7.x86_64.rpm

4.修改配置文件

[[email protected] ~]# vim /etc/sysconfig/spawn-fcgi

OPTIONS="-u nginx -g nginx -p 9000 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"

[[email protected] ~]# cd /etc/nginx/conf.d/

[[email protected] conf.d]# cp default.conf www.conf

[[email protected] conf.d]# vim www.conf

server {
    listen       80;
    server_name  localhost;
    index index.php index.html;
    root /home/www;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
        root   /home/www;
        index  index.html index.htm index.php;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/www$fastcgi_script_name;
        include        fastcgi_params;
    }
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

[[email protected] conf.d]# mv default.conf default.conf.bak

[[email protected] ~]# setenforce 0 关闭seliunx

[[email protected] ~]# vim /etc/selinux/config 开机默认关闭selinux

SELINUX=disabled

[[email protected] ~]# systemctl stop firewalld   关闭防火墙

[[email protected] ~]# systemctl mask firewalld 开机默认关闭防火墙

[[email protected] ~]# mkdir /home/www

用xftp传输文件Discuz_X3.2_SC_UTF8.zip

[[email protected] ~]# unzip Discuz_X3.2_SC_UTF8.zip

[[email protected] ~]# mv upload/* /home/www

[[email protected] ~]# chown -R nginx:nginx /home/www

[[email protected] ~]# vim /etc/php.ini 

short_open_tag = On

5.启动服务

[[email protected] ~]# systemctl start spawn-fcgi 启动spawn-fcgi服务

[[email protected] ~]# systemctl enable spawn-fcgi 开机默认启动spawn-fcgi服务

添加不上 echo "/sbin/chkconfig spawn-fcgi on" >> /etc/rc.local

[[email protected] ~]# systemctl start nginx 启动nginx

[[email protected] ~]# systemctl enable nginx 开机默认启动nginx

[[email protected] ~]# systemctl start mariadb 启动mariadb

[[email protected] ~]# systemctl enable mariadb 开机默认启动mariadb

[[email protected] ~]# mysqladmin -uroot password 设置mysql,root密码

enter: 123.com

6.打开网页
192.168.17.130

进入安装界面

LNMP all-in-one

我同意

LNMP all-in-one

下一步

LNMP all-in-one

全新安装 Discuz! X

下一步

LNMP all-in-one

下一步

LNMP all-in-one

LNMP all-in-one

LNMP all-in-one