centos7下使用yum方式安裝PHP7

1、安裝準備php

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

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

 

2、開始安裝mysql

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

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配置)web

yum -y install php70w-fpm php70w-opcache

 

3.安裝完以後啓動php-fpmsql

systemctl start php-fpm

 

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

php -v

 

3、檢測PHP是否能與Nginx互通服務器

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

<?php
    phpinfo();
?>

 

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

        # 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出現如下內容即爲配置成功

 

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

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

<?php

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

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

修改完以後直接訪問index.php,無需重啓Nginx

相關文章
相關標籤/搜索