Use phpize to create a php extension (Cannotfindconfig. m4)

Source: Internet
Author: User
Then execute make, and you will see an error. you have redefined the function. the previous one, you have changed this file and deleted the original function. in the generated file, you will have the same function. add your code

Php source code:/root/soft/php-5.3.4
Php installation:/usr/local/php


[Root @ ns root] # phpize
Cannot find config. m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module

[Root @ ns root] # phpize
Cannot find config. m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module

 


Find this tool under/usr/local/src/php-4.3.5/ext
To build a php extension framework.
[Root @ ns ext] # cd/root/soft/php-5.3.4/ext/
[Root @ ns ext] #./ext_skel -- extname = my_module
Creating directory my_module
Creating basic files: config. m4. cvsignore my_module.c php_my_module.h credits experimental tests/001. phpt my_module.php [done].

To use your new extension, you will have to execute the following steps:

1. $ cd ..
2. $ vi ext/my_module/config. m4
3. $./buildconf
4. $./configure -- [with | enable]-my_module
5. $ make
6. $./php-f ext/my_module/my_module.php
7. $ vi ext/my_module/my_module.c
8. $ make
After performing this step, you will see this result.
Repeat steps 3-6 until you are satisfied with ext/my_module/config. m4 and
Step 6 confirms that your module is compiled into PHP. Then, start writing
Code and repeat the last two steps as often as necessary.
In this case, a directory named my_module will be generated under this directory.
Let's take a look.
[Root @ ns ext] # cd my_module/
[Root @ ns my_module] # ls
Config. m4 EXPERIMENTAL my_module.php tests
CREDITS my_module.c php_my_module.h

Then we want to modify the file order as follows:
Configue. m4
My_module.c
Php_my_module.h

Open the config. m4 file in the text editor. the file content is roughly as follows:
Dnl $ Id $ d
Dnl config. m4 for extension my_module
Dnl don't forget to call PHP_EXTENSION (my_module)
Dnl Comments in this file start with the string 'dnl '.
Dnl Remove where necessary. This file will not work
Dnl without editing.
Dnl If your extension references something external, use:
Dnl PHP_ARG_WITH (my_module, for my_module support,

Dnl Make sure that the comment is aligned:
Dnl [-- with-my_module Include my_module support])

Dnl Otherwise use enable:
Dnl PHP_ARG_ENABLE (my_module, whether to enable my_module support,

Dnl Make sure that the comment is aligned:
Dnl [-enable-my_module Enable my_module support])

If test "$ PHP_MY_MODULE "! = "No"; then
Dnl If you will not be testing anything external, like existence

Dnl headers, libraries or functions in them, just uncomment

Dnl following line and you are ready to go.
Dnl Write more examples of tests here...
PHP_EXTENSION (my_module, $ ext_shared)

Fi
Choose
Dnl PHP_ARG_WITH (my_module, for my_module support,

Dnl Make sure that the comment is aligned:
Dnl [-- with-my_module Include my_module support])

Modify
PHP_ARG_WITH (my_module, for my_module support,

Make sure that the comment is aligned:
[-- With-my_module Include my_module support])

Or set
Dnl PHP_ARG_ENABLE (my_module, whether to enable my_module support,

Dnl Make sure that the comment is aligned:
Dnl [-enable-my_module Enable my_module support])

Modify
PHP_ARG_ENABLE (my_module, whether to enable my_module support,

Make sure that the comment is aligned:

[-Enable-my_module Enable my_module support])
I used the latter here
Save and exit
Then edit
Vi my_module.c
Modify the following code in the file.

/* Every user visible function must have an entry in my_module_functions [].

*/
Function_entry my_module_functions [] = {
PHP_FE (say_hello, NULL )/*? Add a line of code */

PHP_FE (confirm_my_module_compiled, NULL)/* For testing, remove later .*/

{NULL, NULL, NULL}/* Must be the last line in my_module_functions [] */

};
Add the following code at the end of the file
PHP_FUNCTION (say_hello)
{
Zend_printf ("hello world/n ");

}
Save the file and exit
Then we can use the above command in this directory.
/Usr/local/php/bin/phpize
After execution, you will see the following
[Root @ ns my_module] #/usr/local/php/bin/phpize
Processing ING:
PHP Api Version: 20020918
Zend Module Api No: 20020429
Zend Extension Api No: 20050606
[Root @ ns my_module] #
Then execute. /configure -- enable-my_module -- with-apxs =/usr/local/apache/bin/apxs -- with-php-config =/usr/local/php/bin/php-config
We can find this file in the bin directory of php after installation
Php-config and phpize
Note where your apache apxs is stored in this step.
Then execute make
You will see an error. you have redefined the function.
You can change the file and delete the original function. the generated file contains the same function.
You are adding your code
You can pass
At this time, a directory named modules will be generated under the current directory, and the contents you want will be placed below it.
My_module.so file
Cp modules/my_module.so/usr/local/php/ext/
You need to set the extension directory of your php in
In php. ini
Use extension_dir
The last step is not to open this extension in the php. ini file.
Extension = my_module.so
Then
Restart apache
Use phpinfo to check whether it is OK.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.