Configure php5.5 development environment and development extension in windows _ PHP

Source: Internet
Author: User
Tags php download vc9
This article mainly introduces how to configure the php5.5 development environment and development extension in windows. it is very detailed and comprehensive. it is a very good basic php article. we recommend it to you here. There are a lot of online tutorials, but I found that there are few extension development projects in windows, and most of them are earlier than php5.3. today I will explain to you about php extension development, let's take php5.5 as an example.

Windows (my personal)

The code is as follows:


Windows 8.1 Enterprise Edition (installed on mac OS Boot Camp)
Visual Studio 2012
Msysgit (http://msysgit.github.io/download)
Php-sdk-binary-tools-20110915.zip (http://windows.php.net/downloads/php-sdk/download)
Deps-5.5-vc11-x86.7z (http://windows.php.net/downloads/php-sdk/download)
Php-5.5.20 (http://php.net/downloads.php download, this batch of Infinitus selection)

Step 1
Decompress the php-sdk-binary-tools binary package. for example, if I decompress the package to my C: \ php-sdk folder, the current directory structure is as follows:

The code is as follows:


C: \ php-sdk
-- Bin
-- Script
-- Share

Then, you have installed visual studio 2012. open the VS2012 Native Tools Command Prompt Command line tool.

The code is as follows:


# Enter the Directory
Cd C: \ php-sdk
# Setting environment variables
Bin \ phpsdk_setvars.bat
# Create common php-sdk directories
Bin \ phpsdk_buildtree.bat phpdev

If we open the bin \ phpsdk_buildtree.bat file, we will find that it is only created to VC9 without VC11. but if we develop php5.5, we need VC11. at this time, we need to put C: copy \ php-sdk \ phpdev \ vc9 to C: \ php-sdk \ phpdev \ vc11. the directory structure is as follows:

The code is as follows:


C: \ php-sdk \ phpdev \
-- Vc6
-- Vc8
-- Vc9
-- Vc11

Because I downloaded deps-5.5-vc11-x86.7z, I used deps-5.5-vc11-x86.7z to extract deps-5.5-vc11-x86.7z to the C: \ php-sdk \ phpdev \ vc11 \ x86 \ deps folder, which included library files and necessary tools.
Then decompress the downloaded php-5.5.20.tar.bz2 to the C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 folder.

Compile and install php

Return to VS2012 Native Tools Command Prompt
# Enter the php source directory folder
Cd c: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20
Buildconf
# View the extended and compiled commands
Configure -- help
Php-sdk

If you have not installed php, it will help you now. Compile and install php first.
Configure -- disable-all -- enable-cli
Then, you will see Type 'nmake' to build PHP, and then compile
Nmake
The php.exe file is generated under the C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 \ release_tsfolder, and this path is added to the environment variables. Fortunately, php commands can be used in the command line.

Develop the first extension of PHP

If we want to develop a widuu () function, the implementation effect is as follows:

The code is as follows:


Function widuu ($ string ){
Return "your first extension {$ string} is OK ";
}

Enter the extension directory to generate the Extension folder

The code is as follows:


Cd C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 \ ext
# Input php ext_skel_win32.php -- extname = extension name
Php ext_skel_win32.php -- extname = widuuweb


At this time we in C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 \ ext to see their own directory widuuweb, open widuuweb \ php_widuuweb.h, in
# PHP_MINFO_FUNCTION (widuuweb); write your own function in the next row. for example, I define the widuu () function.
PHP_FUNCTION (widuu );
Open php_widuweb.c and compile the function. under PHP_FUNCTION (confirm_widuweb_compiled ),

The code is as follows:


PHP_FUNCTION (widuu ){
Char * arg_string = NULL;
Int arg_len, str_len;
Char * string;
If (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC, "s", & arg_string, & arg_len) = FAILURE ){
Return;
}
Str_len = spprintf (& string, 0, "your first extension %. 78 s is OK", arg_string );
RETURN_STRINGL (string, str_len, 0 );
}

Then find PHP_FE (confirm_widuweb_compiled, NULL) and register your function below

The code is as follows:


Const zend_function_entry widuweb_functions [] = {
PHP_FE (confirm_widuuweb_compiled, NULL)/* For testing, remove later .*/
PHP_FE (widuu, NULL)
PHP_FE_END/* Must be the last line in widuweb_functions [] */
};

Modify C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 \ ext \ widuuweb \ config. w32, remove
// ARG_ENABLE ("widuuweb", "enable widuweb support", "no ");
Comments to the front, vs command line, enter cd... to the php-5.5.20 Directory, enter the following command
Buildconf -- force
# View Extensions
Configure -- help
If there is an error, you can open it and check configure. js in the directory. this error is reported in line 4791 of configure. js,
ARG_ENABLE ("widuuweb", "enable widuweb support", "no ");*/
With an additional */comment, you can remove it and then enter
Configure -- help
We can see that there is a line
-- Enable-widuweb enable widuuweb support
Then Configure
Configure -- disable-all -- enable-cli -- enable-widuweb = shared
Php dynamic scaling

Among them, -- enable-widuweb = shared dynamic extension is exactly opposite to static extension.
Then input nmake, after completion, we found the php_widuweb.dll file in the C: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.5.20 \ Release_TS directory, can be put in the environment to test.
If you haven't installed the php environment locally, but just compiled php like me, if you test it, I suggest static compilation to see the effect.
Configure -- disable-all -- enable-cli -- enable-widuweb = static
Nmake
Then, enter
Php-r "echo widuu ('widuu ');" // output "your first extension widuu is OK"
Okay, let's talk about it. later, if you have any questions, you can leave a message. you can view the basic ZEND_API at walu. cc.

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.