1. 安装所需环境
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel
2. 下载并安装PHP
1. 下载 wget http://cn2.php.net/distributions/php-7.3.3.tar.gz 2. 解压 tar -xzf php-7.3.3.tar.gz 3. 进入目录 cd php7.3.3 4. 编译php ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/etc/php.d --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache
编译,安装
make && make install -j2
-j: 启用两个任务
3. 配置PHP
1) 复制ini文件
cp php.ini-production /usr/local/php7/etc/php.ini
2) 配置fpm
cd /usr/src/php-7.0.0/sapi/fpm cp init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on
4. 启动服务
/etc/init.d/php-fpm start
5. 添加环境变量
vim /etc/profile 最后添加 export PATH=$PATH:/usr/local/php7/bin 马上生效 source /etc/profile 可以正常使用全局命令 php -v PHP 7.2.0 (cli) (built: Jan 16 2020 12:17:55) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
常见错误:
1.
make时提示: ..................................................... ext/iconv/.libs/iconv.o(.text+0x1738): In function `zif_iconv_mime_encode': /usr/src/php-7.2.0/ext/iconv/iconv.c:1017: undefined reference to `libiconv_open' ext/iconv/.libs/iconv.o(.text+0x1756):/usr/src/php-7.2.0/ext/iconv/iconv.c:1031: undefined reference to `libiconv_open' ext/iconv/.libs/iconv.o(.text+0x1993):/usr/src/php-7.2.0/ext/iconv/iconv.c:1290: undefined reference to `libiconv_close' ext/iconv/.libs/iconv.o(.text+0x19ad):/usr/src/php-7.2.0/ext/iconv/iconv.c:1293: undefined reference to `libiconv_close' ext/iconv/.libs/iconv.o(.text+0x1b01):/usr/src/php-7.2.0/ext/iconv/iconv.c:1102: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x1b33):/usr/src/php-7.2.0/ext/iconv/iconv.c:1134: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x1b5e):/usr/src/php-7.2.0/ext/iconv/iconv.c:1150: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x1e10):/usr/src/php-7.2.0/ext/iconv/iconv.c:1202: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x1e3c):/usr/src/php-7.2.0/ext/iconv/iconv.c:1233: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x207f):/usr/src/php-7.2.0/ext/iconv/iconv.c:1277: more undefined references to `libiconv' follow ext/iconv/.libs/iconv.o(.text+0x2c08): In function `php_iconv_stream_filter_dtor': /usr/src/php-7.2.0/ext/iconv/iconv.c:2393: undefined reference to `libiconv_close' ext/iconv/.libs/iconv.o(.text+0x2cf2): In function `php_iconv_stream_filter_append_bucket': /usr/src/php-7.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x2d34):/usr/src/php-7.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x2de7):/usr/src/php-7.2.0/ext/iconv/iconv.c:2465: undefined reference to `libiconv' ext/iconv/.libs/iconv.o(.text+0x30e2): In function `php_iconv_stream_filter_factory_create': /usr/src/php-7.2.0/ext/iconv/iconv.c:2419: undefined reference to `libiconv_open' collect2: ld returned 1 exit status make: *** [sapi/cli/php] Error 1
解决:
安装libiconv: #wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz #tar -zxvf libiconv-1.13.1.tar.gz #cd libiconv-1.13.1 # ./configure --prefix=/usr/local/libiconv # make # make install 编译PHP添加参数: 再检查php,指定 iconv的位置 --with-iconv=/usr/local/libiconv #./configure --prefix=/usr/local/php72 --with-iconv=/usr/local/libiconv #make #make install
2. error:Please reinstall the BZip2 distribution
yum install bzip2 bzip2-devel
3. configure: error: cURL version 7.10.5 or later is required to compile php with cURL support
yum -y install libcurl libcurl-devel