Ubuntu12.04 use c to compile the php extension module tutorial _ PHP Tutorial

Source: Internet
Author: User
Ubuntu12.04 use c to compile the php extension module tutorial. The system is ubuntu12.04. apache and php have been installed. The php version is 5.3.10. If you encounter permission problems, we recommend that you switch to root. 1. download the source code and check out the system ubuntu 12.04. apache and php have been installed, and the php version is 5.3.10.

If you encounter permission problems, we recommend that you switch to root.

1. download source code

Check out the source code of php 5.3.10.

The code is 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, install svn first and use apt-get to install it in ubuntu:

The code is as follows:


$ Sudo apt-get install subversion

About php source code, such as need to know more information, you can view the php wiki on svn instructions: https://wiki.php.net/vcs/svnfaq

2. create a module

A. after the source code is checked out, go to the ext Directory of the source code and use ext_skel to create a module named my:

The code is as follows:


$./Ext_skel -- extname = my

B. enter the my module:

The code is as follows:


$ Cd my

C. modify the config. m4 file and find the following content:

The code is as follows:


Dnl PHP_ARG_WITH (my, for my support,
Dnl Make sure that the comment is aligned:
Dnl [-- with-my Include my support])

Remove the previous dnl, and the final result is as follows:

The code is as follows:


PHP_ARG_WITH (my, for my support,
Make sure that the comment is aligned:
[-- With-my Include my support])

Save the file.

Tips: If you need to test whether the modification is correct, you can use php my. php to test it:

The code is as follows:


$ Php my. php
Confirm_my_compiled

Congratulations! You have successfully modified ext/my/config. m4. Module my is now compiled into PHP.

The above confirm_my_compiled is the default function of the module. after loading the module, you can call this function.

3. compilation module

Run the following command in the my module directory:

The code is as follows:


$ Phpize
$./Configure
$ Make
$ Make install

After compilation is successful, the following message is displayed:

The code is 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, in ubuntu directly use apt-get installation on OK.

The code is as follows:


$ Apt-get install php5-dev

4. load modules

Edit File:

The code is as follows:


$ Vim/etc/php5/conf. d/my. ini

Add the following content to load the my. so module and save it.

The code is as follows:


Extension = my. so

Restart apache

The code is as follows:


$/Etc/init. d/apache2 restart

In the web environment, you can use phpinfo to check whether the my module is loaded. The terminal can be viewed using php-I | less.

5. Compile the test program

If the above execution is successful, the my module is loaded and the default confirm_my_compiled method of my module can be called. Compile a php test file:

The code is as follows:


Echo confirm_my_compiled ("Hello ");

Run the test file. if the following output is displayed, the test is successful.

The code is as follows:


Congratulations! You have successfully modified ext/my/config. m4. Module Hello is now compiled into PHP.

12.04, apache and php have been installed, and php version is 5.3.10. If you encounter permission problems, we recommend that you switch to root. 1. download the source code and check it out...

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.