System Environment: ubuntu14.04
PHP Version: php5.5.9
Apache Version: apache2.4
Using the source code package: PHP 5.6.8
Php-v
PHP 5.5.9-1ubuntu4.7 (CLI) (Built:mar 16 2015 20:47:39)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
With Zend Opcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
With Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
Configuration Reference article: http://blog.csdn.net/niujiaming0819/article/details/8543028
This article also uses the step process in the reference article as the native implementation process
Step 1. Download PHP source package, PHP official website to download, this time using the php5.6.8 version
Step 2. Unzip the package, into the unpacked package (mysoft$ CD php-5.6.8/), with the LS command to view the file directory in the source package, into the Ext folder (CD ext)
Step 3: Build an extended development framework
./ext_skel--extname=helloworld
Execute the above command to establish the framework of the expansion development, this is you will find the Ext folder under a folder called HelloWorld, while the command line also output some text,
You are prompted to generate an approximate step for the extension.
Step 4. Enter the root directory of the PHP source, edit the file vim ext/helloworld/config.m4
Removing a few lines of comment from this file will roughly be between 第16-19 lines, and the specific version may be different after saving the file (: Wq)
Step 5. Executes the command in the PHP source root directory./buildconf--force
Step 6. PHP code in the root directory compiled PHP program, note the command for./configure--with-helloworld
The last error that appears, no processing
Step 7. Enter our extension directory HelloWorld, execute command phpize (install phpize via sudo apt-get install Php5-dev), at which point your extension directory generates many files that can be used for post-compilation.
Step 8. Compile our extension in the HelloWorld directory./configure--with-php-config=/usr/bin/php-config (php-config with your own environment)--enable-helloworld
You can find the location of your php-config file via a command (Find/-name Php-config) My address is/usr/bin/php-config
Step 9. Enter the extension HelloWorld directory, edit the file php_helloworld.h, add the function php_function (helloworldtest) in the last line;
HelloWorldTest can be changed to your favorite name, then save the exit
Step 10. Open HELLOWORD.C with vim, implement our function in Helloworld.c, then add HelloWorldTest function to helloworld_functions[], save exit
Step one. Do the make command make compile extension, I am running the process is still relatively smooth. If there is an error, please take a serious look at the previous step is wrong, I do the first time also wrong is generally the previous steps have a problem.
STEP12. Copy the compiled generated helloworld.so file to your native PHP extension directory
The extended directory can be passed Php-r "phpinfo ();" | grep extension_dir View the extension path for native PHP
Step 13: Configure PHP.ini to open helloworld.so extensions
View PHP.ini's location (php-r "phpinfo ();" | grep "PHP.ini")
Vim open php.ini file sudo vim/etc/php5/cli/php.ini
Add extensions at the end of a file (extension=helloworld.so)
by Php-r "Phpinfo ();" | grep HelloWorld Test
Step 14. Test the extension (php-r "echo helloworldtest ();" )
In the process I have followed the original author's steps to try, resulting in an error
Segmentation fault "(core dumped)
After debugging, when the original author in the Helloworld.c file added to helloworld_functions[] Php_fe_end replaced with {null,null,null} and then compile the time without error but also give Php_fe_end comment , after the modification, recompile, copy on it.
Refer to the original article the author is very detailed, but in the whole process there will be a different problem, but we should have a problem-solving ideas, and a way to find answers. I also have a long time to touch technology, and recently to help friends do two sites, while trying a bit of PHP extension, feel more important when thinking.
Original reference: http://blog.csdn.net/niujiaming0819/article/details/8543028
PHP extension, an implementation of HelloWorld