: This article mainly introduces WindowsWAMPPHP extension development. For more information about PHP tutorials, see. 1. development preparation
Install WAMP. the Version used is WampServer Version 2.5. The PHP Version is 5.5.12.
WAMP installation directory: D: \ wamp
Apache Directory: D: \ wamp \ bin \ apache
Php Directory: D: \ wamp \ bin \ php
Download the PHP-5.5.12 source package, decompress it to any directory. Example: E: \ php-5.5.12
2. use phpinfo () to query the compilation information of the php version. for details, refer:
CompilerMSVC11 (Visual C ++ 2012)
Ubunturex86
Zend Extension BuildAPI220121212, TS, VC11
PHP Extension BuildAPI20121212, TS, VC11
From the above information, we can see that php in WampServer 2.5 is compiled on x86 (win32) through MSVC11 (VS2012) and the TS (Thread Safe) attribute is set.
Therefore, you also need to use the same compiling environment and TS settings when compiling the extension plug-in (the default value is TS)
3. Generate the config. w32.h file required for compiling the plug-in.
Open the VS2012 developer command prompt and enter the E: \ php-5.5.12 directory;
Run the buildconf. bat command to generate the configure. js file in the current directory;
Run the configure command to generate the E: \ php-5.5.12 \ main \ config. w32.h file.
If a bison-related error occurs during execution, it means that you have not installed bison. you can open the configure. js file, comment out the following three lines, and then re-execute the configure command.
If (! PATH_PROG ('bison ')){
ERROR ('bison is required ')
}
Why can we do this? because we don't need to compile PHP, we only need to generate the config. w32.h file to compile the extension plug-in.
4. prepare the compilation file of the plug-in
Go to the E: \ php-5.5.12 \ ext Directory, copy the E: \ php-5.5.12 \ ext \ skeleton directory and rename the name of the plug-in you need, such as my_plugin;
Rename php_skeleton.h, skeleton. c, and skeleton. dsp to php_my_plugin.h, my_plugin.c, and my_plugin.dsp;
Open the preceding three files, replace extname with my_plugin, and EXTNAME with MY_PLUGIN (case-insensitive );
Copy D: \ wamp \ bin \ php \ php5.5.12 \ dev \ php5ts. lib to the my_plugin directory.
5. Compile and install the plug-in
Use VS2012 to open the my_plugin.dsp file and select Release_TS (generate the Release version) and configure compiling to C code (solution property-configuration property-C/C ++-advanced-compile to C code (/TC ));
Compile the solution and generate the php_my_plugin.dll file corresponding to the plug-in (in the E: \ php-5.5.12 \ Release_TS directory );
Copy the compiled dll file to the Wamp PHP extension directory (D: \ wamp \ bin \ php \ php5.5.12 \ ext );
Edit the D: \ wamp \ bin \ apache \ apache2.4.9 \ bin \ php. ini file, find the "extension =" keyword, and add "extension = php_my_plugin.dll" after the original PHP plug-in ";
Note: the edited php. ini is not D: \ wamp \ bin \ php \ php5.5.12 \ php. ini, because when Wamp initializes PHP, the Read location is D: \ wamp \ bin \ apache \ apache2.4.9 \ bin \ php. ini file.
Restart the Apache server.
6. test the plug-in
If the plug-in is loaded successfully, restart the Apache server to access phpinfo () to view the newly added my_plugin plug-in.
Generate the my_plugin_test.php file and place it in the D: \ wamp \ www Directory. the file content is as follows:
Echo confirm_my_plugin_compiled ("my_plugin ");
?>
Use a browser to access the my_plugin_test.php file created above. the following page appears, indicating that the plug-in is running properly:
Congratulations! You have successfully modified ext/my_plugin/config. m4. Module my_plugin is now compiled into PHP.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces Windows wamp php extension development, including some content, hope to be helpful to friends who are interested in PHP tutorials.