编译遇到的问题很多。网上的文章往往是记录遇到的报错,贴上对应的解决。

而实际的环境,如操作系统,安装的软件必然有差异,所以,更重要的是,如何找到解决方法(不担保按步骤做可以编译成功),并将过程自动化。

安装php-dev

apt-get install php5-dev

安装phpize、autoconf、php-config等configure安装需要的命令

configure 安装三步曲 (configure,make,install三步)

先进入php源码目录

  • ./buildconf --force
  • configure
  • make -j4
  • make install

获得php原configure参数

因为要替换包安装的的php,首先获得configure参数

php-config --configure-options
xxxx@xxxx:/etc/php5/apache2$ php-config --configure-options
--prefix=/usr --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/apache2 --with-config-file-scan-dir=/etc/php5/apache2/conf.d --build=x86_64-linux-gnu --host=x86_64-linux-gnu --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --disable-debug --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --with-pear=/usr/share/php --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-db4 --with-qdbm=/usr --without-gdbm --with-iconv --enable-exif --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex=/usr --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --with-system-tzdata --with-mysql-sock=/var/run/mysqld/mysqld.sock --enable-dtrace --without-mm --with-curl=shared,/usr --with-enchant=shared,/usr --with-zlib-dir=/usr --with-gd=shared,/usr --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-vpx-dir=shared,/usr --with-imap=shared,/usr --with-imap-ssl --enable-intl=shared --without-t1lib --with-ldap=shared,/usr --with-ldap-sasl=/usr --with-mcrypt=shared,/usr --with-mysql=shared,/usr --with-mysqli=shared,/usr/bin/mysql_config --with-pspell=shared,/usr --with-unixODBC=shared,/usr --with-recode=shared,/usr --with-xsl=shared,/usr --with-snmp=shared,/usr --with-sqlite3=shared,/usr --with-mssql=shared,/usr --with-tidy=shared,/usr --with-xmlrpc=shared --with-pgsql=shared,/usr PGSQL_INCLUDE=/usr/include/postgresql --enable-pdo=shared --without-pdo-dblib --with-pdo-mysql=shared,/usr --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-pgsql=shared,/usr/bin/pg_config --with-pdo-sqlite=shared,/usr --with-pdo-dblib=shared,/usr --with-interbase=shared,/usr --with-pdo-firebird=shared,/usr build_alias=x86_64-linux-gnu host_alias=x86_64-linux-gnu CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -O2 -Wall -fsigned-char -fno-strict-aliasing -g LDFLAGS=-Wl,-z,relro CPPFLAGS=-D_FORTIFY_SOURCE=2 CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security

configure 常见错误

bison版本问题

configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 3.0, min: 204, excluded: 3.0).
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: bison is required to build PHP/Zend when building a GIT checkout!
vim configure
line:5268
bison_version_exclude=""

php-config 生成参数包含 -O2 等 configure 不支持的参数

configure: error: unrecognized option: `-O2'

看起来是php-config生成的结果不能直接传入configure,把 CFLAGS 后的参数全部去掉。去掉--disable-debug,加上--enable-debug --enable-mysqlnd=shared——自己编译的目的就是打开调试。

没有装安装包、或有安装对应的包,但路径不对

此类报错数量非常多,总结一下:

  • 一般情况下,可以google报错信息。
  • 查看config.log config.m4 中的内容。找到包名,在https://packages.debian.org/search搜索
  • find 命令查找缺失的文件,看configure命令指定的路径,ln解决

具体报错

  • configure: error: Cannot find sys/sdt.h which is required for DTrace support
xxxx@xxxx:~$ sudo apt-get install systemtap-sdt-dev
  • configure: error: DBA: Could not find necessary header file(s).
xxxx@xxxx:~/workspace/php-src-php-5.6.30$ find . -name "*.m4" | xargs grep "DBA: Could not find necessary " -n
./ext/dba/config.m4:32: AC_MSG_ERROR([DBA: Could not find necessary header file(s).])
./ext/dba/config.m4:35: AC_MSG_ERROR([DBA: Could not find necessary library.])
./ext/dba/config.m4:235: AC_MSG_ERROR([DBA: Could not find necessary header file(s).])
./ext/dba/config.m4:299: AC_MSG_ERROR([DBA: Could not find necessary library.])
// 得知需要找到 db4,qdbm的package,可以在
// https://packages.debian.org/search?suite=default&section=all&arch=amd64&searchon=names&keywords=db4
// 搜索并安装
xxxx@xxxx:~$ wget http://security.debian.org/debian-security/pool/updates/main/d/db4.8/db4.8-util_4.8.30-12+deb7u1_amd64.deb
xxxx@xxxx:~$ sudo dpkg -i db4.8-util_4.8.30-12+deb7u1_amd64.deb
仍然不行,干掉
--with-db4=/usr --with-qdbm=/usr --without-gdbm
  • configure: error: Unable to find gd.h anywhere under /usr
xxxx@xxxx:~$ sudo find / -name "gd.h"
/home/xxxx/workspace/php-src-php-5.6.30/ext/gd/libgd/gd.h
将--with-gd=shared,/usr 改为--with-gd=shared
  • configure: error: Unable to locate gmp.h
xxxx@xxxx:~$ sudo find / -name "gmp.h"
/usr/include/x86_64-linux-gnu/gmp.h
xxxx@xxxx:~$ sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
  • configure: error: libgds, libib_util or libfbclient not found! Check config.log for more information.
搜索得到
jessie (oldstable) (libs): Firebird client library
2.5.3.26778.ds4-5+deb8u1: amd64
xxxx@xxxx:~/deb$ wget http://ftp.cn.debian.org/debian/pool/main/f/firebird2.5/libfbclient2_2.5.3.26778.ds4-5+deb8u1_amd64.deb
xxxx@xxxx:~/deb$ sudo dpkg -i libfbclient2_2.5.3.26778.ds4-5+deb8u1_amd64.deb
xxxx@xxxx:/usr/lib$ sudo apt-get install firebird-dev
仍然报错,查看config.log
/usr/bin/ld: cannot find -lfbclient
xxxx@xxxx:/usr/lib$ sudo find / -name "libfbclient.so*"
/usr/lib/x86_64-linux-gnu/libfbclient.so.2.5.3
/usr/lib/x86_64-linux-gnu/libfbclient.so.2
xxxx@xxxx:/usr/lib$ sudo ln -s /usr/lib/x86_64-linux-gnu/libfbclient.so.2.5.3 /usr/lib/libfbclient.so
  • configure: error: Cannot find ldap libraries in /usr/lib.
xxxx@xxxx:/usr/lib$ sudo ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so
  • configure: error: oniguruma.h not found in /usr/include
sudo apt-get install libonig-dev
gem install oniguruma
  • configure: error: Cannot find FreeTDS in known installation directories
sudo apt-get install freetds-dev
  • configure: error: Could not find /usr/lib/libsybdb.a|so
xxxx@xxxx:~$ sudo ln -s /usr/lib/x86_64-linux-gnu/libsybdb.so /usr/lib/libsybdb.so
  • checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!
xxxx@xxxx:/usr/lib$ sudo apt-get install unixODBC-dev
  • xxxx@xxxx:/usr/lib$ sudo apt-get install libpspell-dev
configure: error: Cannot find pspell
  • configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.
xxxx@xxxx:/usr/lib$ sudo apt-get install librecode-dev
  • configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
xxxx@xxxx:~$ sudo apt-get install libsnmp-dev
  • configure: error: Cannot find libtidy
xxxx@xxxx:/usr/lib$ sudo apt-get install libtidy-dev
  • configure: error: recode extension can not be configured together with: imap
去掉imap

安装php5-redis拓展

获得php5-redis版本

xxxx@xxxx:~/my_code/c++$ sudo apt-show-versions php5-redis
php5-redis:amd64/jessie 2.2.5-1 uptodate

下载php5-redis并安装

xxxx@xxxx:~/workspace/php-src-php-5.6.30/ext$ wget https://github.com/phpredis/phpredis/archive/2.2.5.tar.gz
xxxx@xxxx:~/workspace/php-src-php-5.6.30/ext$ tar -xf 2.2.5.tar.gz
xxxx@xxxx:~/workspace/php-src-php-5.6.30/ext/phpredis-2.2.5$ phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
./configure && make -j4 && sudo make install

当然不可能那么顺利

xxxx@xxxx:~$ php --ini
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226-debug/redis.so' - /usr/lib/php/20131226-debug/redis.so: cannot open shared object file: No such file or directory in Unknown on line 0
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20131226/

怀疑phpize使用的配置和编译安装的不一致

xxxx@xxxx:~/workspace/php-src-php-5.6.30/ext/phpredis-2.2.5$ which phpize
/usr/local/bin/phpize
xxxx@xxxx:~/workspace/php-src-php-5.6.30$ cat /usr/local/bin/phpize | grep local
prefix='/usr/local'
datarootdir='/usr/local/php'
aclocal.m4 config.h config.h.in conftest* ltmain.sh libtool config.cache autom4te.cache/ \
(cd "$builddir" && cat acinclude.m4 ./build/libtool.m4 > aclocal.m4)
-e "s#/usr/local#$prefix#" \

尝试将phpize中的local都去掉。仍然不行。最后将php-redis拓展和php一同编译。

最后的configure命令

./configure --prefix=/usr --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/etc/php5/apache2 --with-config-file-scan-dir=/etc/php5/apache2/conf.d --build=x86_64-linux-gnu --host=x86_64-linux-gnu --sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man --with-regex=php --disable-rpath --disable-static --with-pic --with-layout=GNU --with-pear=/usr/share/php --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype  --with-iconv --enable-exif --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex=/usr --enable-json=shared --enable-shmop --enable-sockets --enable-wddx --with-libxml-dir=/usr --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --with-mysql-sock=/var/run/mysqld/mysqld.sock --enable-dtrace --without-mm --with-curl=shared,/usr --with-enchant=shared,/usr --with-zlib-dir=/usr --with-gd=shared --enable-gd-native-ttf --with-gmp=shared,/usr --with-jpeg-dir=shared,/usr --with-xpm-dir=shared,/usr/X11R6 --with-png-dir=shared,/usr --with-freetype-dir=shared,/usr --with-vpx-dir=shared,/usr --enable-intl=shared --without-t1lib --with-ldap=shared,/usr --with-ldap-sasl=/usr --with-mcrypt=shared --with-mysql=shared,/usr --with-mysqli=shared --with-pspell=shared,/usr --with-unixODBC=shared,/usr --with-recode=shared,/usr --with-xsl=shared,/usr --with-snmp=shared,/usr --with-sqlite3=shared,/usr --with-mssql=shared,/usr --with-tidy=shared,/usr --with-xmlrpc=shared --with-pgsql=shared,/usr PGSQL_INCLUDE=/usr/include/postgresql --enable-pdo=shared --without-pdo-dblib --with-pdo-mysql=shared,/usr --with-pdo-odbc=shared,unixODBC,/usr --with-pdo-pgsql=shared,/usr/bin/pg_config --with-pdo-sqlite=shared,/usr --with-pdo-dblib=shared,/usr --with-interbase=shared --with-pdo-firebird=shared build_alias=x86_64-linux-gnu host_alias=x86_64-linux-gnu --enable-debug --enable-mysqlnd=shared --with-readline=shared --enable-redis=shared

至此,已经可以成功编译出debug版的php以及所需的拓展:

(gdb) b mysqli_api.c:php_mysqli_init
Breakpoint 1 at 0x7f6c64c89d02: file /home/xxxx/workspace/php-src-php-5.6.30/ext/mysqli/mysqli_api.c, line 1540.
(gdb) c
Continuing. Breakpoint 1, php_mysqli_init (ht=0, return_value=0x7f6c71dbe4c0, return_value_ptr=0x7f6c713c8d88, this_ptr=0x0, return_value_used=1)
at /home/xxxx/workspace/php-src-php-5.6.30/ext/mysqli/mysqli_api.c:1540
1540 if (getThis() && ((mysqli_object *) zend_object_store_get_object(getThis() TSRMLS_CC))->ptr) {
(gdb) bt
#0 php_mysqli_init (ht=0, return_value=0x7f6c71dbe4c0, return_value_ptr=0x7f6c713c8d88, this_ptr=0x0, return_value_used=1)
at /home/xxxx/workspace/php-src-php-5.6.30/ext/mysqli/mysqli_api.c:1540
#1 0x00007f6c64c89eba in zif_mysqli_init (ht=0, return_value=0x7f6c71dbe4c0, return_value_ptr=0x7f6c713c8d88, this_ptr=0x0, return_value_used=1)
at /home/xxxx/workspace/php-src-php-5.6.30/ext/mysqli/mysqli_api.c:1577

遇到的Call to undefined function mysqli_init()

有mysqli.so,nm看mysqli.so也有对应的接口,看进程有无加载

xxxx@xxxx:/usr/lib/php/20131226-debug$ sudo cat /proc/12931/maps | grep mysql
xxxx@xxxx:/usr/lib/php/20131226-debug$ sudo cat /proc/12931/maps | grep libphp5
7f0a68002000-7f0a68ad3000 r-xp 00000000 fd:00 33711 /usr/lib/apache2/modules/libphp5.so
7f0a68ad3000-7f0a68cd2000 ---p 00ad1000 fd:00 33711 /usr/lib/apache2/modules/libphp5.so
7f0a68cd2000-7f0a68d90000 rw-p 00ad0000 fd:00 33711 /usr/lib/apache2/modules/libphp5.so
xxxx@xxxx:/etc/p5/apache2$ php --ini
Configuration File (php.ini) Path: /etc/php5/apache2
Loaded Configuration File: /etc/php5/apache2/php.ini
Scan for additional .ini files in: /etc/p5/apache2/conf.d

不知道p5哪里来的

最后find到

Binary file /usr/lib/apache2/modules/libphp5.so matches
Binary file /usr/bin/php matches
/usr/include/php/main/build-defs.h:90:#define PHP_CONFIG_FILE_SCAN_DIR "/etc/p5/apache2/conf.d"

说明是编译期间传入的。

打开build-defs.h发现自己传入了'--with-config-file-scan-dir=/etc/p5/apache2/conf.d'

改完后重新编译安装

xxxx@xxxx:~$ php --ini
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226-debug/redis.so' - /usr/lib/php/20131226-debug/redis.so: cannot open shared object file: No such file or directory in Unknown on line 0
Configuration File (php.ini) Path: /etc/php5/apache2
Loaded Configuration File: /etc/php5/apache2/php.ini
Scan for additional .ini files in: /etc/php5/apache2/conf.d
Additional .ini files parsed: /etc/php5/apache2/conf.d/05-opcache.ini,
/etc/php5/apache2/conf.d/10-mysqlnd.ini,
/etc/php5/apache2/conf.d/10-pdo.ini,
/etc/php5/apache2/conf.d/20-curl.ini,
/etc/php5/apache2/conf.d/20-json.ini,
/etc/php5/apache2/conf.d/20-mcrypt.ini,
/etc/php5/apache2/conf.d/20-mysql.ini,
/etc/php5/apache2/conf.d/20-mysqli.ini,
/etc/php5/apache2/conf.d/20-pdo_mysql.ini,
/etc/php5/apache2/conf.d/20-readline.ini,
/etc/php5/apache2/conf.d/20-redis.ini

参考

http://fivezh.github.io/2016/08/02/PHP-Nginx-Memcached-Redis-configuration/

https://www.crybit.com/20-common-php-compilation-errors-and-fix-unix/

Debian GNU/Linux 8.4 (jessie)编译安装php.md的更多相关文章

  1. 大神教你Debian GNU/Linux 9.7 “Stretch” Live和安装镜像开放下载

    Debian项目团队于昨天发布了Debian GNU/Linux 9 "Stretch" 的第7个维护版本更新,重点修复了APT软件管理器中存在的安全漏洞.在敦促每位用户尽快升级系 ...

  2. ZFS(一):ZFS在Debian GNU/Linux上的安装

    以下内容翻译自https://pthree.org/2012/04/17/install-zfs-on-debian-gnulinux/,并附有原文,由于是第一次翻译,如有任何翻译不恰当之处,欢迎指出 ...

  3. Debian系统中当安装deb软件时出现:deb cdrom:[Debian GNU/Linux 9.3.0 _Stretch_ - Official amd64 DVD Binary-1 20171209-12:11]/ stretch contrib main

    vi /etc/apt/sources.list // 注释掉下面这句话# deb cdrom:[Debian GNU/Linux 9.3.0 _Stretch_ - Official amd64 D ...

  4. debian7 请把标有“Debian GNU/Linux 7.1.0 _Wheezy_ - Official amd64 DVD Binary-1 20130615-23:06”的盘片插入驱动器“/media/cdrom/”再按回车键

    有时候,在通过apt-get install 安装软件的时候,会出现: 更换介质:请把标有“Debian GNU/Linux 7.1.0 _Wheezy_ - Official amd64 DVD B ...

  5. Linux下指定版本编译安装LAMP

    说明: 操作系统:CentOS 6.5 64位 需求: 编译安装LAMP运行环境 各软件版本如下: MySQL:mysql-5.1.73 Apache:httpd-2.2.31 PHP:php-5.2 ...

  6. Linux 从源码编译安装 OpenSSH

    https://blog.csdn.net/bytxl/article/details/46639073 Linux 从源码编译安装 OpenSSH以及各问题解决 2015年06月25日 17:37: ...

  7. Debian GNU Linux服务列表的获取、服务的关闭/开启、服务在启动时是否自己主动执行的生效/失效

    /*********************************************************************  * Author  : Samson  * Date   ...

  8. 【转载】Linux升级NTPD服务器-编译安装ntp-4.2.8p12与配置

    [转载]Linux升级NTPD服务器-编译安装ntp-4.2.8p12与配置 1. 系统与软件版本 1.1 系统版本 rhel6.4(Red Hat Enterprise Linux Server r ...

  9. PCL库在Linux环境下的编译安装

    PCL库在Linux环境下的编译安装 PCL库的源码库:https://github.com/PointCloudLibrary/pcl 下载完了之后解压下来 编译库的几个步骤 mkdir build ...

随机推荐

  1. 201521123092《java程序设计》第十三周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 2.1. 网络基础 1.1 比较ping www.baidu.com与ping cec.j ...

  2. 201521123016 《Java学习笔记》 第11周学习总结

    1. 本周学习总结 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synchronized修饰方法实现互斥同步访问, ...

  3. Java: 类继承中 super关键字

    super 关键字的作用有两个: 1)在子类中调用超类的构造器,完成实例域参数的初始化,调用构造器的语句只能作为另一个构造器(通常指的是子类构造器)的第一条语句出现, 2)在子类中调用超类的方法,如: ...

  4. 西邮linux兴趣小组2014纳新免试题(五)

    [第五关] 题目 http://final5.sinaapp.com/ 关注西邮Linux微信平台,得到一个名为a的文件 分析 分析文件a 需要反汇编,拿IDA上,打开后发现key_function及 ...

  5. 常用git指令

    git checkout -b newBranchName //与当前分支内容相同! git checkout -b 本地分支 origin xxx//远程分支 在本地新建一个分支,并把远程分支的代码 ...

  6. [js高手之路] html5 canvas系列教程 - 像素操作(反色,黑白,亮度,复古,蒙版,透明)

    接着上文[js高手之路] html5 canvas系列教程 - 状态详解(save与restore),相信大家都应该玩过美颜功能,而我们今天要讲的就是canvas强大的像素处理能力,通过像素处理,实现 ...

  7. Linux入门之常用命令(11) 系统监控 vmstat top

    vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ...

  8. 超级密码 hdu1226 bfs

    超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. .Net 内存对象分析

    在生产环境中,通过运行日志我们会发现一些异常问题,此时,我们不能直接拿VS远程到服务器上调试,同时日志输出的信息无法百分百反映内存中对象的状态,比如说我们想查看进程中所有的Socket连接状态.服务路 ...

  10. Docker 最常用的监控方案 - 每天5分钟玩转 Docker 容器技术(78)

    当 Docker 部署规模逐步变大后,可视化监控容器环境的性能和健康状态将会变得越来越重要. 在本章中,我们将讨论几个目前比较常用的容器监控工具和方案,为大家构建自己的监控系统提供参考. 首先我们会讨 ...