1、进入php官网下载
2、使用FTP工具把下载好的包传至 /usr/src 下
3、cd /usr/src
tar -zxvf php-7.3.16.tar.gz
4、安装gcc,gcc-c++,kernel-devel
[root@localhost src]# yum -y install gcc gcc-c++ kernel-devel
5、安装php需要的依赖库
yum -y install wget pcre pcre-devel openssl openssl-devel libicu-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 \ libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap \ openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel \ gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline \ readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
6、创建用户和组
[root@localhost src]# groupadd www [root@localhost src]# useradd -g www www
7、进行编译安装
cd /usr/src/php-7.3.16
[root@localhost php-7.3.16]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--disable-fileinfo \
--enable-fpm \
--with-config-file-scan-dir=/usr/local/php/php.d \
--with-openssl \
--with-zlib \
--with-curl \
--enable-ftp \
--with-gd \
--with-xmlrpc \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--enable-mbstring \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--without-pear \
--enable-bcmath
./configure可能遇到的问题
1、configure: error: DBA: Could not find necessary header file(s).
安装下 yum install gdbm-devel
2、configure: error: Cannot find ldap libraries in /usr/lib.
解决办法:
cp -frp /usr/lib64/libldap* /usr/lib/
3、configure: error: Please reinstall the libzip distribution
(1)移除旧的libzip:
yum remove libzip
(2)安装新版本:
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
4、configure: WARNING: unrecognized options: --with-mcrypt, --with-libmbfl, --enable-gd-native-ttf
说明上面的配置参数已经弃用了,删除即可。
8、
[root@localhost php-7.3.16]# make && make install
1、make: *** [ext/zip/php_zip.lo] Error 1
vi /etc/ld.so.conf.d/local.conf //创建local.conf
/usr/local/lib //添加输入
ldconfig -v //执行命令
必须先make clean 再make,不然也会跑错
2、make: *** [sapi/cli/php] Error 1
vi Makefile
解决方法:编辑Makefile 大约109行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。
编译好Makefile后,记得先make clean一下,再make,不然会报错
9、配置php.ini 文件
[root@localhost php-7.3.16]# cp php.ini-development /usr/local/php/etc/php.ini
[root@localhost php-7.3.16]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
root@localhost php-7.3.16]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
配置php.ini文件
[root@localhost php-7.3.16]# vi /usr/local/php/etc/php.ini
date
.timezone = PRC
extension_dir =
"/usr/local/php/include/php/ext"
10、配置Systemd服务
[root@localhost php-7.3.16]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
启用php-fpm.service
[root@localhost php-7.3.16]# systemctl enable php-fpm.service
启动php-fpm
[root@localhost php-7.3.16]# systemctl start php-fpm.service [root@localhost php-7.3.16]# systemctl status php-fpm.service
OK