jjzjj

php - 如何为 PHP 5.6 构建 mysql 扩展?

coder 2023-10-10 原文

我正在努力并行安装 PHP 5.6 和 7.0,以便于从 PHP 5 迁移到 7。

我正在使用 Ondřej Surý 的 Ubuntu PPA,https://launchpad.net/~ondrej/+archive/ubuntu/php ,它提供可共同安装的 PHP 5.6 和 7.0 版本。

两个 PHP 版本并排工作得很好,但有一个障碍:我无法为 PHP 5.6 构建 mysql 扩展(即使我能够为 7.0 构建它).

(我很清楚 mysql 扩展已经过时,应该放弃它以支持更现代的替代方案。然而,我期望客户的遗留应用程序依赖于它是不合理的在仍然支持 PHP 5.6 的情况下重构他们的代码。所以,我在这件事上别无选择......)

对于不熟悉此可共同安装的 PPA 的任何人,版本号附加到二进制文件,因此各种 PHP 可执行文件的路径如下:

# ls -lah /usr/bin | grep "php"
-rwxr-xr-x  1 root   root     13K Dec 31 03:24 dh_php
lrwxrwxrwx  1 root   root      21 Feb 23 09:51 php -> /etc/alternatives/php
-rwxr-xr-x  1 root   root    3.6M Feb 23 06:37 php5.6
-rwxr-xr-x  1 root   root    3.5M Feb 23 06:58 php7.0
lrwxrwxrwx  1 root   root      25 Feb 23 10:06 php-cgi -> /etc/alternatives/php-cgi
-rwxr-xr-x  1 root   root    3.6M Feb 23 06:37 php-cgi5.6
-rwxr-xr-x  1 root   root    3.4M Feb 23 06:58 php-cgi7.0
lrwxrwxrwx  1 root   root      28 Feb 23 10:06 php-config -> /etc/alternatives/php-config
-rwxr-xr-x  1 root   root    4.1K Feb 23 06:37 php-config5.6
-rwxr-xr-x  1 root   root    4.2K Feb 23 06:58 php-config7.0
lrwxrwxrwx  1 root   root      24 Feb 23 10:06 phpize -> /etc/alternatives/phpize
-rwxr-xr-x  1 root   root    4.7K Feb 23 06:37 phpize5.6
-rwxr-xr-x  1 root   root    4.6K Feb 23 06:58 phpize7.0

这是我尝试过的:

# cd ~

# git clone https://git.php.net/repository/pecl/database/mysql.git

# cd mysql

# phpize5.6
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226

# ./configure --with-php-config=/usr/bin/php-config5.6
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20131226 -I/usr/include/php/20131226/main -I/usr/include/php/20131226/TSRM -I/usr/include/php/20131226/Zend -I/usr/include/php/20131226/ext -I/usr/include/php/20131226/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20131226
checking for PHP installed headers prefix... /usr/include/php/20131226
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for MySQL support... yes, shared
checking for specified location of the MySQL UNIX socket... no
checking for the location of libz... no
checking for MySQL UNIX socket location... /var/run/mysqld/mysqld.sock
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) gawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands

到目前为止,还不错。

问题发生在 make 期间。我只包含了一部分输出,因为我确信相同的问题会反复出现。

# make
/bin/sh /root/mysql/libtool --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/mysql -DPHP_ATOM_INC -I/root/mysql/include -I/root/mysql/main -I/root/mysql -I/usr/include/php/20131226 -I/usr/include/php/20131226/main -I/usr/include/php/20131226/TSRM -I/usr/include/php/20131226/Zend -I/usr/include/php/20131226/ext -I/usr/include/php/20131226/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /root/mysql/php_mysql.c -o php_mysql.lo
libtool: compile:  cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/root/mysql -DPHP_ATOM_INC -I/root/mysql/include -I/root/mysql/main -I/root/mysql -I/usr/include/php/20131226 -I/usr/include/php/20131226/main -I/usr/include/php/20131226/TSRM -I/usr/include/php/20131226/Zend -I/usr/include/php/20131226/ext -I/usr/include/php/20131226/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/mysql/php_mysql.c  -fPIC -DPIC -o .libs/php_mysql.o
In file included from /root/mysql/php_mysql.c:63:0:
/root/mysql/php_mysql_structs.h:114:2: error: unknown type name 'zend_resource'
  zend_resource *default_link;
  ^
/root/mysql/php_mysql_structs.h:115:2: error: unknown type name 'zend_long'
  zend_long num_links,num_persistent;
  ^
/root/mysql/php_mysql_structs.h:116:2: error: unknown type name 'zend_long'
  zend_long max_links,max_persistent;
  ^
/root/mysql/php_mysql_structs.h:117:2: error: unknown type name 'zend_long'
  zend_long allow_persistent;
  ^
/root/mysql/php_mysql_structs.h:118:2: error: unknown type name 'zend_long'
  zend_long default_port;
  ^
/root/mysql/php_mysql_structs.h:122:2: error: unknown type name 'zend_long'
  zend_long connect_errno;
  ^
/root/mysql/php_mysql_structs.h:123:2: error: unknown type name 'zend_long'
  zend_long connect_timeout;
  ^
/root/mysql/php_mysql_structs.h:124:2: error: unknown type name 'zend_long'
  zend_long result_allocated;
  ^
/root/mysql/php_mysql_structs.h:125:2: error: unknown type name 'zend_long'
  zend_long trace_mode;
  ^
/root/mysql/php_mysql_structs.h:126:2: error: unknown type name 'zend_long'
  zend_long allow_local_infile;
  ^
/root/mysql/php_mysql.c:119:2: error: unknown type name 'zend_resource'
  zend_resource *active_result_res;
  ^
/root/mysql/php_mysql.c:414:32: error: unknown type name 'zend_resource'
 static void _free_mysql_result(zend_resource *rsrc)
                                ^
/root/mysql/php_mysql.c:425:40: error: unknown type name 'zend_resource'
 static void php_mysql_set_default_link(zend_resource *link)
                                        ^
/root/mysql/php_mysql.c: In function 'php_mysql_select_db':
/root/mysql/php_mysql.c:372:57: error: request for member 'ptr' in something not a structure or union
    _mysql_result = (MYSQL_RES *)mysql->active_result_res->ptr; \

mysql 扩展的源代码似乎不再与 PHP 5.6 API 兼容。

鉴于 mysql 扩展在同一台服务器上的 PHP 7.0 下编译得非常好,人们一定想知道扩展源是否已更新为适用于 7.0。

我试图找到 mysql 扩展代码的早期版本,但是 https://pecl.php.net/package/mysql仅向用户推荐 http://git.php.net/?p=pecl/database/mysql.git;a=summary ,它似乎没有任何有意义的版本历史记录,例如设计用于 PHP < 7.0="">

我还可以尝试什么?也许我忽略了一些愚蠢的事情......

感谢您的任何建议!

更新:解决方案

根据已接受的答案,当我需要 PHP 5.6 源时,我正在获取 PHP 7 源。

这就是解决方案(请务必根据需要调整您自己的版本、路径和服务命令):

# git clone --depth=1 -b PHP-5.6 https://git.php.net/repository/php-src.git
# cd ./php-src/ext/mysql
# phpize5.6
#./configure --with-php-config=/usr/bin/php-config5.6
# make
# make install
# printf "; configuration for php mysql module\n; priority=20\nextension=mysql.so" > /etc/php/mods-available/mysql.ini
# ln -s /etc/php/mods-available/mysql.ini /etc/php/5.6/fpm/conf.d/20-mysql.ini
# service php5.6-fpm reload

最佳答案

您正在使用 PHP 5.6 构建 PHP 7 扩展源。你必须获取 5.6 源。一种方法可能是从 php-src.git 或源分发 tarball 中获取 5.6 分支,然后在 ext/mysql 目录中运行 phpize。

$ git clone -b PHP_5_6 git@git.php.net:/php-src.git php-5.6
$ cd php-5.6/ext/mysql
$ phpize5.6

关于php - 如何为 PHP 5.6 构建 mysql 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35588831/

