centos7下使用yum方式安裝PHP7


一、安裝准備

使用以下命令將yum倉庫包升級更換成PHP7的rpm包

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

 

二、開始安裝

1.先使用yum命令安裝基本PHP組件,以后要用到啥再安裝啥

yum -y install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

 

2.再安裝PHP-fpm(進程管理器,提供PHP進程管理方式,可以有效控制內存和進程、平滑重載PHP配置)

yum -y install php70w-fpm php70w-opcache

 

3.安裝完之后啟動php-fpm

systemctl start php-fpm

 

4.查看版本以檢測是否安裝成功

php -v

 

三、檢測PHP是否能與Nginx互通

1.在Nginx的默認HTML文件夾里(/usr/local/webserver/nginx/html/)新建一個index.php,內容如下:

<?php
    phpinfo();
?>

 

2.修改Nginx的配置文件(可使用find /|grep nginx.conf搜索配置文件位置)Nginx.conf,修改新增如下:

        # 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  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

要將原屬性修改成藍色字體部分,不然訪問index.php會出現以下情況(php-fpm找不到原SCRIPT_FILENAME里執行的php文件)

3.重啟Nginx

/usr/local/webserver/nginx/sbin/nginx -s reload

 

4.訪問域名(IP)/index.php出現以下內容即為配置成功

 

四、檢測PHP是否能與mysql互通

將上一份index.PHP內容修改如下

<?php

// 創建連接
$test = mysqli_connect('localhost','root','qq1234');//數據庫服務器地址,賬號名,密碼

// 檢測
if (!$test) echo "連接失敗,請檢查mysql服務以及賬戶密碼";
echo "數據庫連接成功!";
?>

修改完之后直接訪問index.php,無需重啟Nginx

 


免責聲明!

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



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