centos7 nginx+php7yum安裝


centos7 nginx+php7yum安裝。

    一.安裝nginx

    1.安裝yum源

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

    2.安裝nginx

yum install -y nginx

    3.啟動nginx並設置開機自動運行

  1.  systemctl start nginx  #啟動,restart-重啟,stop-停止
  2.  systemctl  enable nginx #開機啟動

    4.查看版本及運行狀態

  1.  nginx -v  #查看版本
     
  2.  ps -ef | grep nginx  #查看運行狀態
     

    二.安裝php7

    1.安裝yum源

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

    2.查看php7 yum組件,示例安裝php7.2

  1.  yum search php72w 
     

    3.選擇自己需要的組件安裝,php72w.x86_64 和 php72w-fpm.x86_64 為核心程序必裝

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

    4.啟動php並設為開機啟動

  1.  systemctl start php-fpm  #啟動,restart-重啟,stop-停止
     
  2.  systemctl  enable php-fpm #開機啟動
     

    5.查看版本及運行狀態

  1.  php-fpm -v  #查看版本
     
  2.  ps -ef | grep php-fpm  #查看運行狀態

進行完以上步驟之后,讀者自行在nginx中配置web目錄,已經可以正常運行了,但是此時nginx和php是以root身份運行,以最高權限運行web文件會給系統帶來安全隱患,以下為權限配置示例


    三.修改nginx配置

  vi /etc/nginx/conf.d/default.conf

  1.  找到第一個location中的這一行

    index  index.html index.htm;

    修改為:

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

        2.

    把FastCGI server這行下面的location的注釋去掉,並修改成下面這樣子

     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

     #

     location ~ \.php$ {

         root            /usr/share/nginx/html;  #網站根目錄

         fastcgi_pass   127.0.0.1:9000;

         fastcgi_index  index.php;

         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

         include        fastcgi_params;

     }

service nginx restart   #重啟nginx

service php-fpm start   #開啟php-fpm

  3. 

在網站根目錄新建index.php文件

vim /usr/share/nginx/html/index.php

  4.

輸入內容:

<?php

phpinfo();

  5.

在瀏覽器中輸入虛擬機ip,已經可以看到phpinfo的信息了 
windows上修改hosts文件,添加一行

192.168.6.114   www.test1.com   #配置虛擬機ip對應域名

  6.

現在就可以在windows上用www.test1.com訪問虛擬機配置的服務器了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM