在CentOS下编译PHP 7的过程中遇到很多错误,在此做个笔记,也供网友参考。总的来说是编译的时候报错,先看编译log,缺少什么依赖,然后安装相应依赖包,重新编译。
编译环境
- OS:
shell> cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
- gcc
shell> gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
Copyright (C) 2010 Free Software Foundation, Inc.
- autoconf
shell> autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
- make
shell> make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
安装依赖
sudo yum install git gcc gcc-c++ libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel
编译
- 下载php源码发布包:
shell> wget https://www.php.net/distributions/php-7.3.5.tar.gz
shell>tar zxvf php-7.3.5.tar.gz
- 设置编译选项
可以先通过./configure --help
查看编译选项,由于编译选项比较多,放到build.sh脚本中:
shell> cat build.sh
#!/bin/bash
./buildconf --force
./configure --prefix=/home/dev/opt/php7 \
--with-config-file-path=/home/dev/opt/php7/etc \
--with-config-file-scan-dir=/home/dev/opt/php7/etc/conf.d \
--enable-bcmath \
--with-bz2 \
--with-curl \
--enable-filter \
--enable-fpm \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-intl \
--enable-mbstring \
--enable-mysqlnd \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pdo-sqlite \
--disable-phpdbg \
--disable-phpdbg-webhelper \
--enable-opcache \
--with-openssl \
--enable-simplexml \
--with-sqlite3 \
--enable-xmlreader \
--enable-xmlwriter \
--enable-zip \
--with-zlib \
--disable-fileinfo
- 编译
shell> chmod +x build.sh
shell> sh build.sh
shell> make & make install
编译错问题整理
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
我的机器内存比较小,编译的时候内存耗尽直接被系统kill掉了。使用交换分区创建一个2G的内存了。
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile
# 编译完了再释放掉
sudo swapoff /swapfile
sudo rm /swapfileile
同时在编译选项中加入--disable-fileinfo
禁用fileinfo,见上面build.sh脚本。
buildconf: autoconf version 2.63 found.
You need autoconf version 2.68 or newer installed to build PHP from Git.
make: *** [buildmk.stamp] Error 1
# autoconf版本太低,需要升级一下,yum源没有更高版本,采用源码安装:
shell> curl -L -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
shell> tar zxvf autoconf-2.69.tar.gz
shell> cd autoconf-2.69
shell> ./configure --prefix=/usr
shell> make
shell> sudo make install
configure: error: Please reinstall the BZip2 distribution
#缺少bzip2库,使用yum安装:
shell>sudo yum install bzip2 bzip2-devel
configure: error: jpeglib.h not found.
# 缺少jpeglib库,使用yum安装:
shell>sudo yum install libjpeg libjpeg-devel
configure: error: png.h not found.
# 缺少libpng库,使用yum安装
shell>sudo yum install libpng libpng-devel
configure: error: freetype-config not found.
# 缺少freetype,采用yum安装
shell> sudo yum install freetype freetype-devel
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
#可以使用yum安装
shell> sudo yum install icu icu-devel
#也可以使用源码安装
shell> wget http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-src.tgz
shell> tar zxvf icu4c-56_1-src.tgz
shell> cd icu/source
shell> ./configure --prefix=/usr/local
shell> make
shell> sudo make install
#需要注意,源码安装icu到/usr/local下,上面build.sh脚本需要手动指定icu的安装目录`--with-icu-dir=/usr/local`
configure: error: Please reinstall the libzip distribution
#安装libzip库
shell> sudo yum install libzip libzip-devel
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
#libzip的版本过低,yum源没有更高版本,采用源码安装
shell> wget https://nih.at/libzip/libzip-1.2.0.tar.gz
shell> cd libzip-1.2.0
shell> tar zxvf libzip-1.2.0.tar.gz
shell > sudo yum remove libzip
shell> ./configure
shell > make
shell > sudo make install
/usr/local/include/zip.h:59:21: error: zipconf.h: No such file or directory
make: *** [ext/zip/php_zip.lo] Error 1
#找不到/usr/local/include/zip.h,估计是源码安装的时候,没有把zipconf.h文件放到/usr/local/include目录下,手动copy一下:
shell>>cp -v /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
更多参考
3.http://www.manongjc.com/article/28448.html
网友评论