The system is Ubuntu 12.04, and the version of Apache and php,php has been installed is 5.3.10.
The following actions are recommended to switch to root if you encounter permissions issues.
1, download the source code
Check out the source code for PHP 5.3.10
Copy Code code as follows:
$ svn Checkout https://svn.php.net/repository/php/php-src/branches/PHP_5_3_10/
Tips: If you do not have this command, you need to install SVN, under Ubuntu directly using the Apt-get installation is OK:
Copy Code code as follows:
$ sudo apt-get install subversion
About PHP source code, if you need more information, you can view the PHP wiki on svn instructions: Https://wiki.php.net/vcs/svnfaq
2. Create the module
A, after the source check out, into the source code ext directory, first with Ext_skel to create a module, the module named my:
Copy Code code as follows:
b, enter my module:
Copy Code code as follows:
C, modify the Config.m4 file, find the following content:
Copy Code code as follows:
DNL Php_arg_with (My, for my support,
DNL Make sure this comment is aligned:
DNL [--with-my Include my support])
Remove the DNL from the front, and finally the following:
Copy Code code as follows:
Php_arg_with (My, for my support,
Make sure this comment is aligned:
[--with-my Include my support])
Then save the file.
Tips: If you need to test the correct changes, you can use the PHP my.php to test the following:
Copy Code code as follows:
$ PHP my.php
Confirm_my_compiled
congratulations! You have successfully modified EXT/MY/CONFIG.M4. Module my are now compiled into PHP.
The above confirm_my_compiled is the module default function, after the module is loaded, you can call this function.
3, compile the module
Or in the directory of my module, execute the following command:
Copy Code code as follows:
$ phpize
$./configure
$ make
$ make Install
After the compilation succeeds, you will be prompted with this information:
Copy Code code as follows:
Installing Shared extensions:/usr/lib/php5/20090626+lfs/
Indicates that the module has been compiled and copied to the PHP module directory.
Tips: If the phpize command is not found, you need to install the Php5-dev, under Ubuntu directly using the Apt-get installation is OK.
Copy Code code as follows:
$ apt-get Install Php5-dev
4. Loading module
Edit file:
Copy Code code as follows:
$ vim/etc/php5/conf.d/my.ini
Add the following to indicate that the my.so module is loaded and then saved.
Copy Code code as follows:
Restart Apache
Copy Code code as follows:
$/etc/init.d/apache2 Restart
In a Web environment, you can use Phpinfo to see if the My module is loaded. Terminals can use Php-i | Less view.
5. Write test procedure
If all goes well, the My module is loaded in, and the default method of my module, confirm_my_compiled, can be invoked. Writing PHP Test files:
Copy Code code as follows:
Echo confirm_my_compiled ("Hello");
Execute the test file, and if you see the output below, it succeeds.
Copy Code code as follows:
congratulations! You have successfully modified EXT/MY/CONFIG.M4. Module Hello is now compiled into PHP.