One, build PHP environment Download PHP 5.2.6 source code and unzip
Compile and install, build PHP environment
Second, create an extension project Access to the source directory
CD php5.2.6/ext/
./ext_skel--extname=my_ext
Create a project with the name My_ext, which will eventually generate the my_ext.so
Three, change configuration and program $ VI EXT/MY_EXT/CONFIG.M4
According to your own choice, you will
DNL Php_arg_with (My_ext, for my_ext support,
DNL Make sure this comment is aligned:
DNL [--with-my_ext Include my_ext support])
Modified into
Php_arg_with (My_ext, for my_ext support,
Make sure this comment is aligned:
[--with-my_ext Include My_ext support])
or to
DNL php_arg_enable (My_ext, whether to ENABLE My_ext support,
DNL Make sure this comment is aligned:
DNL [--enable-my_ext enable my_ext support])
Modified into
Php_arg_enable (My_ext, whether to ENABLE My_ext support,
Make sure this comment is aligned:
[--enable-my_ext enable my_ext support])
$ VI ext/my_ext/php_my_ext.h
Will
Php_function (confirm_my_ext_compiled); /* For testing, remove later. */
Change to
Php_function (Say_hello);
$ VI ext/my_ext/my_ext.c
Will
Zend_function_entry php5cpp_functions[] = {
Php_fe (confirm_my_ext_compiled, NULL)/* For testing, remove later. */
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] * *
};
Change to
Zend_function_entry php5cpp_functions[] = {
Php_fe (Say_hello, NULL)
{null, NULL, NULL}/* must is the last line in php5cpp_functions[] * *
};
At the end add:
Php_function (Say_hello)
{
zend_printf ("Hello world\n");
}
four, compile $ CD My_ext
$/usr/local/php/bin/phpize
PS: If appears: Cannot find autoconf ..... Error message, you need to install the autoconf (installation process is slightly)
$./configure--with-php-config=/usr/local/php/bin/php-config
$ make
This will compile the my_ext/modules/my_ext.so
Five, configure PHP.ini Put the my_ext.so into/usr/local/php/ext/Directory
$ VI php.ini
Modifications are added as follows:
Extension_dir = '/usr/local/php/ext/'
Extension=my_ext.so
Six, test $ VI test.php
<?php
Say_hello ();
?>
$/usr/local/php/bin/php test.php
Hello world.
is done
PS: If you have questions, please leave a message, we discuss together
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.