Build PHP Extension development environment in Windows

Source: Internet
Author: User
Tags vc9
Build PHP Extension development environment in Windows

First, prepare in advance

Download and install VS2008

Download PHP5.4.5 Program:

NTS download

TS Download

PHP binary packages are divided into VC6, VC8, VC9, and TS and NTS versions.

VC6, VC8, VC9 respectively correspond to VC6, VC2005, VC2008

TS (thread safe), which is recommended when using ISAPI (IIS SERVER), because it is a single-process multi-threaded operation, and to avoid memory leaks and shared variable security, we recommend that you use the TS version.

when executed in a single process, such as fast_cgi, there is no need for thread security checks.


Download PHP5.4.5 Source code

Download PHP-SDK

Download Msys, which includes implementations of Linux compilers under Windows

Download Deps


The following configuration basics are based on the F:\php_stdio folder


Second, compile PHP

First download the PHP-SDK, first download the newer php-sdk-binary-tools-20110915.zip, extract to

f:\php_stdio\PHP-SDK

Directory. Note that after decompression, there should be bin and script subdirectories in this directory.

Open a CMD window, switch to the F:\PHP_STDIO\PHP-SDK directory, run Vcvarsall.bat to set the compilation environment variable.

VS2008 Installation Path \vc\vcvarsall.bat

The specific directory of Vcvarsall.bat here depends on your own installation location.

Next, go to the cmd window to continue running the following command:

Bin\phpsdk_setvars.bat

Bin\phpsdk_buildtree.bat Php54dev

In this way, there is another Php54dev directory under the F:\PHP_STDIO\PHP-SDK directory.

Then continue to extract the deps to

F:\php_stdio\php-sdk\php54dev\vc9\x86\

Directory. The original directory under the Deps directory of all subdirectories are empty directories, after decompression, should be copied into a lot of necessary modules/extensions required library files.

Next, copy the PHP-5.4.5 source directory to

F:\php_stdio\php-sdk\php54dev\vc9\x86\

Directory. Enter the PHP source directory

CD F:\PHP_STDIO\PHP-SDK\php54dev\vc9\x86\php-5.4.5

Run

Buildconf

Then you can try to compile PHP first. In the beginning, generally compile as few modules as possible, first let the core can be compiled correctly:

Configure--disable-all--ENABLE-CLI


The main purpose of this step is to generate config.w32.h, and if you need to generate PHP, you can continue to execute


nmake clean; NMAKE

the php5.4 core and a command-line tool are compiled. NMAKE Clean is designed to avoid interference with legacy compilation intermediate result files.


Third, create a new extension my_fopen

PHP extension infrastructure is the same, to facilitate the development of PHP provides Ext_skel and ext_skel_win32.php are Linux, Windows, the expansion of skeleton building tools.

This is about building a PHP extended development environment in Windows, so you are using ext_skel_win32.php. Use it to create a new extension skeleton that can be opened directly with vs.


is a parameter supported by ext_skel_win32.php

Commonly used mainly are--extname and--proto:

Extname: Specifies the name of the extension

Proto: To make it easy to build a function skeleton quickly, you can create a file and write the definitions of each function.


CD f:\php_stdio\php-sdk\php54dev\vc9\x86\php-5.4.5\extphp ext_skel_win32.php--extname=my_fopen


The result of the above execution indicates that the new extension skeleton was successfully generated and is now open F:\PHP_STDIO\PHP-SDK \php54dev\vc9\x86\php-5.4.5\ext can see the My_fopen folder. Enter My_fopen to seeMY_FOPEN.DSP, it is the project file for vs.

Now you can develop the extensions you want.



Iv. compiling, using extensions

No function interfaces are created in the current new extension, but the default extension gives us a test function interface.

The naming convention for the default function is: confirm_[extname]_compiled

Function interface: Tring confirm_[extname]_compiled (String)


1. Open MY_FOPEN.DSP with VS

2. Set project Properties-"Configuration Properties-" c/c++-"code generation, set Runtime: Multithreaded DLLs (/MD)

3. Set project Properties-"configuration: Switch to Release_ts


4. Set project Properties-"Configuration Properties-" c/c++-advanced, set compile to: Compile to C code (/TC)

5. Set the project Properties-"Configuration Properties-" linker general, Set output file: Release_ts/php_my_fopen.dll.

if not set, it can be cumbersome to find after compiling the build extension. Therefore, this setting is not required.

6. Set project Properties-"Configuration Properties-" linker general, add additional library directory: F:\php_work\php-5.4.5\dev

If you do not set this option, it will be reported at compile time: Cannot open input file "Php5ts.lib"


7. Finally press F5 to perform the compilation. Will generate Php_my_fopen.dll


1 successful, indicating that the DLL was built successfully.


Now that the extension has been compiled successfully, the next step is to use it in PHP.

8. Copy Php_my_fopen.dll to F:\php_work\php-5.4.5\ext

8. Open F:\php_work\php-5.4.5\php.ini, add Extension=ext/php_my_fopen.dll

9. New F:\php_work\test.php

echo confirm_my_fopen_compiled ("test");


V. Issues encountered in compiling a new extension

1.fatal Error C1902: The program Database Manager does not match; Please check the installation
Mspdbsrv.exe or Mspdbcore.dll is missing or the version and Mspdb80.dll versions are different, make sure the same version of the three files is installed in the system.
In the VC installation directory under the \Common7\IDE directory to copy these three files to the installation directory under the VC\bin can be

2 ... /main/config.w32.h Open failed
PHP source code After the Configure will not produce config.w32.h

3. Unable to open input file "Php5ts.lib"
In the Set project Properties page, compile the c++-> advanced-to-compile as C code (/TC), add the Library directory to the linker, and add a PHP binary package to the dev directory.


  • 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.