1、去PHP官网下载PHP7.2版本
wget http://cn2.php.net/distributions/php-7.2.12.tar.gz
-
- 如果执行命令后提示:-bash: wget: command not found ,用 yum install wget 安装即可
2、解压 **.tar.gz 安装包
tar -xzvf php-7.2.12.tar.gz
3、如果安装中提示缺少各种依赖包的话,请直接安装下面的所有包:
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
4、进入PHP文件夹编译
./configure \--prefix=/usr/local/php7.2 \--with-config-file-path=/usr/local/php7.2/etc \--enable-mysqlnd \--with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-zlib \--with-libxml-dir=/usr \--enable-xml \--disable-rpath \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-inline-optimization \--with-curl \--enable-cli \--enable-mbregex \--enable-fpm \--enable-mbstring \--with-mcrypt \--with-gd \--with-gettext \--enable-gd-native-ttf \--with-openssl \--with-mhash \--enable-pcntl \--enable-sockets \--with-xmlrpc \--with-iconv \--enable-zip \--enable-soap \--enable-short-tags \--enable-static \--with-xsl \--with-pear \--with-fpm-user=www \--with-fpm-group=www \--enable-opcache=no \--enable-maintainer-zts \--enable-ftp
5、编译完成之后,执行安装命令:
make && make install
---------------------
至此已经安装完毕,接下来有需要的可以配置PHP,步骤如下:
6、在编译的源码包中,找到 php.ini-production,复制到/usr/local/php7.2下,并改名为php.ini
[root@localhost php-7.2.12]# cp php.ini-production /usr/local/php7.2/etc/php.ini
如果你不确定php.ini的目录位置的话 可以用如下查看
[root@localhost ~]# /usr/local/php7.2/bin/php --ini Configuration File (php.ini) Path: /usr/local/php7.2/etc
7、复制php-fpm启动脚本
[root@localhost php-7.2.12]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm[root@localhost php-7.2.12]# chmod +x /etc/init.d/php-fpm
8、加入开机启动项
[root@localhost ~]# cd /etc/init.d/[root@localhost init.d]# chkconfig --add php-fpm
9、给PHP做个软链接便于使用
[root@localhost php-7.2.12]# ln -s /usr/local/php7.2/bin/php /usr/bin/php
或者是直接将bin目录加入PATH环境变量中,如果你有多个版本还是建议软链接的方式好点。
[root@localhost php-7.2.12]# export PATH=/usr/local/php7.2/bin:$PATH
OK,完毕!