Home >Backend Development >PHP Tutorial >PHP extension, an implementation of helloworld_PHP tutorial
Execute the above command to establish the framework for expansion development. You will find that there is an additional folder called helloworld under the ext folder, and some text is also output from the command line,
You will be prompted with the general steps to generate the extension.
step 4. Enter the root directory of the php source code and edit the file vim ext/helloworld/config.m4
Remove a few lines of comments in this file, which will be roughly between lines 16-19. The specific version may be different and then save the file (: wq)
step 5. Execute the command ./buildconf --force
in the php source code root directory
step 6. Compile the php program in the root directory of the php source code. Note that the command is ./configure --with-helloworld
The last error that occurred was not processed
step 7. Enter our extension directory helloworld and execute the command phpize (install phpize through sudo apt-get install php5-dev). At this time, your extension directory will generate many files that can be used Post compilation.
step 8.Compile our extension in the helloworld directory./configure --with-php-config=/usr/bin/php-config (use the php-config of your own environment) -- enable-helloworld
You can find the location of your php-config file through a command (find / -name php-config) as shown in the figure: My address is /usr/bin/php-config
step 9. Enter the extended helloworld directory, edit the file php_helloworld.h, and add the function PHP_FUNCTION(helloworldTest);
in the last linehelloworldTest can be changed to your favorite name, then save and exit
step 10. Open helloword.c with vim, implement our function in helloworld.c, then add the helloworldTest function to helloworld_functions[], save and exit
step 11.Execute the make command to compile the extension. I ran it relatively smoothly. If an error occurs, please carefully check the previous steps to see if there are any errors. I also made errors when I did it for the first time. Generally, there is a problem with the previous steps.
step12. Copy the compiled helloworld.so file to your local php extension directory
The extension directory can be viewed through php -r phpinfo(); | grep extension_dir to view the extension path of native php
step 13. Configure php.ini to enable helloworld.so extension
View the location of php.ini (php -r phpinfo(); | grep php.ini )
vim opens the php.ini file sudo vim /etc/php5/cli/php.ini
Add extension (extension=helloworld.so) at the end of the file
Tested by php -r phpinfo(); | grep helloworld
step 14. Test extension (php -r echo helloworldTest();)
During this process, I tried following the original author’s steps, but an error occurred
After debugging, the original author changed PHP_FE_END to {null,null,null} when adding it to helloworld_functions[] in the helloworld.c file. When he compiled it again, there was no error, but he also commented PHP_FE_END. Modification After that, just recompile and copy.