Install PHP extension development in linux

Source: Internet
Author: User
Tags automake
: This article describes how to install PHP extensions in linux. For more information about PHP tutorials, see. Preface sentiment

In the pulse of a buddy's words, the more he thinks of the advantages of computer science, the longer programming, the more he thinks of the importance of basic knowledge, just like a mountain that cannot go around, the peak may turn, and the future may be smooth, however, we will always meet this mountain. we can continue our journey only by rolling over the difficulties.
I strongly agree that the longer it takes for programming to study at the underlying level, the more advanced it can be. Therefore, the next goal is to systematically study the PHP source code. I reported that I was learning C, and the teacher was an academic character of NB. It is said that the books read C are higher than the lecture table.

Preparation

I found that there were not many comprehensive materials for php extension development on the Internet, and there were no forums. It seems that there are not many requirements in this regard.
First, you need to download the php source code. you can download it from git/svn or the official website. I am from the official website, because some of the source code in git does not have the phpize tool (I have never tried it). phpize is used to expand the PHP extension module.

Start

Go to the downloaded php source code
The ext Directory of the php source code has an ext_skel file, which can be used to easily build a PHP Extension Framework. The following describes how to create a myext extension.

Enter the ext directory cd ext/

./Ext_skel-extname = myext
Creating directory myext
Creating basic files: config. m4 config. w32. gitignore myext. c php_myext.h credits experimental tests/001. phpt myext. php [done].

To use your new extension, you will have to execute the following steps:

  1. $ Cd ..
  2. $ Vi ext/myext/config. m4
  3. $./Buildconf
  4. $./Configure-[with | enable]-myext
  5. $ Make
  6. $./Sapi/cli/php-f ext/myext. php
  7. $ Vi ext/myext. c
  8. $ Make

Repeat steps 3-6 until you are satisfied with ext/myext/config. m4 and
Step 6 confirms that your module is compiled into PHP. Then, start writing
Code and repeat the last two steps as often as necessary .'

At this time, your Directory should have a myext directory, which is the extension framework that ext_skel will help you generate.
Modify config. m4.
Remove the dnl before the following code:

dnl PHP_ARG_ENABLE(myext, whether to enable myext support,dnl [  --enable-myext           Enable myext support])

Save and exit!
Start compilation
In the myext directory. Run the following code:

phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake testmake install

After make install, you will be prompted to install the extension directory/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/after entering, you can see myext. so

Add extension information in php. ini.
Extension = myext. so
Run the php-m command to check whether the extension is successfully installed.
Restart fpm and you can see the installed extension in phpinfo.

Note:

Install an extension here.
Make test will warn that some functions are disabled in php. ini. Find the disable_function of php. ini and remove the warning function.
In addition, I will explain the installation steps of GNU AUTOCONF and AUTOMAKE programs in linux.

Config/configure/Configure
This is used to detect the target features of your installation platform. For example, it will check whether you have CC or GCC. it does not require CC or GCC. it is a shell script.
This step is generally used to generate Makefile to prepare for the next compilation. you can add parameters after configure to control the installation. for example:
./Configure-prefix =/usr
The above means to install the software under/usr
The execution file will be installed in/usr/bin (instead of the default/usr/local/bin)
The resource file will be installed in/usr/share (instead of the default/usr/local/share)
You can specify the-sys-c
You can also use parameters such as-with,-enable,-without, and-disable to control Compilation. you can view the help instructions in detail through./configure-help.
Make
This step is used for Compilation. it reads commands from Makefile and then compiles
This step is Compilation. most source code packages are compiled through this step.
Of course, some software written in perl or python must call perl or python for compilation.
If an error occurs during the make process, you need to write down the error code (note that it is not just the last line), and then you can submit the bugreport to the developer (generally there is a submission address in INSTALL ), or your system has less dependent libraries, and you need to carefully study the error code.
Make test/make check
As the name suggests, this step is to check make in the previous step. make sure that make is correct, that is, test and check in this step must be all OK, and error is 0.
Sudo make install
This step is used for installation. it also reads commands from Makefile and installs them to the specified location.
This command is used for installation. Generally, you need to have the root permission (because you want to write files to the system ).

AUTOMAKE and AUTOCONF are very useful for publishing C programs. If you want to use AUTOMAKE and AUTOCONF, you can refer to related articles on CNGNU. ORG.

The above introduces the installation of PHP extension development in linux, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

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.