Use VC9, VC11 to compile 32-bit, 64-bit PHP and its extensions in Windows systems

Source: Internet
Author: User
Tags php source code runkit vc9 zts

AOP is required in the project using the Runkit module, but the development environment for the team members is Windows, and the Runkit module does not provide DLL extensions in the Windows environment and compiles itself only.

The following is a summary of the compilation process. (Operating system environment for Windows 10 64-bit Chinese flagship edition)

  • Compiled version of PHP
    The version here refers not to the release version of PHP, such as 5.3, 7.0, but rather the compiler used at compile time, the program schema and whether it is thread-safe.
    This information can be printed out in Phpinfo.

    The PHP used in Miscrosoft is compiled with MSVC11 in Visual 2012, the program schema is x86 (that is, 32-bit), non-thread safe (NTS).

    PHP in, is compiled using Miscrosoft Visual 2012 MSVC11, the program schema is x64 (that is, 64-bit), thread safety (TS).

    Slightly different, there is no specific list item that describes the compiler version, the program schema, and only the information that is visible from the compile-time configuration. PHP here is compiled using Miscrosoft Visual 6 MSVC6, the program architecture is x86 (i.e. 32-bit), thread-safe (threads Safety = enabled).

    This last one, compiled with MSVC9 in Miscrosoft Visual 2008, has a program schema of x86 (that is, 32 bits), thread safety (TS).
    This article only discusses MSVC9 and MSVC11 compilation of two cases.
  • Prepare php-sdk and PHP source code
    The following steps are required, regardless of which version of PHP is compiled.
    • Download PHP-SDK:
      Can be found in http://windows.php.net/downloads/php-sdk/, download the Php-sdk-binary-tools-20110915.zip
    • Unzip to 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 VC6, VC8, and Vc9 subfolders.
      If you compile PHP with MSVC11, copy C:\php-sdk\phpdev\vc9 to C:\php-sdk\phpdev\vc11.
      If you compile PHP with MSVC14, copy C:\php-sdk\phpdev\vc9 to C:\php-sdk\phpdev\vc14.

    • Download the appropriate version of PHP's compile-time dependency package, see http://windows.php.net/downloads/php-sdk/.
      Unzip it to the x86 or x64 folder under the appropriate compilation folder, overwriting the Deps folder. Note to be consistent with the PHP release and program schema to be compiled, such as compiling the 32-bit version of php5.4.x, unzip the deps-5.4-vc9-x86.7z, such as the 64-bit version of the compiled php5.5.x to decompress deps-5.6-vc11-x64.7z, and so on.
      php5.4.x and php5.3.x usually need to be compiled with VC9, so their dependent files are extracted 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 with VC11, so their dependent files are extracted to c:\php-sdk\phpdev\vc11\x86 or c:\php-sdk\phpdev\vc11\x64.
      php7.0.x, however, needs to be VC14 compiled, so its dependent files are extracted to c:\php-sdk\phpdev\vc14\x86 or c:\php-sdk\phpdev\vc14\x64.
    • Download the PHP source files you need, in http://windows.php.net/download/, http://php.net/downloads.php, http://php.net/releases/,/http Windows.php.net/downloads/releases/archives/can be found in several places.
      The solution is suppressed under the corresponding compilation folder.
      For example:
      Unzip 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 its 32-bit and 64-bit versions separately.
      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 it is compiled PHP extension, then to the corresponding address to download the source code, this article is taking Runkit as an example, in Http://pecl.php.net/package/runkit.
      Download to the source code to extract the PHP source of the Ext folder, this example is extracted 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 compilation environment:
    • Using MSVC9 to compile PHP, you need to download and install Windows SDK 6.1, this address is downloaded in the online installation version. can also be in 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 Download the offline installation package.
      If you need to compile the 32-bit version, when installing Windows SDK 6.1, be careful to choose to install the x86 compiler, or you will not find cl.exe problems.
    • Using MSVC11 to compile PHP, you can download visual Studio for Windows Desktop with the online and offline installation (ISO) versions.
    • Two tools are not conflicting and can be installed on the same system at the same time.

