Use VC9 and VC11 in Windows to compile 32-bit and 64-bit PHP and its extension

Source: Internet
Author: User
Tags runkit vc9 zts
In Windows systems, you must use the runkit module to compile 32-bit, 64-bit PHP and its extension projects using VC9 and VC11 to implement AOP. However, the development environment of team members is Windows, the runkit module does not officially provide dll extensions in Windows, so it can only be compiled by itself.

The following is a summary of the compilation process. (The OS is Windows 10 64-bit flagship edition)

  • The PHP compilation version here refers not to the PHP release version, such as 5.3 and 7.0, but to the compiler, program architecture, and thread security used during compilation. This information can be printed in phpinfo. The PHP used in is compiled using MSVC11 in Miscrosoft Visual 2012. the program architecture is x86 (that is, 32-bit), and the non-thread security (ETS ). PHP in is compiled using MSVC11 in Miscrosoft Visual 2012. the program architecture is x64 (64-bit) and thread security (TS ). Slightly different, there is no special list item to describe the compiler version and program architecture, and relevant information can only be seen from the configuration at compilation. Here, PHP is compiled using MSVC6 in Miscrosoft Visual 6. The program architecture is x86 (32-bit) and Thread security (Thread Safety = enabled ). The last one is compiled using MSVC9 in Miscrosoft Visual 2008. the program architecture is x86 (32-bit) and thread security (TS ).This article only discusses MSVC9 and MSVC11 compilation.
  • Prepare PHP-SDK and PHP source code the following steps are required no matter which version of PHP is compiled.
    • Download PHP-SDK: found in the http://windows.php.net/downloads/php-sdk/, download the php-sdk-binary-tools-20110915.zip in it
    • Decompress the package to the C: \ php-sdk folder.
    • Open the command line and execute the following command:

      Cd c: \ php-sdk \

      Bin \ phpsdk_buildtree.bat phpdev

      The phpdev folder is generated under the c: \ php-sdk folder, which contains the vc6, vc8, and vc9 subfolders.

      If you use MSVC11 to compile PHP, copy c: \ php-sdk \ phpdev \ vc9 to c: \ php-sdk \ phpdev \ vc11.

      If you use MSVC14 to compile PHP, copy c: \ php-sdk \ phpdev \ vc9 to c: \ php-sdk \ phpdev \ vc14.

    • Download the corresponding version of the PHP compile-time dependency package, see the http://windows.php.net/downloads/php-sdk. Decompress the package to the x86 or x64 folder under the corresponding compiling folder to overwrite the deps folder. And so on. Php5.4.x and php5.3.x usually need to be compiled using vc9, so the dependent files are decompressed to c: \ php-sdk \ phpdev \ vc9 \ x86 or c: \ php-sdk \ phpdev \ vc9 \ x64. Php5.5.x and php5.6.x usually need to be compiled using vc11, so the dependent files are decompressed to c: \ php-sdk \ phpdev \ vc11 \ x86 or c: \ php-sdk \ phpdev \ vc11 \ x64. Php7.0.x requires vc14 Compilation. Therefore, the dependent files are decompressed to c: \ php-sdk \ phpdev \ vc14 \ x86 or c: \ php-sdk \ phpdev \ vc14 \ x64.
    • Download the required PHP source file, which can be found in the http://windows.php.net/download/, http://php.net/downloads.php, http://php.net/releases/, http://windows.php.net/downloads/releases/archives. Decompress it to the corresponding compiling folder. For example, decompress the php-5.4.45.tar.gz to c: \ php-sdk \ phpdev \ vc9 \ x86 \ php-5.4.45 or c: \ php-sdk \ phpdev \ vc9 \ x64 \ php-5.4.45, to compile the 32-bit and 64-bit versions respectively. Unzip the php-5.6.16.tar.gz to c: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.6.16 or c: \ php-sdk \ phpdev \ vc11 \ x64 \ php-5.6.16.
    • If the PHP extension is compiled, download the source code to the corresponding address, this article is runkit as an example, in the http://pecl.php.net/package/runkit. Decompress the downloaded source code to the ext folder of the PHP source code. In this example, decompress the downloaded source code to c: \ php-sdk \ phpdev \ vc9 \ x86 \ php-5.4.45 \ ext \ runkit, c: \ php-sdk \ phpdev \ vc9 \ x64 \ php-5.4.45 \ ext \ runkit, c: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.6.16 \ ext \ runkit, c: \ php-sdk \ phpdev \ vc11 \ x64 \ php-5.6.16 \ ext \ runkit.
  • Prepare the compiling environment:
    • To compile PHP with MSVC9, you need to download and install Windows SDK 6.1, which is an online installation version. You can also

      The http://download.microsoft.com/download/a/4/2/a4282359-1d35-4648-a7a7-d85e3bfe81ac/6.0.6001.16621.148.WindowsSDK_LonghornServer_IDS04_idw.WindowsSDK.DVD.Release.iso downloads the offline installation package.

      To compile the 32-bit version, you must select the x86compiler installation option when installing the Windows SDK 6.1. if no, you cannot find cl.exe.
    • When using MSVC11 to compile PHP, you can download Visual Studio 2012 Express for Windows Desktop, including the online and offline installation versions (ISO ).
    • The two tools do not conflict. they can be installed on the same system at the same time.

