centos7/centos8 PHP7.2/php7.3/php7.4 以上版本 源码安装 编译

yum update  

1、 安装依赖包

[root@centos7_4 ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-servers openldap-clients freetype-devel gmp-devel

2、 下载PHP源码包

[root@centos7_4 ~]# wget http://cn2.php.net/distributions/php-7.2.6.tar.gz

亲测 可以安装php7.4.20   wget http://cn2.php.net/distributions/php-7.4.20.tar.gz

[root@centos7_4 ~]# wget http://cn2.php.net/distributions/php-7.2.6.tar.gz

3、解压压缩包

[root@centos7_4 ~]# tar zxf php-7.2.6.tar.gz -C /usr/local/src/

[root@centos7_4 ~]# cd /usr/local/src/php-7.2.6/

4、 生成配置文件

[root@centos7_4 php-7.2.6]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-mysql-sock=/usr/local/mysql/mysql.sock --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-ldap --with-ldap-sasl --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm  --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --enable-zip --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd 

--with-ldap --with-ldap-sasl \            #如果不添加这两项,要是安装zabbix监控时候,会有提示还得需要再次编译,如果不安装zabbix,也可以忽略

 

configure: error: Cannot find ldap libraries in /usr/lib.       #解决方法

[root@centos7_4 php-7.2.6]# cp -frp /usr/lib64/libldap* /usr/lib/    #在重新配置

关于libxml 或者 libxml-2的报错

可能出现的错误

No package 'libxml-2.0' found

configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:

No package 'libxml-2.0' found

解决方法

yum install libxml2-devel

中途可能需要更新其他的依赖, 确定就可以了

No package 'openssl' found

configure: error: Package requirements (openssl >= 1.0.1) were not met:

No package 'openssl' found

解决方法

yum install openssl-devel

No package 'sqlite3' found

configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

No package 'sqlite3' found

解决方法

yum install sqlite-devel

No package 'libcurl' found

configure: error: Package requirements (libcurl >= 7.15.5) were not met:

No package 'libcurl' found

解决方法

yum install libcurl-devel

Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met

configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:

No package 'icu-uc' found
No package 'icu-io' found
No package 'icu-i18n' found

解决方法

yum install libicu-devel

configure: error: C++ preprocessor "/lib/cpp" fails sanity check

checking whether g++ accepts -g... no
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/data/programs/php-7.4.7':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details

解决方法, 缺少g++库, 安装

yum install gcc-c++

No package 'oniguruma' found

configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

 

如果启用了--with-mbstring,则需要安装 oniguruma, 因为7.4的正则表达式使用了oniguruma

解决方法

yum install oniguruma oniguruma-devel

No package 'libxslt' found

configure: error: Package requirements (libxslt >= 1.1.0) were not met:

No package 'libxslt' found

--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件

解决方法

yum install libxslt-devel

No package 'libpng' found

configure: error: Package requirements (libpng) were not met:

No package 'libpng' found

解决方法

yum install libpng-devel

No package 'libjpeg' found

configure: error: Package requirements (libjpeg) were not met:

No package 'libjpeg' found

解决方法

yum install libjpeg-devel

No package 'freetype2' found

configure: error: Package requirements (freetype2) were not met:

No package 'freetype2' found

解决方法

yum install freetype-devel

No package 'libzip' found

configure: error: Package requirements (libzip >= 0.11) were not met:

No package 'libzip' found

解决方法

这里不使用软件仓库中的libzip, 也就是不使用yum install libzip-devel,
因为版本不够, 安装方法看下面一条

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

这是因为软件仓库的libzip版本过低, 需要手动编译安装

# 先删除原有的libzip
yum remove -y libzip
# 下载并手动编译安装, 自己下载到合适的位置
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
# 更新依赖路径, centos版本小于8的,一定要执行下面这个命令,不然还是找不到 libzip
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
# 上面一行的代码参考自 https://wujie.me/centos7-3-compile-and-install-php-7-4-1/

configure: error: GNU MP Library version 4.2 or greater required

yum -y install gmp-devel 

configure: error: Please reinstall readline - I cannot find readline.h

yum -y install readline-devel

configure: error: Cannot find ldap.h 

yum install openldap openldap-devel  -y

configure: error: Cannot find ldap libraries in /usr/lib 

cp -frp /usr/lib64/libldap* /usr/lib/

configure: error: Package requirements (oniguruma) were not met:  

centos   7 :

yum install oniguruma-devel


centos 81. wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
    2. tar -zxf oniguruma-6.9.4.tar.gz
    3. cd oniguruma-6.9.4
    4. ./autogen.sh && ./configure --prefix=/usr
--------------------------------
此处如果遇到 ./autogen.sh: line 6: autoreconf: command not found

       --> yum  -y  install autoconf automake libtool

--------------------------------
5. make && make install

./autogen.sh: line 6: autoreconf: command not found

yum  -y  install autoconf automake libtool

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation. 

yum -y install net-snmp-devel

 

5、 编译并安装

[root@centos7_4 php-7.2.6]# make

/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup'

/usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

make: *** [sapi/cli/php] Error 1

 

[root@centos7_4 php-7.2.6]# vim Makefile      #在以EXTRA_LIBS开头的一行结尾添加‘-llber’

EXTRA_LIBS = -lcrypt -lz -lresolv -lcrypt -lrt -lldap -lgmp -lpng -lz -ljpeg -lz -lrt -lm -ldl -lnsl -lpthread -lxml2 -lz -lm -ldl -lssl -lcrypto -lcurl -lxml2 -lz -lm -ldl -lssl -lcrypto -lfreetype -lxml2 -lz -lm -ldl -lnetsnmp -lssl -lssl -lcrypto -lm -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lssl -lcrypto -lcrypt -llber

[root@centos7_4 php-7.2.6]# make

[root@centos7_4 php-7.2.6]# echo $?    

0

[root@centos7_4 php-7.2.6]# make install

[root@centos7_4 php-7.2.6]# echo $?    

0

6、 配置php配置文件

移动php配置文件的位置,并修改名称

[root@centos7_4 php-7.2.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.conf

复制php.ini文件

[root@centos7_4 php-7.2.6]# cp /usr/local/src/php-7.2.6/php.ini-production /usr/local/php/etc/php.ini

7、 复制php启动脚本到/etc/init.d/

[root@centos7_4 php-7.2.6]# cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

添加执行权限,添加到启动项并设置卡机启动

[root@centos7_4 php-7.2.6]# chmod +x /etc/init.d/php-fpm

[root@centos7_4 php-7.2.6]# chkconfig --add php-fpm

[root@centos7_4 php-7.2.6]# chkconfig php-fpm on

启动php-fpm

[root@centos7_4 ~]# /etc/init.d/php-fpm start

Starting php-fpm  done

 

[root@centos7_4 ~]# vim /usr/local/nginx/conf/nginx.conf

43         location / {

44             root   html;

45             index  index.php index.html index.htm;

46         }

[root@centos7_4 ~]# service nginx restart     #重启nginx服务

 

编写php探测文件

[root@centos7_4 ~]# vim /usr/local/nginx/html/index.php

<?php

        phpinfo();

?>

[root@centos7_4 ~]# netstat -antup|grep php-fpm

tcp    0    0 127.0.0.1:9000      0.0.0.0:*      LISTEN    128974/php-fpm: mas

 

posted @ 2019-10-21 18:11  黑锦鲤  阅读(1186)  评论(0编辑  收藏  举报