CentOS 7 配置PHP语言开发环境
安装PHP 5.6
可以从CentOS SCLo软件集进行安装。 即使安装了5.4,因为5.6位于另一个PATH上也是可以安装的。
# install from SCLo
[root@linuxprobe ~]# yum --enablerepo=centos-sclo-rh -y install rh-PHP56
- 加载环境变量
# load environment variables
[root@linuxprobe ~]# scl enable rh-PHP56 bash
[root@linuxprobe ~]# PHP -v
PHP 5.6.5 (cli) (built: Mar 23 2016 19:17:38)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0,Copyright (c) 1998-2014 Zend Technologies
[root@linuxprobe ~]# which PHP
/opt/rh/rh-PHP56/root/usr/bin/PHP
- 设置开机自启用环境变量
[root@linuxprobe ~]# vi /etc/profile.d/rh-PHP56.sh
#!/bin/bash
source /opt/rh/rh-PHP56/enable
export X_SCLS="`scl enable rh-PHP56 'echo $X_SCLS'`"
安装PHP 7.0
可以从Remi的存储库安装
[root@linuxprobe ~]# yum --enablerepo=remi-safe -y install PHP70
- 加载环境变量
[root@linuxprobe ~]# PHP70 -v
PHP 7.0.8 (cli) (built: Jun 22 2016 10:57:20) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0,Copyright (c) 1998-2016 Zend Technologies
[root@linuxprobe ~]# which PHP70
/bin/PHP70
[root@linuxprobe ~]# ll /bin/PHP70
lrwxrwxrwx 1 root root 32 Jul 6 09:58 /bin/PHP70 -> /opt/remi/PHP70/root/usr/bin/PHP
# load environment variables with SCL tool
[root@linuxprobe ~]# scl enable PHP70 bash
[root@linuxprobe ~]# PHP -v
PHP 7.0.8 (cli) (built: Jun 22 2016 10:57:20) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0,Copyright (c) 1998-2016 Zend Technologies
- 设置开机自启用环境变量
[root@linuxprobe ~]# vi /etc/profile.d/PHP70.sh
#!/bin/bash
source /opt/remi/PHP70/enable
export X_SCLS="`scl enable PHP70 'echo $X_SCLS'`"
安装PHP 7.1
可以从Remi的存储库安装
[root@linuxprobe ~]# yum --enablerepo=remi-safe -y install PHP71
- 加载环境变量
[root@linuxprobe ~]# PHP71 -v
PHP 7.1.3 (cli) (built: Mar 14 2017 16:22:48) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0,Copyright (c) 1998-2017 Zend Technologies
[root@linuxprobe ~]# which PHP71
/bin/PHP71
[root@linuxprobe ~]# ll /bin/PHP71
lrwxrwxrwx 1 root root 32 Jul 6 11:10 /bin/PHP71 -> /opt/remi/PHP71/root/usr/bin/PHP
# load environment variables with SCL tool
[root@linuxprobe ~]# scl enable PHP71 bash
[root@linuxprobe ~]# PHP -v
PHP 7.1.3 (cli) (built: Mar 14 2017 16:22:48) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0,Copyright (c) 1998-2017 Zend Technologies
- 设置开机自启用环境变量
[root@linuxprobe ~]# vi /etc/profile.d/PHP71.sh
#!/bin/bash
source /opt/remi/PHP71/enable
export X_SCLS="`scl enable PHP71 'echo $X_SCLS'`"
在Httpd上使用PHP7.1,配置PHP-fpm
- 安装PHP-fpm
# install Apache httpd
[root@linuxprobe ~]# yum install httpd -y
# install from Remi
[root@linuxprobe ~]# yum --enablerepo=remi-safe -y install PHP71-PHP-fpm
[root@linuxprobe ~]# vi /etc/httpd/conf.d/PHP.conf
# line 5: change like follows
<FilesMatch \.PHP$>
# SetHandler application/x-httpd-PHP
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
[root@linuxprobe ~]# systemctl start PHP71-PHP-fpm
[root@linuxprobe ~]# systemctl enable PHP71-PHP-fpm
[root@linuxprobe ~]# systemctl restart httpd
- 使用嵌入式方式
# install from Remi
[root@linuxprobe ~]# yum --enablerepo=remi-safe -y install PHP71-PHP
# rename and disable the old version if it exists
[root@linuxprobe ~]# mv /etc/httpd/conf.modules.d/15-PHP71-PHP.conf /etc/httpd/conf.modules.d/15-PHP71-PHP.conf.org
[root@linuxprobe ~]# systemctl restart httpd
# create PHPinfo to verify working
[root@linuxprobe ~]# echo '<?PHP PHPinfo(); ?>' > /var/www/html/info.PHP
[root@linuxprobe ~]# 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 20 100 20 0 0 1601 0 --:--:-- --:--:-- --:--:-- 1666