0x00 说明
PHP扩展有两种编译方式
- 在编译PHP时直接将扩展编译进去
- 扩展被编译成.so文件,在php.ini里配置加载路径
源码环境
先下载源码,可以通过git clone
等,进入源码跟目录,进入插件目录
cd php-5.6.31
cd ext
0x01 创建PHP扩展
执行ext_skel
命令生成扩展框架
./ext_skel --extname=demo
执行成功后会有一个操作步骤提示
To use your new extension, you will have to execute the following steps:
- $ cd ..
- $ vi ext/demo/config.m4
- $ ./buildconf
- $ ./configure –[with|enable]-demo
- $ make
- $ ./sapi/cli/php -f ext/demo/demo
- $ vi ext/demo/demo
- $ make
这是源码编译的步骤
0x02 修改文件config.m4
重点看line10-18的代码,用于设置./configure时启用此扩展的命令选项,将其中line16和line18的dnl删掉,把dnl理解为注释符。
14 dnl Otherwise use enable:
15
16 dnl PHP_ARG_ENABLE(myfirstext, whether to enable myfirstext support,
17 dnl Make sure that the comment is aligned:
18 dnl [ --enable-myfirstext Enable myfirstext support])
19
20 if test "$PHP_MYFIRSTEXT" != "no"; then
21 dnl Write more examples of tests here...
0x03-1 编译PHP时直接将扩展编译进去
cd php-src/
./buildconf or ./buildconf --force
./configure –enable-demo
make
大概这样子就OK了,但是我没有这样编译过,一般用另一种方式的。同时也推荐用另一种方式
0x03-2 编译成.so文件 【推荐】
cd php-src/ext/demo
phpize
./configure –enable-demo
make
然后扩展就是成功编译,并且保存在php-src/ext/demo/modules/demo.so
0x04 加载扩展
在php.ini
中,添加extension=/path/demo.dll
或者zend_extension=/path/demo.so
根据不同的扩展类型选择不同的加载方式。
FROM : virzz.com | Author:Virink
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论