wget http://cn2.php.net/distributions/php-5.6.10.tar.gztar -zxvf php-5.6.10.tar.gz
2、建立扩展开发框架 ./ext_skel --extname=helloworld
cd php-5.6.10/ext/./ext_skel --extname=helloworldcreating directory helloworldcreating basic files: config.m4 config.w32 .gitignore helloworld.c php_helloworld.h credits experimental tests/001.phpt helloworld.php [done].to use your new extension, you will have to execute the following steps:1. $ cd ..2. $ vi ext/helloworld/config.m43. $ ./buildconf4. $ ./configure --[with|enable]-helloworld5. $ make6. $ ./sapi/cli/php -f ext/helloworld/helloworld.php7. $ vi ext/helloworld/helloworld.c8. $ makerepeat steps 3-6 until you are satisfied with ext/helloworld/config.m4 andstep 6 confirms that your module is compiled into php. then, start writingcode and repeat the last two steps as often as necessary.
3、进入php源码的根目录, 编辑文件 vim ext/helloworld/config.m4
去掉这几行代码前面的dnl
php_arg_enable(helloworld, whether to enable helloworld support,make sure that the comment is aligned:[ --enable-helloworld enable helloworld support])
4、在php源码根目录执行命令 ./buildconf --force
forcing buildconfremoving configure cachesbuildconf: checking installation...buildconf: autoconf version 2.69 (ok)rebuilding configurerebuilding main/php_config.h.in
5、在php源码的根目录编译php程序,注意命令为 ./configure --with-helloworld
configure: warning: unrecognized options: --with-helloworldchecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -echecking for a sed that does not truncate output... /bin/sedchecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuchecking for cc... ccchecking whether the c compiler works... yeschecking for c compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the gnu c compiler... yeschecking whether cc accepts -g... yeschecking for cc option to accept iso c89... none neededchecking how to run the c preprocessor... cc -echecking for icc... nochecking for suncc... no......最后出现的error,没有处理configure: error: xml2-config not found. please check your libxml2 installation.
6、. 进入我们的扩展目录helloworld,执行命令 phpize(通过 sudo apt-get install php5-dev 安装 phpize),此时你的扩展目录会生成很多文件,可以用于后期编译。
cd php-5.6.10/ext/helloworldphpizeconfiguring for:php api version: 20121113zend module api no: 20121212zend extension api no: 220121212
7、在helloworld目录编译我们的扩展 ./configure --with-php-config=/usr/bin/php-config(使用你自己环境的php-config) --enable-helloworld
你可以通过一条命令查找你的php-config文件的位置(find / -name php-config)如下:我的地址为/usr/bin/php-config
./configure --with-php-config=/usr/bin/php-configchecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -echecking for a sed that does not truncate output... /bin/sedchecking for cc... ccchecking whether the c compiler works... yeschecking for c compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the gnu c compiler... yeschecking whether cc accepts -g... yeschecking for cc option to accept iso c89... none neededchecking how to run the c preprocessor... cc -echecking for icc... nochecking for suncc... nochecking whether cc understands -c and -o together... yeschecking for system library directory... libchecking if compiler supports -r... no......
8、进入扩展helloworld目录,编辑文件php_helloworld.h,在最后一行添加函数php_function(helloworldtest);
php_function(helloworldtest);
9、用vim 打开helloword.c,在helloworld.c中实现我们的函数,之后 将helloworldtest函数加入到helloworld_functions[]中,保存退出
php_function(helloworldtest){ return_string(hello world !, 1);}const zend_function_entry helloworld_functions[] = { php_fe(confirm_helloworld_compiled, null) /* for testing, remove later. */ php_fe(helloworldtest, null) php_fe_end /* must be the last line in helloworld_functions[] */};
10、执行make命令 make 编译扩展,我在运行的过程中还是比较顺利的。如果出现错误,请认真看前面步骤是否有错,我在第一遍做的时候也有错一般都是前面步骤有问题。
/bin/bash /php/php-5.6.10/ext/helloworld/libtool --mode=compile cc -i. -i/php/php-5.6.10/ext/helloworld -dphp_atom_inc -i/php/php-5.6.10/ext/helloworld/include -i/php/php-5.6.10/ext/helloworld/main -i/php/php-5.6.10/ext/helloworld -i/usr/include/php5 -i/usr/include/php5/main -i/usr/include/php5/tsrm -i/usr/include/php5/zend -i/usr/include/php5/ext -i/usr/include/php5/ext/date/lib -dhave_config_h -g -o2 -c /php/php-5.6.10/ext/helloworld/helloworld.c -o helloworld.lo libtool: compile: cc -i. -i/php/php-5.6.10/ext/helloworld -dphp_atom_inc -i/php/php-5.6.10/ext/helloworld/include -i/php/php-5.6.10/ext/helloworld/main -i/php/php-5.6.10/ext/helloworld -i/usr/include/php5 -i/usr/include/php5/main -i/usr/include/php5/tsrm -i/usr/include/php5/zend -i/usr/include/php5/ext -i/usr/include/php5/ext/date/lib -dhave_config_h -g -o2 -c /php/php-5.6.10/ext/helloworld/helloworld.c -fpic -dpic -o .libs/helloworld.o/bin/bash /php/php-5.6.10/ext/helloworld/libtool --mode=link cc -dphp_atom_inc -i/php/php-5.6.10/ext/helloworld/include -i/php/php-5.6.10/ext/helloworld/main -i/php/php-5.6.10/ext/helloworld -i/usr/include/php5 -i/usr/include/php5/main -i/usr/include/php5/tsrm -i/usr/include/php5/zend -i/usr/include/php5/ext -i/usr/include/php5/ext/date/lib -dhave_config_h -g -o2 -o helloworld.la -export-dynamic -avoid-version -prefer-pic -module -rpath /php/php-5.6.10/ext/helloworld/modules helloworld.lo libtool: link: cc -shared -fpic -dpic .libs/helloworld.o -o2 -wl,-soname -wl,helloworld.so -o .libs/helloworld.solibtool: link: ( cd .libs && rm -f helloworld.la && ln -s ../helloworld.la helloworld.la )/bin/bash /php/php-5.6.10/ext/helloworld/libtool --mode=install cp ./helloworld.la /php/php-5.6.10/ext/helloworld/moduleslibtool: install: cp ./.libs/helloworld.so /php/php-5.6.10/ext/helloworld/modules/helloworld.solibtool: install: cp ./.libs/helloworld.lai /php/php-5.6.10/ext/helloworld/modules/helloworld.lalibtool: finish: path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/sbin ldconfig -n /php/php-5.6.10/ext/helloworld/modules----------------------------------------------------------------------libraries have been installed in: /php/php-5.6.10/ext/helloworld/modulesif you ever happen to want to link against installed librariesin a given directory, libdir, you must either use libtool, andspecify the full pathname of the library, or use the `-llibdir'flag during linking and do at least one of the following: - add libdir to the `ld_library_path' environment variable during execution - add libdir to the `ld_run_path' environment variable during linking - use the `-wl,-rpath -wl,libdir' linker flag - have your system administrator add libdir to `/etc/ld.so.conf'see any operating system documentation about shared libraries formore information, such as the ld(1) and ld.so(8) manual pages.----------------------------------------------------------------------build complete.don't forget to run 'make test'.
11、安装php
apt-get install php5 php5-gd php5-cli
11、将编译生成的helloworld.so 文件复制到你本机的php扩展目录
创建:info.php内容:phpinfo();php info.php | grep extenextension_dir => /usr/lib/php5/20121212 => /usr/lib/php5/20121212mbstring extension makes use of streamable kanji code filter and converter, which is distributed under the gnu lesser general public license version 2.1.root@4ccdc77255ea:/php/php-5.6.10/ext/helloworld# cp modules/helloworld.so /usr/lib/php5/20121212/
12、配置php.ini 开启 helloworld.so 扩展
php info.php | grep php.iniloaded configuration file => /etc/php5/cli/php.iniroot@4ccdc77255ea:/php# vim /etc/php5/cli/conf.d/ php.ini
13、创建echo.php
14、docker中遇到的问题
1. apt-get install autoconf2. gcc make等依赖包安装
