帮助中心
  • 云主机
  • 数据盘
  • 弹性IP
  • 快照
  • 云防火墙

以Centos7.1为例:

安装 CentOS 7 EPE 源:

[root@localhost ~]# yum -y install epel-release

 

安装源后可以安装nginx服务

[root@localhost ~]# yum -y install nginx

 

启动nginx 服务,并设为自启动

[root@localhost ~]# systemctl start nginx

[root@localhost ~]# systemctl enable nginx

安装完成后在浏览器中输入配好的域名或IP如下图证明已经安装完成

http://server_domain_name_or_IP/

blob.png

添加如下nginx配置:

[root@localhost ~]# vi /etc/nginx/conf.d/default.conf

server {

    listen       80;

    server_name  localhost;

 

    location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm;

    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

下面安装MySQL (mariadb-server ):

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

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# systemctl enable mariadb

 

下面执行mysql_secure_installation 来初始化数据库并设置root密码:

blob.png


下面开始安装php:

[root@localhost ~]# yum -y install php php-mysql php-fpm

[root@localhost ~]# vi /etc/php.ini

修改php的参数cgi.fix_pathinfo 避免nginx文件类型错误解析漏洞

blob.png

修改php-fpm的监听,使用sock方式

[root@localhost ~]# vi /etc/php-fpm.d/www.conf

blob.png

修改php-fpm使用nginx帐户运行

blob.png

启动php-fpm,并设置成自动开机启动

[root@localhost ~]# systemctl start php-fpm

[root@localhost ~]# systemctl enable php-fpm

 

Nginx的php配置升级成

[root@localhost ~]# vi /etc/nginx/conf.d/default.conf

server {

    listen      80;

    server_name  _;

    # note that these lines are originally from the "location /" block

    root   /usr/share/nginx/html;

    index index.php index.html index.htm;

 

    location / {

        try_files $uri $uri/ =404;

    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

    location = /50x.html {

        root /usr/share/nginx/html;

    }

    location ~ \.php$ {

        try_files $uri =404;

        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include fastcgi_params;

     }

     }

 

重启nginx,新建php 的测试web页面

[root@localhost ~]# systemctl restart nginx

[root@localhost ~]# vi /usr/share/nginx/html/test.php

blob.png

 

然后直接输入 http://yourserver_IP/test.php

出现如下页面显示,即表示这套安装环境已部署完成

blob.png




上一篇 下一篇