Centos7 编译安装PHP7.3.2

php编译安装可以让组件配置更灵活,但需要你对php的各种配置非常熟悉,具体的编译参数可以在php解压的路径下执行“./configure  --help”进行详细查看。以下为大致安装流程,可供参考。

安装依赖包

yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel 
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel 
readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel 
ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel 
xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip

下载安装包并解压

wget http://php.net/distributions/php-7.3.2.tar.gz
tar -zxvf php-7.3.2.tar.gz
cd php-7.3.2

编译安装(./configure --help可查看编译参数)

./configure \
 --prefix=/usr/local/php\
 --enable-fpm\
 --with-fpm-user=www\
 --with-fpm-group=www\
 --with-config-file-path=/usr/local/php/conf\
 --disable-rpath\
 --enable-soap\
 --with-libxml-dir\
 --with-xmlrpc\
 --with-openssl\
 --with-mhash\
 --with-pcre-regex\
 --with-zlib\
 --enable-bcmath\
 --with-bz2\
 --enable-calendar\
 --with-curl\
 --enable-exif\
 --with-pcre-dir\
 --enable-ftp\
 --with-gd\
 --with-openssl-dir\
 --with-jpeg-dir\
 --with-png-dir\
 --with-zlib-dir\
 --with-freetype-dir\
 --enable-gd-jis-conv\
 --with-gettext\
 --with-gmp\
 --with-mhash\
 --enable-mbstring\
 --with-onig\
 --with-mysqli=mysqlnd\
 --with-pdo-mysql=mysqlnd\
 --with-zlib-dir\
 --with-readline\
 --enable-shmop\
 --enable-sockets\
 --enable-sysvmsg\
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-wddx\
 --with-libxml-dir\
 --with-xsl\
 --enable-zip\
 --with-pear

注意:如果在配置时报libzip版本太低,请卸载重新安装高版本

完成后,再进行编译及安装,执行 make && make install 即可安装。

注意:如果编译时报:php7 configure: error: off_t undefined; check your library configuration错误,请执行以下操作:

# 添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v

注意:如果编译时报:/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory 错误,请执行以下操作:

在安装完新版的 libzip 时可能会出现打不到 zipconf.h,手动复制一下 
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

安装后配置

执行完安装命令后php7就已经安装在到了/usr/local/php目录下了。

/usr/local/php/bin/php -v

查看安装是否成功。

为了以后方便,可以编辑 /etc/profile 添加环境变量 ,添加到最后面

PATH=$PATH:/usr/local/php/bin
export PATH

然后更新环境变量。

source /etc/profile

查看环境变量

echo $PATH

查看php版本

php -v

配置php-fpm

cp php.ini-production /usr/local/php/conf/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

将php-fpm加入启动服务

cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service

启动php-fpm

systemctl start php-fpm.service

如果报这种错误

Starting php-fpm [2-Feb-2019 21:02:25] ERROR: [pool www] cannot get uid for user 'www'

说明没有该用户,直接执行

groupadd www
useradd -g www www

然后再启动php-fpm

posted @ 2019-02-28 16:11  技术随笔  阅读(862)  评论(0编辑  收藏  举报