PHP7.4编译

一、下载php7安装包放至选定目录

cd /usr/local/src

wget https://www.php.net/distributions/php-7.4.8.tar.xz


二、解压包并创建用户和组

tar Jxvf php-7.4.8.tar.xz

groupadd php-fpm

useradd -r -g php-fpm -s /sbin/nologin php-fpm


三、安装依赖包

1、直接yum安装

yum  install -y  bzip2-devel  libtool  libpng-devel  libxslt-devel   libjpeg-devel   freetype-devel    libicu-devel    gcc  gcc-c++    openldap-devel    libzip-devel  sqlite-devel


2、手动安装

1)编译安装libzip包(centos7自带的是0.10版本,编译环境需要0.10版本以上但不包含1.3和1.7版本的包)

yum remove libzip  libzip-devel -y

wget https://libzip.org/download/libzip-1.2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0

./configure

make && make install

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"


2)下载安装oniguruma5phponiguruma5php-devel

##若无网络,可通过网址将两个包下载到本地再上传服务器,通过(rpm -ivh  包名)进行本地安装

yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.5+rev1-2.el7.remi.x86_64.rpm

yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.5+rev1-2.el7.remi.x86_64.rpm


四、开始编译

cd php-7.4.8

./configure  --prefix=/usr/local/php

--with-config-file-path=/usr/local/php/etc/ --with-fpm-user=php-fpm

--with-fpm-group=php-fpm --enable-fpm --enable-opcache

--enable-inline-optimization --disable-debug --disable-rpath

--enable-shared -enable-mysqlnd --with-mysqli=mysqlnd

--with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support

--with-iconv-dir --with-zlib --enable-xml --disable-rpath

--enable-bcmath --enable-shmop --enable-sysvsem

--enable-inline-optimization --with-curl --enable-mbregex

--enable-mbstring --enable-intl --enable-ftp --enable-gd

--enable-gd-jis-conv --with-jpeg   --with-freetype  --with-openssl

--with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-zip

--enable-soap --with-gettext --disable-fileinfo --with-pear

--enable-maintainer-zts --with-ldap=shared --without-gdbm

--with-libdir=lib64

echo $?     #查看上条命令是否执行成功(返回0表示成功,其它则有报错)   

make && make install          #安装php目录

echo $?


五、配置php的文件环境

cp php.ini-production  /usr/local/php/etc/php.ini

cp sapi/fpm/init.d.php-fpm /etc/init.d/php

cd /usr/local/php/etc/

cp php-fpm.d/php-fpm.conf.default   php-fpm.d/php-fpm.conf

cp www.conf.default www.conf


六、将php启动项添加到服务列表

chkconfig --add php

chkconfig php on

chmod 755 /etc/init.d/php


七、php启动方式

1、/etc/init.d/php start/stop/restart/status 

##php服务启动/停止/重启/查看状态

2、service php start/stop/restart/status   

##php服务启动/停止/重启/查看状态


八、编译报错详解:

1、No package 'oniguruma' found

解决:安装oniguruma5php和oniguruma5php-devel

yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.5+rev1-2.el7.remi.x86_64.rpm

yum install -y http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.5+rev1-2.el7.remi.x86_64.rpm

2、Libtool library used but ‘LIBTOOL’ is undefined

解决:yum install -y libtool

3、checking for BZip2 in default path... not found

解决:yum install -y bzip2-devel

4、No package 'libpng' found

解决:yum install -y libpng-devel

5、No package 'libxslt' found

解决:yum install -y libxslt-devel

6、No package 'libjpeg' found

解决:yum install -y libjpeg-devel

7、No package 'freetype2' found

解决:yum install -y freetype-devel

8、

No package 'icu-uc' found

No package 'icu-io' found

No package 'icu-i18n' found

解决:yum install -y libicu-devel

9、checking whether g++ accepts -g... no

解决:yum install -y gcc  gcc-c++

10、configure: error: Cannot find ldap.h

解决:yum install -y openldap-devel

11、error: Cannot find ldap libraries in /usr/lib

解决:在 ./configure 里添加--with-libdir=lib64选项

12、No package 'libzip' found

解决:yum install -y libzip-devel

13、No package 'sqlite3' found

解决:yum install -y sqlite-devel

14、No package 'libcurl' found

解决:yum install -y libcurl-devel

15、Requested 'libzip >= 0.11' but version of libzip is 0.10.1

解决:下载包手动编译安装0.11版本以上的libzip

yum remove libzip  libzip-devel -y

wget https://libzip.org/download/libzip-1.2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0

./configure

make && make install

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

你可能感兴趣的:(PHP7.4编译)