The following is the specific compilation steps, some of the content will appear to repeat, is to let lazy classmate retrace, sample study:

  • Compile the 32-bit version of PHP5.4.33 with MSVC9 (this example compiles runkit.dll)
    • Install Windows SDK 6.1, and note that the x86 compiler is selected during installation.
    • Unzip 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 overwrite the original Deps folder.
    • Extract 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 the name of the folder without the version number, This example should be runkit, not runkit-1.0.4.
    • Create the obj folder under C:\php-sdk\phpdev\vc9\x86 to store the final Php.exe and associated DLL files.
    • Click the Start menu, select Microsoft Windows SDK v6.1>cmd Shell, and start the compile command line.
    • Enter the following command:
      Setenv/x86/xp/release (this line command executes successfully, the text of the command line turns 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
      To compile the non-thread-safe version (version nts), replace the last line above
      Configure--disable-all--enable-cli--enable-runkit=shared--disable-zts--enable-object-out-dir=. \obj
      Final execution
      Nmake
    • There are releases (thread-safe version-ts) or release_nts (non-thread-safe version-nts) folders in obj, where Php.exe and Php-runkit.dll are compiled results.
    • Put the Php-runkit.dll file in the Ext folder of the PHP installation folder, modify the php.ini, add the Extension=php_runkit.dll, restart the PHP service.
  • Compile the 64-bit version of PHP5.4.33 with MSVC9 (this example compiles runkit.dll)
    • Install Windows SDK 6.1, and note that the x86 compiler is selected during installation.
    • Unzip 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\x64\php-5.4.45.
    • Unzip the downloaded deps-5.4-vc9-x86.7z to c:\php-sdk\phpdev\vc9\x64\deps overwrite the original Deps folder.
    • Extract 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 the name of the folder without the version number, This example should be runkit, not runkit-1.0.4.
    • Create the obj folder under C:\php-sdk\phpdev\vc9\x64 to store the final Php.exe and associated DLL files.
    • Click the Start menu, select Microsoft Windows SDK v6.1>cmd Shell, and start the compile command line.
    • Enter the following directive: significantly different from the 32-bit program compiled above, there is no 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
      To compile the non-thread-safe version (version nts), replace the last line above
      Configure--disable-all--enable-cli--enable-runkit=shared--disable-zts--enable-object-out-dir=. \obj
      Final execution
      Nmake
    • There are releases (thread-safe version-ts) or release_nts (non-thread-safe version-nts) folders in obj, where Php.exe and Php-runkit.dll are compiled results.
    • Put the Php-runkit.dll file in the Ext folder of the PHP installation folder, modify the php.ini, add the Extension=php_runkit.dll, restart the PHP service.
  • Compile the 32-bit version of PHP5.4.33 with MSVC11 (this example compiles runkit.dll)
    • Install visual Studio Express for Windows Desktop.
    • Unzip 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 overwrite the original Deps folder.
    • Extract 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 the name of the folder without the version number, This example should be runkit, not runkit-1.0.4.
    • Create the obj folder under C:\php-sdk\phpdev\vc11\x64 to store the final Php.exe and associated DLL files.
    • Click the Start menu, select Microsoft Visual Studio 2012>visual Studio tools>vs2012 x64 Cross Tools command Prompt, and start the compile command line.
    • Enter the following command:
      CD C:\PHP-SDK
      Bin\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
      To compile the non-thread-safe version (version nts), replace the last line above
      Configure--disable-all--enable-cli--enable-runkit=shared--disable-zts--enable-object-out-dir=. \obj
      Final execution
      Nmake
    • There are releases (thread-safe version-ts) or release_nts (non-thread-safe version-nts) folders in obj, where Php.exe and Php-runkit.dll are compiled results.
    • Put the Php-runkit.dll file in the Ext folder of the PHP installation folder, modify the php.ini, add the Extension=php_runkit.dll, restart the PHP service.
  • Compile the 64-bit version of PHP5.4.33 with MSVC11 (this example compiles runkit.dll)
    • Install visual Studio Express for Windows Desktop.
    • Unzip 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 overwrite the original Deps folder.
    • Extract 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 the name of the folder without the version number, This example should be runkit, not runkit-1.0.4.
    • Create the obj folder under C:\php-sdk\phpdev\vc11\x86 to store the final Php.exe and associated DLL files.
    • Click the Start menu, select Microsoft Visual Studio 2012>visual Studio tools>vs2012 x86 Native Tools command Prompt, start the compile command line.
    • Enter 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
      To compile the non-thread-safe version (version nts), replace the last line above
      Configure--disable-all--enable-cli--enable-runkit=shared--disable-zts--enable-object-out-dir=. \obj
      Final execution
      Nmake
    • There are releases (thread-safe version-ts) or release_nts (non-thread-safe version-nts) folders in obj, where Php.exe and Php-runkit.dll are compiled results.
    • Put the Php-runkit.dll file in the Ext folder of the PHP installation folder, modify the php.ini, add the Extension=php_runkit.dll, restart the PHP service.

Problems you may encounter:

  • If you encounter a there is no script engine for file extension ". js" error, it means that the JScript engines of Windows are not registered correctly and can be resolved as follows:
    • To open the command line as an administrator:
    • Execute the following command:

      regsvr32%windir%\system32\jscript.dll
      regsvr32%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): 40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,\
      00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,\
      32,00,5c,00,77,00,73,00,68,00,65,00,78,00,74,00,2e,00,64,00,6c,00,6c,00,2c,\
      00,2d,00,34,00,38,00,30,00,34,00,00,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,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
      00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,53,00,\
      63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,00,31,\
      00,22,00,20,00,25,00,2a,00,00,00

      [Hkey_classes_root\jsfile\shell\open2]
      @=hex (2): 4f,00,70,00,65,00,6e,00,20,00,26,00,77,00,69,00,74,00,68,00,20,00,43,\
      00,6f,00,6d,00,6d,00,61,00,6e,00,64,00,20,00,50,00,72,00,6f,00,6d,00,70,00,\
      74,00,00,00
      "MUIVerb" =hex (2): 40,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,\
      6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,\
      00,77,00,73,00,68,00,65,00,78,00,74,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,\
      34,00,35,00,31,00,31,00,00,00

      [Hkey_classes_root\jsfile\shell\open2\command]
      @=hex (2): 25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
      00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,43,00,53,00,\
      63,00,72,00,69,00,70,00,74,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,00,31,\
      00,22,00,20,00,25,00,2a,00,00,00

      [Hkey_classes_root\jsfile\shell\print\command]
      @=hex (2): 25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
      00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,6f,00,\
      74,00,65,00,70,00,61,00,64,00,2e,00,65,00,78,00,65,00,20,00,2f,00,70,00,20,\
      00,25,00,31,00,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, click OK, and import it into the registry.
  • If you are using MSVC9 to compile 32-bit PHP, you encounter the checking for cl.exe ... <not found> error, which means that when you install Windows SDK 6.1 , you forget to select the x86 compiler.

Ps:

    • The above steps, in fact, there are many do not need to step-by, especially the folder structure. C:\PHP-SDK, in fact, can be placed under any disk character. Just before you start compiling, execute one: X:\php-sdk\bin\php-setvars.bat (x: Is the php-sdk of the letter).
    • Phpdev and all levels of folders are not required, especially the x86 and x64 folders, not misplaced, it is only convenient to identify the results of the final compilation. As long as the deps and PHP source is placed in the same folder, such as in D: Build Php-source folder, under which to place Desp, Obj and php-5.6.16 subfolders (well, it doesn't matter where obj is placed, direct the output position to obj at compile time), and go to the php-5.6.16 folder to compile.

In the practice process, the main reference is as follows three articles, only to the original author thanks:

    • Build your own PHP on Windows
    • PHP and PHP extensions compiled in Windows environment, extension DLL file compilation
    • Resolve Win7 under there is no script engine for file extension ". js"

Use VC9, VC11 to compile 32-bit, 64-bit PHP and its extensions in Windows systems

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.