有关php - 如何为 PHP 5.6 构建 mysql 扩展?的更多相关文章

  1. ruby - 使用 C 扩展开发 ruby​​gem 时,如何使用 Rspec 在本地进行测试? - 2

    我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当

  2. ruby - 如何为 emacs 安装 ruby​​-mode - 2

    我刚刚为fedora安装了emacs。我想用emacs编写ruby。为ruby​​提供代码提示、代码完成类型功能所需的工具、扩展是什么? 最佳答案 ruby-mode已经包含在Emacs23之后的版本中。不过,它也可以通过ELPA获得。您可能感兴趣的其他一些事情是集成RVM、feature-mode(Cucumber)、rspec-mode、ruby-electric、inf-ruby、rinari(用于Rails)等。这是我当前用于Ruby开发的Emacs配置:https://github.com/citizen428/emacs

  3. c - mkmf 在编译 C 扩展时忽略子文件夹中的文件 - 2

    我想这样组织C源代码:+/||___+ext||||___+native_extension||||___+lib||||||___(Sourcefilesarekeptinhere-maycontainsub-folders)||||___native_extension.c||___native_extension.h||___extconf.rb||___+lib||||___(Rubysourcecode)||___Rakefile我无法使此设置与mkmf一起正常工作。native_extension/lib中的文件(包含在native_extension.c中)将被完全忽略。

  4. ruby - 在 Ruby 中构建长字符串的简洁方法 - 2

    在编写Ruby(客户端脚本)时,我看到了三种构建更长字符串的方法,包括行尾,所有这些对我来说“闻起来”有点难看。有没有更干净、更好的方法?变量递增。ifrender_quote?quote="NowthatthereistheTec-9,acrappyspraygunfromSouthMiami."quote+="ThisgunisadvertisedasthemostpopularguninAmericancrime.Doyoubelievethatshit?"quote+="Itactuallysaysthatinthelittlebookthatcomeswithit:themo

  5. 使用canal同步MySQL数据到ES - 2

    文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co

  6. ruby - 使用 rbenv 和 ruby​​-build 构建 ruby​​ 失败,出现 undefined symbol : SSLv2_method - 2

    我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby​​2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby​​-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm

  7. ruby-on-rails - 向 Rails 3 添加 Ruby 扩展方法的最佳实践? - 2

    我有一个要在我的Rails3项目中使用的数组扩展方法。它应该住在哪里?我有一个应用程序/类,我最初把它放在(array_extensions.rb)中,在我的config/application.rb中我加载路径:config.autoload_paths+=%W(#{Rails.root}/应用程序/类)。但是,当我转到railsconsole时,未加载扩展。是否有一个预定义的位置可以放置我的Rails3扩展方法?或者,一种预先定义的方式来添加它们?我知道Rails有自己的数组扩展方法。我应该将我的添加到active_support/core_ext/array/conversion

  8. ruby-on-rails - 如何为空白字段编写 rspec? [Rails3.1] - 2

    我使用rails3.1+rspec和factorygirl。我对必填字段(validates_presence_of)的验证工作正常。我如何让测试将该事实用作“成功”而不是“失败”规范是:describe"Addanindustrywithnoname"docontext"Unabletocreatearecordwhenthenameisblank"dosubjectdoind=Factory.create(:industry_name_blank)endit{shouldbe_invalid}endend但是我失败了:Failures:1)Addanindustrywithnona

  9. ruby-on-rails - 无法安装 mysql2 0.3.14 gem - 2

    我看到其他人也遇到过类似的问题,但没有一个解决方案对我有用。0.3.14gem与其他gem文件一起存在。我已经完全按照此处指示完成了所有操作:https://github.com/brianmario/mysql2.我仍然得到以下信息。我不知道为什么安装程序指示它找不到include目录,因为我已经检查过它存在。thread.h文件存在,但不在ruby​​目录中。相反,它在这里:C:\RailsInstaller\DevKit\lib\perl5\5.8\msys\CORE\我正在运行Windows7并尝试在Aptana3中构建我的Rails项目。我的Ruby是1.9.3。$gemin

  10. ruby - 如何在 ruby​​ 中复制目录结构,不包括某些文件扩展名 - 2

    我想编写一个ruby​​脚本来递归复制目录结构,但排除某些文件类型。因此,给定以下目录结构:folder1folder2file1.txtfile2.txtfile3.csfile4.htmlfolder2folder3file4.dll我想复制这个结构,但不包含.txt和.cs文件。因此,生成的目录结构应如下所示:folder1folder2file4.htmlfolder2folder3file4.dll 最佳答案 您可以使用查找模块。这是一个代码片段:require"find"ignored_extensions=[".cs"

随机推荐