The idea cdphp-5.4.23ext creates the config. m4 file PHP_ARG_ENABLE (heiyoubo,
Download PHP source code php-5.4.23.tar.gz, unzip, enter/home/hubo/php-5.4.23/ext/extension directory wget http://cn2.php.net/get/php-5.4.23.tar.gz/from/this/mirror tar-xzvf php-5.4.23.tar.gz cd php-5.4.23/ext/create config. m4 file PHP_ARG_ENABLE (heiyoubo,
Download PHP source code php-5.4.23.tar.gz, decompress, enter/home/hubo/php-5.4.23/ext/extension directory
Wget http://cn2.php.net/get/php-5.4.23.tar.gz/from/this/mirror
Tar-xzvf php-5.4.23.tar.gz
Cd php-5.4.23/ext/
Create a config. m4 file in the ext directory.
PHP_ARG_ENABLE(heiyoubo, [Whether to enable the "heiyoubo" extension], [ enable-heiyoubo Enable "heiyoubo" extension support])if test $PHP_HEIYOUBO != "no"; then PHP_SUBST(HEIYOUBO_SHARED_LIBADD) PHP_NEW_EXTENSION(heiyoubo, heiyoubo.c, $ext_shared)fi
Create the heiyoubo. c file in the ext directory.
# Ifdef HAVE_CONFIG_H # include "config. h" # endif // load the php header file # include "php. h" # define phpext_heiyoubo_ptr & destroy (heiyoubo_hello) {php_printf ("Hello World Heiyoubo! \ N ");} static zend_function_entry heiyoubo_functions [] = {ZEND_FE (heiyoubo_hello, NULL) {NULL, NULL, NULL }}; // module entryzend_module_entry heiyoubo_module_entry = {# if needed> = 20010901 STANDARD_MODULE_HEADER, # endif "heiyoubo", // The extension name is used in this place. Heiyoubo_functions,/* Functions */NULL,/* MINIT */NULL,/* MSHUTDOWN */NULL,/* RINIT */NULL,/* RSHUTDOWN */NULL, /* MINFO */# if ZEND_MODULE_API_NO> = 20010901 "2.1", // This is our extended version # endif STANDARD_MODULE_PROPERTIES}; # ifdef evaluate (heiyoubo) # endif
Run phpize to prepare the compiling environment of the PHP extension library.
[Hubo @ test15169x ~ /Php-5.4.23/ext] $/usr/local/php/bin/phpize
Processing ing:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Enable heiyoubo extension during configure and specify the directory of php-config to obtain the installed PHP configuration information.
[Hubo @ test15169x ~ /Php-5.4.23/ext] $./configure -- enable-heiyoubo -- with-php-config =/usr/local/php/bin/php-config
[Hubo @ test15169x ~ Php-5.4.23/ext] $ make
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ make test
The heiyoubo. so extension has been generated to the module Directory.
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ ll modules /*
-Rw-r -- 1 hubo 799 01-09 16:53 modules/heiyoubo. la
-Rwxrwxr-x 1 hubo 26 K 01-09 16:53 modules/heiyoubo. so
Copy the heiyoubo. so file to the php extension directory.
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ php-ini | grep extension_dir
Extension_dir =>/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525 =>/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ cp modules/heiyoubo. so/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/
Add heiyoubo. so to the extension file/usr/local/etc/cgi/php. ini in php extension = "heiyoubo. so"
[Hubo @ test15169x ~ // Php-5.4.23/ext] $ php -- ini
Configuration File (php. ini) Path:/usr/local/etc/cgi
Loaded Configuration File:/usr/local/etc/cgi/php. ini
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ php-r 'var _ dump (get_loaded_extensions (); '| grep heiyoubo
String (8) "heiyoubo"
Verify that the installation is successful. The heiyoubo_hello () function in the C extension is executed successfully.
[Hubo @ test15169x ~ /Php-5.4.23/ext] $ php-r 'heiyoubo _ hello ();'
Hello World Heiyoubo!
Reference link:
Http://www.php.net/manual/zh/internals2.buildsys.configunix.php
Https://github.com/walu/phpbook/blob/master/5.1.md Extending and Embedding PHPPHP extension development and kernel applications
Http://www.laruence.com/2009/04/28/719.html
Http://www.php-internals.com/