php7 nginx安裝

1.安裝yum源php

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    2.安裝nginxhtml

yum install -y nginx
    3.啓動nginx並設置開機自動運行mysql

systemctl start nginx #啓動,restart-重啓,stop-中止
systemctl enable nginx #開機啓動
    4.查看版本及運行狀態nginx

nginx -v #查看版本

ps -ef | grep nginx #查看運行狀態web

 

注意,這裏的nginx運行的用戶是root ,最好改爲nginxredis

 

二.安裝php7
    sql

更換安裝源後端

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmcentos

 

yum clean all 
yum makecache 
yum updatephp7

 

安裝

yum install php72w* --skip-broken
//或者指定模塊7.0
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
//或者安裝7.2版本
yum install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel

 

 

配置php

vi /etc/php.in

改:cgi.fix_pathinfo=0  (大概在762行,若是文件不存在,則阻止 Nginx 將請求發送到後端的 PHP-FPM 模塊, 以免遭受惡意腳本注入的攻擊)

 

配置php-fpm

vi /etc/php-fpm.d/www.conf
  1. user = nginx
  2. group = nginx
  3. listen = /var/run/php-fpm/php-fpm.sock
  4. listen.owner = nginx
  5. listen.group = nginx

配置nginx支持PHP

vi /etc/nginx/conf.d/default.conf
location / {
        root   /web/web1;
        index  index.php index.html index.htm;
    }

    location ~ \.php$ {
      #注意這裏,也要把root加進去
      root /web/web1;
      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;
    }

注意防火牆

相關文章
相關標籤/搜索