改进版本V1.1,修改源码包中的各种小错误
一.Yum升级
1.查看当前PHP版本
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
2.升级Yum软件仓库
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3.删除原有PHP程序
[root@localhost ~]# yum remove php-common php* -y
4.安装PHP 5.6版本以及使用模块
[root@localhost ~]# yum install php56w php56w-opcache php56w-xml php56w-mcrypt php56w-gd php56w-devel php56w-mysql php56w-intl php56w-mbstring php56w-fpm -y
5.查看现在PHP版本
[root@localhost ~]# php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
二.源码包安装
1.查看当前PHP版本
#无PHP程序可忽略!
[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
2.下载php-7.1.31源码包
#因php-5.6版本过老查不到源码包,改用php-7.1.31版本
[root@localhost ~]# wget -c https://www.php.net/distributions/php-7.1.31.tar.gz
3.解压php-7.1.31源码包
[root@localhost data]# tar -xzf php-7.1.31.tar.gz
4.删除原有PHP程序
#无PHP程序可忽略!
[root@localhost php-7.1.31]# yum remove php-common -y
5.安装xml扩展,png 扩展,jpeg 扩展,freetype 扩展
[root@localhost php-7.1.31]# yum install libxml2-devel libpng-devel libjpeg-devel freetype-devel -y
安装缺少得C编译器
[root@localhost php-7.1.31]# yum install gcc -y
安装OpenSSL库
[root@localhost php-7.1.31]# yum install openssl-devel -y
6.进入php-7.1.31进行预编译
[root@localhost php-7.1.31]# ./configure
--prefix=/usr/local/php
--with-config-file-path=/usr/local/php/lib
--with-freetype-dir=/usr/lib/
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-mysql=mysqlnd
--with-openssl-dir=/usr
--with-freetype-dir=/usr
--with-gd
--with-openssl
--with-pdo-mysql=mysqlnd
--with-pear
--with-zlib
--with-libxml-dir=/usr
--with-xmlrpc
--with-iconv
--enable-gd-native-ttf
--enable-zip
--enable-fpm
--enable-xml
--enable-sockets
--enable-soap
--enable-pcntl
--enable-cli
--enable-mbstring
--enable-ftp
复制可直接使用
[root@localhost php-7.1.31]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/lib --with-freetype-dir=/usr/lib/ --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-openssl-dir=/usr --with-freetype-dir=/usr --with-gd --with-openssl --with-pdo-mysql=mysqlnd --with-pear --with-zlib --with-libxml-dir=/usr --with-xmlrpc --with-iconv --enable-gd-native-ttf --enable-zip --enable-fpm --enable-xml --enable-sockets --enable-soap --enable-pcntl --enable-cli --enable-mbstring --enable-ftp
7.编译完成
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
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/phpdbg/phpdbg.1
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: --with-mysql
8.编译与编译安装php 7.1
[root@localhost php-7.1.31]# make && make install
9.拷贝配置文件
[root@localhost php-7.1.31]# cp php.ini-development /usr/local/php/lib/php.ini
10.查看当前PHP版本
[root@localhost php-7.1.31]# /usr/local/php/bin/php -v
PHP 7.1.31 (cli) (built: Aug 22 2019 20:10:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies