在Linux Centos7下编译安装PHP7.3.11(nginx)

精帖 276
一讯
一讯 2020-02-28 13:36:50
土匪头子

1、下载PHP7.3.11的安装包解压,编译,安装:

cd /usr/src/
wget 
tar -xzxvf php-7.3.11.tar.gz
cd php-7.3.11

    注意事项:

        请检查是否安装了gcc ,没有的话执行yum install -y make cmake gcc gcc-c++(需要换成其他yum源)

        请检查是否安装了openssl,没有的话执行yum install -y openssl openssl-devel

        请检查是否安装了libxml2 ,没有的话执行yum install libxml2 

        请检查是否安装了libxml2-devel,没有的话执行yum install libxml2-devel

        注:因为改为用nginx了,所以编译参数中的--with-apxs2=/usr/bin/apxs去掉了,如果要配置apache用,安装PHP前,请先安装apache。

2、编译参数配置

./configure --prefix=/usr/local/php/php7.3.11 --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl  --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr  --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu/ --enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-iconv --with-xpm-dir=/usr

3、错误集合

报错 Cannot find OpenSSL's <evp.h>
 执行 yum install openssl openssl-devel
报错 Please reinstall the libcurl distribution
 执行 yum -y install curl-devel
错误 jpeglib.h not found
 执行 yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
 和执行 yum install libjpeg-devel
错误:checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution 这是bzip2软件包没有安装
 执行 yum install bzip2-devel.x86_64 -y
错误:configure: error: xpm.h not found.
 执行 yum install libXpm-devel
错误: Unable to locate gmp.h
 执行 yum install gmp-devel
错误:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works
 执行 yum install -y icu libicu libicu-devel
错误:mcrypt.h not found. Please reinstall libmcrypt.
 执行 yum install php-mcrypt libmcrypt libmcrypt-devel
错误: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
 执行 yum install postgresql-devel
错误: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
 执行 yum install libxslt-devel
错误: configure: error: Please reinstall the libzip distribution
  执行 yum install libzip-devel
错误: checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
    请查看http://www.zunkr.com/article/61

错误处理

错误:  configure: error: off_t undefined; check your library configuration


off_t 类型是在 头文件 unistd.h中定义的,
在32位系统 编程成 long int ,64位系统则编译成 long long int ,
在进行编译的时候 是默认查找64位的动态链接库,
但是默认情况下 centos 的动态链接库配置文件/etc/ld.so.conf里并没有加入搜索路径,
这个时候需要将 /usr/local/lib64 /usr/lib64 这些针对64位的库文件路径加进去。

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

4、编译&&安装

make clean && make && make install

报错

usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

成功输出

Installing phpdbg man page:       /usr/local/php/php7.3.11/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/php7.3.11/bin/
Installing PHP CGI man page:      /usr/local/php/php7.3.11/php/man/man1/
Installing build environment:     /usr/local/php/php7.3.11/lib/php/build/
Installing header files:          /usr/local/php/php7.3.11/include/php/
Installing helper programs:       /usr/local/php/php7.3.11/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php7.3.11/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/php7.3.11/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.7
[PEAR] Console_Getopt - installed: 1.4.2
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.3
[PEAR] PEAR           - installed: 1.10.9
Wrote PEAR system config file at: /usr/local/php/php7.3.11/etc/pear.conf
You may want to add: /usr/local/php/php7.3.11/lib/php to your php.ini include_path
/opt/php-7.3.11/build/shtool install -c ext/phar/phar.phar /usr/local/php/php7.3.11/bin
ln -s -f phar.phar /usr/local/php/php7.3.11/bin/phar
Installing PDO headers:           /usr/local/php/php7.3.11/include/php/ext/pdo/

配置,建立目录

cp php.ini-production /usr/local/php/php7.3.11/lib/php.ini
cp /usr/local/php/php7.3.11/etc/php-fpm.conf.default /usr/local/php/php7.3.11/etc/php-fpm.conf
//创建软连接
ln -s /usr/local/php/php7.3.11/sbin/php-fpm /usr/local/bin

设置环境变量 :修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/php/php7.3.11/bin/
export PATH

然后执行生效命令

source /etc/profile

查看PHP版本信息

php -v
//输出
PHP 7.3.11 (cli) (built: Oct 29 2019 16:04:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies

配置PHP-fpm

cp /usr/local/php/php7.3.11/etc/php-fpm.d/www.conf.default /usr/local/php/php7.3.11/etc/php-fpm.d/www.conf
cp /opt/php-7.3.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动php-fpm

/etc/init.d/php-fpm start

如果出现错误:ERROR: [pool www] cannot get uid for user 'www-data'则新建www-data 用户组:

groupadd www-data
useradd -g www-data www-data

重启php-fpm

/etc/init.d/php-fpm restart

测试安装成功

mkdir -p /home/www/wwwroot/php
cd /home/www/wwwroot/php
vim test.php

测试代码

<?php
 
phpinfo();
 
?>