一、Centos7安裝PHP72
檢查系統(tǒng)版本
cat /etc/redhat-release
uname -r
1.1安裝EPEL庫
yum install -y epel-release
1.2安裝remi庫 CentOS 7 / RHEL 7
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
默認(rèn)地,REMI是禁用的。要檢查REMI是否已經(jīng)成功安裝,使用這個(gè)命令yum repolist disabled | grep remi
要搜索或安裝REMI倉庫中的包,使用這些命令:
yum --enablerepo=remi search <keyword>
yum --enablerepo=remi install <package-name>
1.3安裝yum-utils工具包
yum install -y yum-utils
1.4開啟remi庫
yum-config-manager --enable remi-php72
yum update -y
1.5查找有沒有7.2的包
yum search php72 | more
yum search php72 | egrep 'fpm|gd|mysqy|memcache'
1.6安裝php7.2
yum install -y php72
其他形式
#安裝PHP
yum --enablerepo=remi install -y php72
#升級(jí)PHP
yum --enablerepo=remi-php72,remi update php*
#升級(jí)mysql
yum --enablerepo=remi-mysql,remi update mysql*
1.7安裝php72-php-fpm,和一些其他模塊
yum install -y php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
二、驗(yàn)證
2.1驗(yàn)證版本
php72 --version
2.2驗(yàn)證安裝的模塊
php72 --modules
三、有關(guān)php72-php-fpm服務(wù)
3.1設(shè)置開機(jī)啟動(dòng) php fpm服務(wù)
systemctl enable php72-php-fpm.service
3.2開啟 php fpm服務(wù)
systemctl start php72-php-fpm.service
3.3關(guān)閉 php fpm服務(wù)
systemctl stop php72-php-fpm.service
3.4重新啟動(dòng) php fpm服務(wù)
systemctl restart php72-php-fpm.service
3.5獲取php fpm服務(wù)狀態(tài)
systemctl status php72-php-fpm.service
四、配置nginx
需要先確保系統(tǒng)上已經(jīng)安裝最近版本的nginx
4.1查看服務(wù)用戶和用戶組
egrep '^(user|group)' /etc/nginx/nginx.conf
4.2編輯php-fpm配置文件,并修改用戶名和用戶組為nginx
vi /etc/opt/remi/php72/php-fpm.d/www.conf
設(shè)置用戶名和用戶組
user = nginx
group = nginx
4.3重新啟動(dòng)php-fpm服務(wù)
systemctl restart php72-php-fpm.service
4.4修改nginx配置,添加以下內(nèi)容
vi /etc/nginx/conf.d/default.conf
增加配置:
## enable php support ##
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_params SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
4.5重新啟動(dòng)nginx
systemctl restart nginx
4.6在/usr/share/nginx/html/下創(chuàng)建foo.php測(cè)試文件,并添加一下內(nèi)容,保存退出
vi /usr/share/nginx/html/foo.php
增加以下內(nèi)容:
<?php
phpinfo();
?>
五、其他
# php安裝路徑
/etc/opt/remi/php72
#nginx配置文件
/etc/nginx/nginx.conf
#nginx默認(rèn)項(xiàng)目路徑
/usr/share/nginx/html
#創(chuàng)建一個(gè)軟連接php執(zhí)行php72
which php72
cd /usr/bin
ln -s php72 php
備注:
epel-release:為yum擴(kuò)展軟件源
remi:為yum擴(kuò)展軟件源,Remi repository 是包含最新版本 PHP 和 MySQL 包的 Linux 源,由 Remi 提供維護(hù)。有個(gè)這個(gè)源之后,使用 YUM 安裝或更新 PHP、MySQL、phpMyAdmin 等服務(wù)器相關(guān)程序的時(shí)候就非常方便了
PHP-FPM(FastCGI Process Manager:FastCGI進(jìn)程管理器)是一個(gè)PHPFastCGI管理器文章來源:http://www.zghlxwxcb.cn/news/detail-473651.html
作者:rapattern
鏈接:https://www.jianshu.com/p/37c59acade70
來源:簡(jiǎn)書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。文章來源地址http://www.zghlxwxcb.cn/news/detail-473651.html
到了這里,關(guān)于Centos7安裝PHP的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!