php是不是最好的语言这里不做讨论,纠结请出去 门在那┏ (゜ω゜)=☞
2015年12月初PHP7正式版发布,迎来自2004年以来最大的版本更新。PHP7最显著的变化就是性能的极大提升,已接近Facebook开发的PHP执行引擎HHVM。在WordPress基准性能测试中,速度比5.6版本要快2~3倍,大大减少了内存占用。PHP7在语言上也有一些变化,比如添加返回类型声明、增加了一些新的保留关键字等。在安全方面,去除了PHP安全模式,添加魔术引号等。不仅如此,新版还支持64位,而且包含最新版Zend引擎。
更多细节请翻阅php文档吧这里不多啰嗦。
下载PHP版本
# vi /etc/centos-release
或者
# vi /etc/redhat-release
CentOS release 6.9 (Final)
ps:不同的版本命令有所差异这里主要介绍6.x版本
#rpm -qa |grep php
或者
#php -v
#rpm -qa |grep httpd
或者
# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Mar 22 2017 06:52:55
#rpm -qa |grep mysql
或者
#mysql -v
或者
#mysql --help | grep Distrib
mysql Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using EditLine wrapper
#yum remove php* php-common
已加载插件:fastestmirror, security
设置移除进程
解决依赖关系
--> 执行事务检查
---> Package php-cli.x86_64 0:5.3.3-49.el6 will be 删除
---> Package php-common.x86_64 0:5.3.3-49.el6 will be 删除
---> Package php-mbstring.x86_64 0:5.3.3-49.el6 will be 删除
---> Package php-pdo.x86_64 0:5.3.3-49.el6 will be 删除
---> Package php-pear.noarch 1:1.9.4-5.el6 will be 删除
---> Package php-process.x86_64 0:5.3.3-49.el6 will be 删除
---> Package php-xml.x86_64 0:5.3.3-49.el6 will be 删除
--> 完成依赖关系计算
依赖关系解决
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
正在删除:
php-cli x86_64 5.3.3-49.el6 @base 6.2 M
php-common x86_64 5.3.3-49.el6 @base 2.9 M
php-mbstring x86_64 5.3.3-49.el6 @base 2.1 M
php-pdo x86_64 5.3.3-49.el6 @base 168 k
php-pear noarch 1:1.9.4-5.el6 @base 2.2 M
php-process x86_64 5.3.3-49.el6 @base 65 k
php-xml x86_64 5.3.3-49.el6 @base 307 k
事务概要
================================================================================
Remove 7 Package(s)
Installed size: 14 M
确定吗?[y/N]:y
下载软件包:
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在删除 : 1:php-pear-1.9.4-5.el6.noarch 1/7
正在删除 : php-cli-5.3.3-49.el6.x86_64 2/7
正在删除 : php-process-5.3.3-49.el6.x86_64 3/7
正在删除 : php-xml-5.3.3-49.el6.x86_64 4/7
正在删除 : php-pdo-5.3.3-49.el6.x86_64 5/7
正在删除 : php-mbstring-5.3.3-49.el6.x86_64 6/7
正在删除 : php-common-5.3.3-49.el6.x86_64 7/7
warning: /etc/php.ini saved as /etc/php.ini.rpmsave
Verifying : php-mbstring-5.3.3-49.el6.x86_64 1/7
Verifying : php-pdo-5.3.3-49.el6.x86_64 2/7
Verifying : php-xml-5.3.3-49.el6.x86_64 3/7
Verifying : php-cli-5.3.3-49.el6.x86_64 4/7
Verifying : 1:php-pear-1.9.4-5.el6.noarch 5/7
Verifying : php-process-5.3.3-49.el6.x86_64 6/7
Verifying : php-common-5.3.3-49.el6.x86_64 7/7
删除:
php-cli.x86_64 0:5.3.3-49.el6 php-common.x86_64 0:5.3.3-49.el6
php-mbstring.x86_64 0:5.3.3-49.el6 php-pdo.x86_64 0:5.3.3-49.el6
php-pear.noarch 1:1.9.4-5.el6 php-process.x86_64 0:5.3.3-49.el6
php-xml.x86_64 0:5.3.3-49.el6
完毕!
ps:机器上之前有5.3版本的php环境现在需要卸载掉
#rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
#yum list php7*
已加载插件:fastestmirror, security
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: uk.repo.webtatic.com
可安装的软件包
php70w.x86_64 7.0.27-1.w6 webtatic
php70w-bcmath.x86_64 7.0.27-1.w6 webtatic
php70w-cli.x86_64 7.0.27-1.w6 webtatic
php70w-common.x86_64 7.0.27-1.w6 webtatic
php70w-dba.x86_64 7.0.27-1.w6 webtatic
php70w-devel.x86_64 7.0.27-1.w6 webtatic
php70w-embedded.x86_64 7.0.27-1.w6 webtatic
php70w-enchant.x86_64 7.0.27-1.w6 webtatic
php70w-fpm.x86_64 7.0.27-1.w6 webtatic
php70w-gd.x86_64 7.0.27-1.w6 webtatic
php70w-imap.x86_64 7.0.27-1.w6 webtatic
php70w-interbase.x86_64 7.0.27-1.w6 webtatic
php70w-intl.x86_64 7.0.27-1.w6 webtatic
php70w-ldap.x86_64 7.0.27-1.w6 webtatic
php70w-mbstring.x86_64 7.0.27-1.w6 webtatic
php70w-mcrypt.x86_64 7.0.27-1.w6 webtatic
php70w-mysql.x86_64 7.0.27-1.w6 webtatic
php70w-mysqlnd.x86_64 7.0.27-1.w6 webtatic
php70w-odbc.x86_64 7.0.27-1.w6 webtatic
php70w-opcache.x86_64 7.0.27-1.w6 webtatic
php70w-pdo.x86_64 7.0.27-1.w6 webtatic
php70w-pdo_dblib.x86_64 7.0.27-1.w6 webtatic
php70w-pear.noarch 1:1.10.4-1.w6 webtatic
php70w-pecl-apcu.x86_64 5.1.9-1.w6 webtatic
php70w-pecl-apcu-devel.x86_64 5.1.9-1.w6 webtatic
php70w-pecl-geoip.x86_64 1.1.1-1.w6 webtatic
php70w-pecl-igbinary.x86_64 2.0.5-1.w6 webtatic
php70w-pecl-igbinary-devel.x86_64 2.0.5-1.w6 webtatic
php70w-pecl-imagick.x86_64 3.4.3-1.w6 webtatic
php70w-pecl-imagick-devel.x86_64 3.4.3-1.w6 webtatic
php70w-pecl-memcached.x86_64 3.0.4-1.w6 webtatic
php70w-pecl-mongodb.x86_64 1.3.3-1.w6 webtatic
php70w-pecl-redis.x86_64 3.1.6-1.w6 webtatic
php70w-pecl-xdebug.x86_64 2.6.0-1.w6 webtatic
php70w-pgsql.x86_64 7.0.27-1.w6 webtatic
php70w-phpdbg.x86_64 7.0.27-1.w6 webtatic
php70w-process.x86_64 7.0.27-1.w6 webtatic
php70w-pspell.x86_64 7.0.27-1.w6 webtatic
php70w-recode.x86_64 7.0.27-1.w6 webtatic
php70w-snmp.x86_64 7.0.27-1.w6 webtatic
php70w-soap.x86_64 7.0.27-1.w6 webtatic
php70w-tidy.x86_64 7.0.27-1.w6 webtatic
php70w-xml.x86_64 7.0.27-1.w6 webtatic
php70w-xmlrpc.x86_64 7.0.27-1.w6 webtatic
php71w-bcmath.x86_64 7.1.14-1.w6 webtatic
php71w-cli.x86_64 7.1.14-1.w6 webtatic
php71w-common.x86_64 7.1.14-1.w6 webtatic
php71w-dba.x86_64 7.1.14-1.w6 webtatic
php71w-devel.x86_64 7.1.14-1.w6 webtatic
php71w-embedded.x86_64 7.1.14-1.w6 webtatic
php71w-enchant.x86_64 7.1.14-1.w6 webtatic
php71w-fpm.x86_64 7.1.14-1.w6 webtatic
php71w-gd.x86_64 7.1.14-1.w6 webtatic
php71w-imap.x86_64 7.1.14-1.w6 webtatic
php71w-interbase.x86_64 7.1.14-1.w6 webtatic
php71w-intl.x86_64 7.1.14-1.w6 webtatic
php71w-ldap.x86_64 7.1.14-1.w6 webtatic
php71w-mbstring.x86_64 7.1.14-1.w6 webtatic
php71w-mcrypt.x86_64 7.1.14-1.w6 webtatic
php71w-mysql.x86_64 7.1.14-1.w6 webtatic
php71w-mysqlnd.x86_64 7.1.14-1.w6 webtatic
php71w-odbc.x86_64 7.1.14-1.w6 webtatic
php71w-opcache.x86_64 7.1.14-1.w6 webtatic
php71w-pdo.x86_64 7.1.14-1.w6 webtatic
php71w-pdo_dblib.x86_64 7.1.14-1.w6 webtatic
php71w-pear.noarch 1:1.10.4-1.w6 webtatic
php71w-pecl-apcu.x86_64 5.1.9-1.w6 webtatic
php71w-pecl-apcu-devel.x86_64 5.1.9-1.w6 webtatic
php71w-pecl-geoip.x86_64 1.1.1-1.w6 webtatic
php71w-pecl-igbinary.x86_64 2.0.5-1.w6 webtatic
php71w-pecl-igbinary-devel.x86_64 2.0.5-1.w6 webtatic
php71w-pecl-imagick.x86_64 3.4.3-1.w6 webtatic
php71w-pecl-imagick-devel.x86_64 3.4.3-1.w6 webtatic
php71w-pecl-memcached.x86_64 3.0.4-1.w6 webtatic
php71w-pecl-mongodb.x86_64 1.3.3-1.w6 webtatic
php71w-pecl-redis.x86_64 3.1.6-1.w6 webtatic
php71w-pecl-xdebug.x86_64 2.6.0-1.w6 webtatic
php71w-pgsql.x86_64 7.1.14-1.w6 webtatic
php71w-phpdbg.x86_64 7.1.14-1.w6 webtatic
php71w-process.x86_64 7.1.14-1.w6 webtatic
php71w-pspell.x86_64 7.1.14-1.w6 webtatic
php71w-recode.x86_64 7.1.14-1.w6 webtatic
php71w-snmp.x86_64 7.1.14-1.w6 webtatic
php71w-soap.x86_64 7.1.14-1.w6 webtatic
php71w-tidy.x86_64 7.1.14-1.w6 webtatic
php71w-xml.x86_64 7.1.14-1.w6 webtatic
php71w-xmlrpc.x86_64 7.1.14-1.w6 webtatic
这里选择 php70w.x86_64
来进行安装
#yum -y install php70w.x86_64
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* epel: mirrors.sohu.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: us-east.repo.webtatic.com
解决依赖关系
--> 执行事务检查
---> Package php70w.x86_64 0:7.0.27-1.w6 will be 安装
--> 处理依赖关系 php70w-common(x86-64) = 7.0.27-1.w6,它被软件包 php70w-7.0.27-1.w6.x86_64 需要
--> 处理依赖关系 php70w-cli(x86-64) = 7.0.27-1.w6,它被软件包 php70w-7.0.27-1.w6.x86_64 需要
--> 处理依赖关系 php70w-cli = 7.0.27-1.w6,它被软件包 php70w-7.0.27-1.w6.x86_64 需要
--> 执行事务检查
---> Package php70w-cli.x86_64 0:7.0.27-1.w6 will be 安装
---> Package php70w-common.x86_64 0:7.0.27-1.w6 will be 安装
--> 完成依赖关系计算
依赖关系解决
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
正在安装:
php70w x86_64 7.0.27-1.w6 webtatic 2.7 M
为依赖而安装:
php70w-cli x86_64 7.0.27-1.w6 webtatic 2.6 M
php70w-common x86_64 7.0.27-1.w6 webtatic 1.2 M
事务概要
================================================================================
Install 3 Package(s)
总下载量:6.5 M
Installed size: 25 M
下载软件包:
(1/3): php70w-7.0.27-1.w6.x86_64.rpm | 2.7 MB 00:03
(2/3): php70w-cli-7.0.27-1.w6.x86_64.rpm | 2.6 MB 00:02
(3/3): php70w-common-7.0.27-1.w6.x86_64.rpm | 1.2 MB 00:01
--------------------------------------------------------------------------------
总计 718 kB/s | 6.5 MB 00:09
warning: rpmts_HdrFromFdno: Header V4 DSA/SHA1 Signature, key ID cf4c4ff9: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el6
Importing GPG key 0xCF4C4FF9:
Userid : Webtatic EL6
Package: webtatic-release-6-9.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el6
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
正在安装 : php70w-common-7.0.27-1.w6.x86_64 1/3
正在安装 : php70w-cli-7.0.27-1.w6.x86_64 2/3
正在安装 : php70w-7.0.27-1.w6.x86_64 3/3
Verifying : php70w-cli-7.0.27-1.w6.x86_64 1/3
Verifying : php70w-common-7.0.27-1.w6.x86_64 2/3
Verifying : php70w-7.0.27-1.w6.x86_64 3/3
已安装:
php70w.x86_64 0:7.0.27-1.w6
作为依赖被安装:
php70w-cli.x86_64 0:7.0.27-1.w6 php70w-common.x86_64 0:7.0.27-1.w6
完毕!
安装 php70w-mysql.x86_64
php-mysql扩展
#yum install php70w-mysql
ps:这里遇到了点问题正在处理
安装mbstring扩展
#yum install php70w-mbstring
已加载插件:fastestmirror, security
设置安装进程
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* epel: mirrors.sohu.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
* webtatic: us-east.repo.webtatic.com
解决依赖关系
--> 执行事务检查
---> Package php70w-mbstring.x86_64 0:7.0.27-1.w6 will be 安装
--> 完成依赖关系计算
依赖关系解决
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
正在安装:
php70w-mbstring x86_64 7.0.27-1.w6 webtatic 949 k
事务概要
================================================================================
Install 1 Package(s)
总下载量:949 k
Installed size: 2.7 M
确定吗?[y/N]:y
下载软件包:
php70w-mbstring-7.0.27-1.w6.x86_64.rpm | 949 kB 00:09
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : php70w-mbstring-7.0.27-1.w6.x86_64 1/1
Verifying : php70w-mbstring-7.0.27-1.w6.x86_64 1/1
已安装:
php70w-mbstring.x86_64 0:7.0.27-1.w6
完毕!
去官网下载镜像文件: php下载地址
当前最新版本是php-7.2.3
我们这里选择了 php-7.2.3.tar.gz
我们选择了中国的地址 http://cn2.php.net/get/php-7.2.3.tar.gz/from/this/mirror
下面开始执行命令
#cd /usr/local/src
所有的软件源码下载放到这里
#wget http://cn2.php.net/get/php-7.2.3.tar.gz
# tar -xzvf php-7.2.3.tar.gz
#cd php-7.2.3
下面开始编译配置编译之后文件放在了 /usr/local/php7.2.3
目录中
#./configure --prefix=/usr/local/php7.2.3 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
我执行过程中遇到了一些问题 缺少一些模块
xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
#yum -y install libxslt libxslt-devel
执行上面的指令后接着重新进行编译配置
看到下面的提示说明配置完成了
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --enable-gd-native-ttf
最后这里有一个警告
configure: WARNING: unrecognized options: –enable-gd-native-ttf
表示php7.2不支持这个选项,
把--enable-gd-native-ttf
编译选项删除就可以了。
#make ZEND_EXTRA_LIBS=' -liconv'
#make install
编译时间有点长
#cp php.ini-production /usr/local/php7/etc/php.ini
#cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
#cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm7
#cd /etc/init.d
#vim php7-fpm
文件内容如下
#!/bin/sh
# chkconfig: 2345 15 95
# description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
#chmod a+x /etc/init.d/php7-fpm
#chkconfig --add php7-fpm
#chkconfig php7-fpm on
#service php7-fpm start
#service php7-fpm stop
新建 /var/www/html/php
目录
目录中新建index.php
// 顺便可以看一下php的扩展全不全
phpinfo();
?>
配置nginx
server {
listen 8011;
server_name localhost ; #域名可以有多个,用空格隔开
access_log logs/access.log main;
root /var/www/html/php;
index index.php index.html index.htm;
# 这里新加的
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
然后重新加载nginx
测试是否能返回php网页信息
curl http://localhost:8011
配置php就这样了
老版本安装请参考PHP-5.3.29编译安装