PHP Install
snow chuai汇总、整理、撰写---2020/07/26
1. PHP 7.2安装与验证
1) 安装PHP
[root@srv1 ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/remi-safe.repo
[root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-safe.repo
[root@srv1 ~]# yum --enablerepo=remi-safe install php72 php72-php-pear php72-php-mbstring -y
2) 验证php
[root@srv1 ~]# scl enable php72 bash
[root@srv1 ~]# php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@srv1 ~]# vim /etc/profile.d/php72.sh
#!/bin/bash
source /opt/remi/php72/enable
export X_SCLS="`scl enable php72 'echo $X_SCLS'`"
3) 让Apache使用PHP-(PHP-FPM)
[root@srv1 ~]# yum --enablerepo=remi-safe install php72-php-fpm -y
[root@srv1 ~]# vim /etc/httpd/conf.d/php.conf
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
php_value session.save_handler "files"
php_value session.save_path "/var/opt/remi/php72/lib/php/session"
[root@srv1 ~]# systemctl enable --now php72-php-fpm
[root@srv1 ~]# systemctl restart httpd
[root@srv1 ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php
[root@srv1 ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69081 0 69081 0 0 3107k 0 --:--:-- --:--:-- --:--:-- 3212k
PHP Version 7.2.1
4) 让Apache使用嵌入式的PHP
[root@srv1 ~]# yum --enablerepo=remi-safe -y install php72-php
[root@srv1 ~]# mv /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/10-php.conf.org
[root@srv1 ~]# systemctl restart httpd
[root@srv1 ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php
[root@srv1 ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69081 0 69081 0 0 3107k 0 --:--:-- --:--:-- --:--:-- 3212k
PHP Version 7.2.1
|
2. PHP 7.3安装与验证
1) 安装PHP
[root@srv1 ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@srv1 ~]# sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/remi-safe.repo
[root@srv1 ~]# sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-safe.repo
[root@srv1 ~]# yum --enablerepo=remi-safe install php73 php73-php-pear php73-php-mbstring -y
2) 验证php
[root@srv1 ~]# scl enable php73 bash
[root@srv1 ~]# vim /etc/profile.d/php73.sh
source /opt/remi/php73/enable
export X_SCLS="`scl enable php73 'echo $X_SCLS'`"
[root@srv1 ~]# php -v
PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
3) 让Apache使用PHP-(PHP-FPM)
[root@srv1 ~]# yum --enablerepo=remi-safe install php73-php-fpm -y
[root@srv1 ~]# vim /etc/httpd/conf.d/php.conf
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
php_value session.save_handler "files"
php_value session.save_path "/var/opt/remi/php73/lib/php/session"
[root@srv1 ~]# systemctl enable --now php73-php-fpm
[root@srv1 ~]# systemctl restart httpd
[root@srv1 ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php
[root@srv1 ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69081 0 69081 0 0 3107k 0 --:--:-- --:--:-- --:--:-- 3212k
PHP Version 7.3.5
4) 让Apache使用嵌入式的PHP
[root@srv1 ~]# yum --enablerepo=remi-safe -y install php73-php
[root@srv1 ~]# mv /etc/httpd/conf.modules.d/10-php.conf /etc/httpd/conf.modules.d/10-php.conf.org
[root@srv1 ~]# systemctl restart httpd
[root@srv1 ~]# echo '<?php phpinfo(); ?>' > /var/www/html/info.php
[root@srv1 ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 69081 0 69081 0 0 3107k 0 --:--:-- --:--:-- --:--:-- 3212k
PHP Version 7.3.5
|
如对您有帮助,请随缘打个赏。^-^