The following are the specific compilation steps. Some content will be repeated to allow the lazy students to follow the steps shown in the following illustration :)

  • Use MSVC9 to compile the 32-bit version of PHP5.4.33 (in this example, compile runkit. dll)
    • Install Windows SDK 6.1. Be sure to select the x86 compiler during installation.
    • Decompress the downloaded php-sdk-binary-tools-20110915.zip to c: \ php-sdk.
    • Open the Windows command line and enter the following command: cd c: \ php-sdk bin \ phpsdk_buildtree.bat phpdev
    • Unzip the downloaded php-5.4.45.tar.gz to c: \ php-sdk \ phpdev \ vc9 \ x86 \ php-5.4.45.
    • Unzip the downloaded deps-5.4-vc9-x86.7z to c: \ php-sdk \ phpdev \ vc9 \ x86 \ deps to overwrite the original deps folder.
    • Decompress the downloaded http://pecl.php.net/get/runkit-1.0.4.tgz to the c: \ php-sdk \ phpdev \ vc9 \ x86 \ php-5.4.45 \ ext folder, note that the folder name does not contain the version number, this example should be runkit, rather than runkit-1.0.4.
    • Create an object folder under c: \ php-sdk \ phpdev \ vc9 \ x86to store the final php.exe file and related dll files.
    • Click the Start menu, select Microsoft Windows SDK V6.1> CMD Shell, and start the compilation command line.
    • Run the following command: setenv/x86/xp/release (the command line is successfully executed, and the text of the command line will change to green) cd c: \ php-sdk bin \ phpsdk_setvars.bat cd phpdev \ vc9 \ x86 \ php-5.4.45 buildconf configure -- disable-all -- enable-cli -- enable-runkit = shared -- enable-object-out-dir = .. \ obj if you need to compile the non-thread Security Edition ), replace the last line with configure -- disable-all -- enable-cli -- enable-runkit = shared -- disable-zts -- enable-object-out-dir = .. \ obj finally executes nmake
    • Compile and php-runkit.dll are the compilation results.
    • Put the php-runkit.dll file in the ext folder of the PHP installation folder, modify php. ini, add extension = php_runkit.dll, and restart the PHP service.
  • Use MSVC9 to compile the 64-bit version of PHP5.4.33 (in this example, compile runkit. dll)
    • Install Windows SDK 6.1. Be sure to select the x86 compiler during installation.
    • Decompress the downloaded php-sdk-binary-tools-20110915.zip to c: \ php-sdk.
    • Open the Windows command line and enter the following command: cd c: \ php-sdk bin \ phpsdk_buildtree.bat phpdev
    • Unzip the downloaded php-5.4.45.tar.gz to the c: \ php-sdk \ phpdev \ vc9 \ x64 \ php-5.4.45.
    • Unzip the downloaded deps-5.4-vc9-x86.7z to c: \ php-sdk \ phpdev \ vc9 \ x64 \ deps to overwrite the original deps folder.
    • Decompress the downloaded http://pecl.php.net/get/runkit-1.0.4.tgz to the c: \ php-sdk \ phpdev \ vc9 \ x64 \ php-5.4.45 \ ext folder, note that the folder name does not contain the version number, this example should be runkit, rather than runkit-1.0.4.
    • Create an object folder in c: \ php-sdk \ phpdev \ vc9 \ x64to store the final php.exe file and related dll files.
    • Click the Start menu, select Microsoft Windows SDK V6.1> CMD Shell, and start the compilation command line.
    • Enter the following command: obviously different from the 32-bit program compiled above, you do not need to execute setenv/x86/xp/release cd c: \ php-sdk bin \ phpsdk_setvars.bat cd phpdev \ vc9 \ x64 \ php-5.4.45 buildconf configure -- disable-all -- enable-cli -- enable-runkit = shared -- enable-object-out-dir = .. \ obj if you need to compile the non-thread Security Edition ), replace the last line with configure -- disable-all -- enable-cli -- enable-runkit = shared -- disable-zts -- enable-object-out-dir = .. \ obj finally executes nmake
    • Compile and php-runkit.dll are the compilation results.
    • Put the php-runkit.dll file in the ext folder of the PHP installation folder, modify php. ini, add extension = php_runkit.dll, and restart the PHP service.
  • Use MSVC11 to compile the 32-bit version of PHP5.4.33 (in this example, compile runkit. dll)
    • Install Visual Studio 2012 Express for Windows Desktop.
    • Decompress the downloaded php-sdk-binary-tools-20110915.zip to c: \ php-sdk.
    • Open the Windows command line and enter the following command: cd c: \ php-sdk bin \ phpsdk_buildtree.bat phpdev
    • Unzip the downloaded php-5.6.16.tar.gz to c: \ php-sdk \ phpdev \ vc11 \ x64 \ php-5.6.16.
    • Unzip the downloaded deps-5.6-vc11-x64.7z to c: \ php-sdk \ phpdev \ vc11 \ x64 \ deps to overwrite the original deps folder.
    • Decompress the downloaded http://pecl.php.net/get/runkit-1.0.4.tgz to the c: \ php-sdk \ phpdev \ vc11 \ x64 \ php-5.6.16 \ ext folder, note that the folder name does not contain the version number, this example should be runkit, rather than runkit-1.0.4.
    • Create an object folder in c: \ php-sdk \ phpdev \ vc11 \ x64to store the final php.exe file and related dll files.
    • Click the Start menu, select Microsoft Visual Studio 2012> Visual Studio Tools> VS2012 x64 Cross Tools Command Prompt, and start the compilation Command line.
    • Run the following command: cd c: \ php-sdbin \ phpsdk_setvars.bat cd phpdev \ vc11 \ x64 \ php-5.6.16 buildconf configure -- disable-all -- enable-cli -- enable-runkit = shared -- enable-object-out-dir = .. \ obj if you need to compile the non-thread Security Edition ), replace the last line with configure -- disable-all -- enable-cli -- enable-runkit = shared -- disable-zts -- enable-object-out-dir = .. \ obj finally executes nmake
    • Compile and php-runkit.dll are the compilation results.
    • Put the php-runkit.dll file in the ext folder of the PHP installation folder, modify php. ini, add extension = php_runkit.dll, and restart the PHP service.
  • Use MSVC11 to compile the 64-bit version of PHP5.4.33 (in this example, compile runkit. dll)
    • Install Visual Studio 2012 Express for Windows Desktop.
    • Decompress the downloaded php-sdk-binary-tools-20110915.zip to c: \ php-sdk.
    • Open the Windows command line and enter the following command: cd c: \ php-sdk bin \ phpsdk_buildtree.bat phpdev
    • Unzip the downloaded php-5.6.16.tar.gz to c: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.6.16.
    • Unzip the downloaded deps-5.6-vc11-x86.7z to c: \ php-sdk \ phpdev \ vc11 \ x86 \ deps to overwrite the original deps folder.
    • Decompress the downloaded http://pecl.php.net/get/runkit-1.0.4.tgz to the c: \ php-sdk \ phpdev \ vc11 \ x86 \ php-5.6.16 \ ext folder, note that the folder name does not contain the version number, this example should be runkit, rather than runkit-1.0.4.
    • Create an object folder under c: \ php-sdk \ phpdev \ vc11 \ x86to store the final php.exe file and related dll files.
    • Click the Start menu, select Microsoft Visual Studio 2012> Visual Studio Tools> VS2012 x86 Native Tools Command Prompt, and start the compilation Command line.
    • Run the following command: cd c: \ php-sdk bin \ phpsdk_setvars.bat cd phpdev \ vc11 \ x86 \ php-5.6.16 buildconf configure -- disable-all -- enable-cli -- enable-runkit = shared -- enable-object-out-dir = .. \ obj if you need to compile the non-thread Security Edition ), replace the last line with configure -- disable-all -- enable-cli -- enable-runkit = shared -- disable-zts -- enable-object-out-dir = .. \ obj finally executes nmake
    • Compile and php-runkit.dll are the compilation results.
    • Put the php-runkit.dll file in the ext folder of the PHP installation folder, modify php. ini, add extension = php_runkit.dll, and restart the PHP service.

