C language PHP helloworld extension 1. Download php source code
wget http://cn2.php.net/distributions/php-5.6.10.tar.gztar -zxvf php-5.6.10.tar.gz
2. establish an extension development framework./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. go to the root directory of the php source code and edit the vim ext/helloworld/config. m4 file.
Remove the dnl lines before the code.
PHP_ARG_ENABLE(helloworld, whether to enable helloworld support,Make sure that the comment is aligned:[ --enable-helloworld Enable helloworld support])
4. run the command./buildconf -- force in the php source code root directory.
Forcing buildconfRemoving configure cachesbuildconf: checking installation...buildconf: autoconf version 2.69 (ok)rebuilding configurerebuilding main/php_config.h.in
5. Compile the php program in the root directory of the php source code. Note that the command is./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... the 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 ...... the final error that appears does not handle configure: error: xml2-config not found. please check your libxml2 installation.
6,.Go to our extension directory helloworld and execute the command phpize (install phpize via sudo apt-get install php5-dev). at this point your extension directory will generate a lot of files that can be used for post-compilation.
cd php-5.6.10/ext/helloworldphpizeConfiguring for:PHP Api Version: 20121113Zend Module Api No: 20121212Zend Extension Api No: 220121212
7. compile our extensions in the helloworld directory. /configure -- with-php-config =/usr/bin/php-config (use php-config in your own environment) -- enable-helloworld
You can run a command to find the location of your php-config file (find/-name php-config) as follows: My address is/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. go to the extended helloworld Directory, edit the file php_helloworld.h, and add the function PHP_FUNCTION (helloworldTest) in the last line );
PHP_FUNCTION(helloworldTest);
9. use vim to open helloword. c, implement our function in helloworld. c, add the helloworldTest function to helloworld_functions [], save and exit.
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. execute the make command to compile the extension, and I am still running smoothly. If an error occurs, check whether there are any errors in the previous step. the errors I made during the first step are generally due to errors in the previous step.
/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. install php
apt-get install php5 php5-gd php5-cli
11. copy the compiled helloworld. so file to your local php extension directory.
Create: info. php content: phpinfo (); php info. php | grep extenextension_dir =>/usr/lib/php5/20121212 =>/usr/lib/php5/20121212 mbstring extension makes use of "streamable kanji code filter and converter ", which is distributed under the GNU Lesser General Public License version 2.1.root @ 4ccsc77255ea:/php/php-5.6.10/ext/helloworld # cp modules/helloworld. so/usr/lib/php5/20121212/
12. configure php. ini to enable helloworld. so extension.
php info.php | grep php.iniLoaded Configuration File => /etc/php5/cli/php.iniroot@4ccdc77255ea:/php# vim /etc/php5/cli/conf.d/ php.ini
13. create echo. php
14. problems encountered in Docker
1. apt-get install autoconf2. install dependent packages such as gcc make