Possible problems:

  • If the There is no script engine for file extension ". js" error occurs, it indicates that the jscript engine of Windows is not properly registered. you can follow these steps:
    • Open the command line as an administrator:
    • Run the following command:

      Regsvr32 % WINDIR % \ System32 \ jscript. dllregsvr32 % WINDIR % \ SysWOW64 \ jscript. dll

    • Generate a jscript. reg file with the following content:

      Windows Registry Editor Version 5.00

      [HKEY_CLASSES_ROOT \. js] @ = "jsfile"

      [HKEY_CLASSES_ROOT \. js \ PersistentHandler] @ = "{5e941d80-bf96-11cd-b579-08002b30bfeb }"

      [HKEY_CLASSES_ROOT \ JSFile]

      "FriendlyTypeName" = hex (2):, 6d ,\

      00, 6f, 00, 6f, 25, 00, 5c, 00, 6d, 00 ,\

      , 00, 5c, 68, 00, 6c, 6c, 00, 2c ,\

      00, 2d, 38, 34, 00

      [HKEY_CLASSES_ROOT \ JSFile \ ScriptEngine] @ = "JScript"

      [HKEY_CLASSES_ROOT \ JSFile \ ScriptHostEncode] = "{85131630-480C-11D2-B1F9-00C04F86C324 }"

      [HKEY_CLASSES_ROOT \ JSFile \ Shell] @ = "Open"

      [HKEY_CLASSES_ROOT \ JSFile \ Shell \ Open \ Command]

      @ = Hex (2): 25, 00, 53,00, 79,00, 00, 6d, 00, 6f, 00, 6f, 25 ,\

      00, 5c, 00, 00, 00, 5c, 53, 00 ,\

      ,\

      , 22, 00, 00, 2a, 00

      [HKEY_CLASSES_ROOT \ JSFile \ Shell \ Open2]

      @ = Hex (2): 4f, 00, 6e ,\

      00, 6f, 00, 6d, 00, 6d, 00, 6e, 20, 00, 6f, 00, 6d, 00 ,\

      "MUIVerb" = hex (2): 40, 00, 25, 00, 53,00, 79,00, 00, 6d, 00, 6f, 00 ,\

      6f, 25, 00, 5c, 00, 00, 6d, 00, 5c ,\

      , 78, 00, 00, 2e, 00, 6c, 00, 00, 2c, 00, 2d, 00 ,\

      [HKEY_CLASSES_ROOT \ JSFile \ Shell \ Open2 \ Command]

      @ = Hex (2): 25, 00, 53,00, 79,00, 00, 6d, 00, 6f, 00, 6f, 25 ,\

      00, 5c, 00, 00, 00, 5c, 53, 00 ,\

      ,\

      , 22, 00, 00, 2a, 00

      [HKEY_CLASSES_ROOT \ JSFile \ Shell \ Print \ Command]

      @ = Hex (2): 25, 00, 53,00, 79,00, 00, 6d, 00, 6f, 00, 6f, 25 ,\

      00, 5c, 00, 00, 6d, 00, 5c, 00, 4e, 00, 6f, 00 ,\

      , 00, 00, 2f, 20 ,\

      , 25, 00, 00

      [HKEY_CLASSES_ROOT \ JSFile \ ShellEx \ DropHandler] @ = "{60254CA5-953B-11CF-8C96-00AA00B8708C }"

      [HKEY_CLASSES_ROOT \ JSFile \ ShellEx \ PropertySheetHandlers \ WSHProps] @ = "{60254CA5-953B-11CF-8C96-00AA00B8708C }"

      [HKEY_CLASSES_ROOT \ JScript] @ = "JScript Language"

      [HKEY_CLASSES_ROOT \ JScript \ CLSID] @ = "{f414c260-6ac0-11cf-b6d1-00aa00bbbb58 }"

      [HKEY_CLASSES_ROOT \ JScript \ OLEScript]

    • Double-click the file and click OK to import it to the registry.
  • If you encounter Checking for cl.exe when using MSVC9 to compile 32-bit PHP... When installing Windows SDK 6.1, you forget to select the x86 compiler.

PS:

  • Many of the above steps do not need to be performed step by step, especially the folder structure. C: \ php-sdk can be placed under any drive letter. You just need to execute an above: x: \ php-sdk \ bin \ php-setvars.bat before you start compilation (x: the drive letter of the php-sdk ).
  • Phpdev and its folders at different levels are not required, especially for x86 and x64 folders. it is not possible to put an error, but it is easy to identify the final compilation result. Just put deps and php source code in the same folder, for example, in d: Create a php-source folder, put desp, obj and php-5.6.16 subfolders under it (well, it doesn't matter where obj is put, directly point the location of the output results to obj at compilation), enter the php-5.6.16 folder for compilation.

In practice, I mainly refer to the following three articles and only thank you to the original author:

  • Build your own PHP on Windows
  • Extension compilation of php and Php in windows, extension of dll file compilation
  • Solve There is no script engine for file extension ". js" in Win7"
Related Article

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.