internals:windows:stepbystepbuild

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
internals:windows:stepbystepbuild [2012/01/23 15:04] – add link in ldap section jmckennainternals:windows:stepbystepbuild [2019/11/15 21:57] (current) nikic
Line 1: Line 1:
 ====== Build your own PHP on Windows ====== ====== Build your own PHP on Windows ======
 +
 +> **This tutorial concerns building PHP before 7.2. To build PHP 7.2+, please refer to the [[internals:windows:stepbystepbuild_sdk_2|newer documentation]].**
  
 ===== Before you Begin ===== ===== Before you Begin =====
Line 8: Line 10:
   - The PHP source   - The PHP source
  
-===== The Build Environment ===== +===== Compiler =====
- +
-This is the hardest part of the PHP windows build system to set up and will take up a lot of space on your hard drive - you need to have several GB of space free.+
  
 ==== Requirements ==== ==== Requirements ====
  
-  * Microsoft Visual C++, PHP officially supports building with Visual C++ 6.0 or with Visual C++ 9 (also known as Visual C++ 2008 just to be confusing).  You can use the Express versions as well MinGW and other compilers are NOT supported or even known to work.  For more information and how to get the compiler see the [[internals:windows:compiler|supported versions]] +PHP officially supports building with Microsoft'Visual C++ compilers. MinGW and other compilers are NOT supported or even known to work. The free Express and Developer editions can also be used. For more information and how to get the compiler see the [[internals:windows:compiler|supported versions]]The following VC versions are supported:
-  * The correct Windows SDK or Platform SDK to match your compiler.   see this [[internals:windows:windowssdk|page]] for the supported versions +
-  * Various tools, see [[http://windows.php.net/downloads/php-sdk/]] for binary versions of them +
-===== Setup =====+
  
-== Quick 'n' easy ==+  * Visual C++ 9.0 (Visual Studio 2008 or Visual C++ 2008) for **PHP 5.4**. 
 +  * Visual C++ 11.0 (Visual Studio 2012) for **PHP 5.5 or 5.6**. 
 +  * Visual C++ 14.0 (Visual Studio 2015) for **PHP 7.0+**.
  
-  - get visual studio 2008 (no matter what version - [[http://www.microsoft.com/express/downloads/#Visual_Studio_2008_Express_Downloads express]], pro or others; all should work) and install it +If using VC9, you will also need the [[http://www.microsoft.com/en-us/download/details.aspx?id=11310|Windows SDK 6.1]] (see [[internals:windows:windowssdk|this page]] for additional info on the SDK)
-  - get and install windows sdk 6.1 +
-  - get a php 5.3 [[http://snaps.php.net | snapshot ]] (do not extract yet!) +
-  - create the folder “c:\php-sdk“ +
-  - unpack the binary-tools.zip archive (http://windows.php.net/downloads/php-sdk/) into this directory, there should be one sub-directory called “bin” and one called “script“ +
-  - open the “windows sdk 6.1 shell” (it’s available from the start menu group) and execute the following commands in it: +
-  - <code bash>setenv /x86 /xp /release</code> +
-  - <code bash>cd c:\php-sdk\</code> +
-  - <code bash>bin\phpsdk_setvars.bat</code> +
-  - <code bash>bin\phpsdk_buildtree.bat php53dev</code> +
-  - now extract the snapshot from 3) to C:\php-sdk\php53dev\vc9\x86 with your favourite unpacker (winrar should handle it) so that the following directory gets created: C:\php-sdk\php53dev\vc9\x86\php5.3-xyz +
-  - in the same directory (C:\php-sdk\php53dev\vc9\x86) there is a "deps" folder, extract any of your required libraries inside that folder (see http://wiki.php.net/internals/windows/libs) but make sure their top-level contains /include and /lib (some of them have an extra directory level in there) +
-  - run in the windows-sdk-shell: <code bash>cd C:\php-sdk\php53dev\vc9\x86\php5.3-xyz</code> +
-  - <code bash>buildconf</code> +
-  - to get an overview of the compiling flags: <code bash>configure --help</code> +
-  - create your configure command: <code bash>configure --disable-all --enable-cli --enable-$remains</code> (warning: some extensions need libraries, header files and helper apps, see [[internals/windows/libs]], fetch the version you need and extract the archive in the deps directory, ie: c:\php-sdk\php53\vc9\x86\deps) +
-  - <code bash>nmake</code> +
-  - if you want the resulting php to be zipped (comes handy for redist, believe me!), run after this also: <code bash>nmake snap</code> +
-  - the compiled php is now under C:\php-sdk\php53dev\vc9\x86\php5.3-SNAPSHOTTIME\Release_TS, same as the zip file (if you created it).+
  
-== Adding PECL extensions (using 'dbase' as an example) ==+==== Setup ====
  
-  - <code bash>cd C:\php-sdk\php53dev\vc9\x86</code> +  * If compiling **PHP 5.4**
-  - get the dbase extension code through Subversion +    * Install Visual Studio 2008 
-  - <code bash>svn co http://svn.php.net/repository/pecl/dbase/trunk pecl/dbase</code> +    * Install [[http://www.microsoft.com/en-us/download/details.aspx?id=11310|Windows SDK 6.1]] 
-  - <code bash>cd php5.3-xyz</code> +  * If compiling **PHP 5.5 or 5.6**: 
-  - <code bash>buildconf</code> +    * Install Visual Studio 2012. If using the express version, install "[[https://www.visualstudio.com/de/vs/older-downloads/|Visual Studio 2012 Express for Windows Desktop]]" 
-  - executing <code bash>configure --help</code> should now contain a dbase option +  * If compiling **PHP 7.0+**: 
-  - <code bash>configure --enable-cli --enable-dbase</code> +    * Install Visual Studio 2015
-  - <code bash>nmake</code> +
-  - test the binary with a <code bash>php -m</code> command, to make sure dbase exists+
  
-== LDAP Support Notes ==+==== Command prompt ====
  
-  - add "--with-ldap" to your configure +Each version of Visual Studio (or Windows SDK) provides a command prompt environment for compiling (available from the Start Menu group).
-  - make sure to package your generated binaries with libsasl.dll, which will not be built through this process - you must download it from one of the PHP [[http://windows.php.net/download/|official binary packages]]+
  
-=== Pitfalls ===+    * If compiling **PHP 5.4**, open the **"Windows SDK 6.1 shell"** and execute the following command in it: <code bash>setenv /x86 /xp /release</code> 
 +    * If compiling **PHP 5.5 or 5.6** open the **"VS2012 x86 Native Tools Command Prompt"** 
 +    * If compiling **PHP 7.0+** open either the **"VS2015 x64 Native Tools Command Prompt"** or the **"VS2015 x86 Native Tools Command Prompt"**.
  
-== fatal error C1900: [] mismatch between 'P1' version '200801116' and 'P2' version '20070207' ==+All commands in the rest of this document should be run in the appropriate command prompt.
  
-If you are using Visual Studio 2008 Express and Platform SDK 6.1 make sure you have the latest versions and check for version incompatibilities. There are known issues with old versions of VS 2008 Express and Platform SDK 6.1.  +===== Download prerequisites ===== 
 + 
 +  - Get the PHP source, there are two alternatives: 
 +    * download a source archive ([[http://windows.php.net/download/|Stable releases]], [[http://windows.php.net/qa/|QA releases]]) 
 +    * clone the [[http://git.php.net/|PHP Git repository]] ([[https://github.com/php/php-src|GitHub mirror]]) 
 +  - Get the binary tools: 
 +    * available from [[http://windows.php.net/downloads/php-sdk/]] 
 +    * the binary tools archives are named php-sdk-binary-tools-YYYYMMDD.zip, get the latest one 
 +  - Get the libraries on which PHP depends: 
 +    * download the packaged deps from [[http://windows.php.net/downloads/php-sdk/]] 
 +    * dependency archives are named ''deps-<php version>-<vc version>-<architecture>.7z'' 
 +    * chose the archive which matches your desired PHP version and architecture, for example ''deps-5.6-vc11-x86.7z'' 
 +    * **Note:** This should include the libraries needed to build most the core extensions. However, some other extensions may need additional libraries, header files and helper apps.  See [[internals/windows/libs]], fetch the version you need and extract the archive into the deps directory (see below). 
 + 
 +===== Setup the build directory ===== 
 + 
 +This should be done only once before building PHP. 
 + 
 +  - Create the build directory ''c:\php-sdk'' 
 +  - Unpack the binary tools archive into this directory, it should contain three sub-directories: ''bin'', ''script'' and ''share'' 
 +  - Open the command prompt and enter the build directory: <code bash>cd c:\php-sdk\</code> 
 +  - Run the ''buildtree'' batch script which will create the desired directory structure: <code bash>bin\phpsdk_buildtree.bat phpdev</code> 
 +  - The ''buildtree'' script hasn't been updated for newer versions of VC++ so: 
 +    * If compiling for **VC11**: copy ''C:\php-sdk\phpdev\**vc9**'' to ''C:\php-sdk\phpdev\**vc11**'' 
 +    * If compiling for **VC14**: copy ''C:\php-sdk\phpdev\**vc9**'' to ''C:\php-sdk\phpdev\**vc14**'' 
 +  - Extract the PHP source code to ''C:\php-sdk\phpdev\**vc##**\**x##**'', where: 
 +    * ''**vc##**'' is the compiler version you are using (''vc9'', ''vc11'' or ''vc14''
 +    * ''**x##**'' is your architecture (''x86'' or ''x64''
 +    * For example: ''C:\php-sdk\phpdev\vc11\x86\php-5.6.4-src'' 
 +  - In the same directory where you extracted the PHP source there is a ''**deps**'' directory. Here you will need to extract the libraries required to build PHP, which you downloaded in the perevious step (the ''deps-*.7z'' archive). 
 + 
 +===== Compile ===== 
 + 
 +  - Open the command prompt and enter the build directory: <code bash>cd c:\php-sdk\</code> 
 +  - Set up the build environment variables: <code bash>bin\phpsdk_setvars.bat</code> 
 +  - Change directory to the location of your PHP source code, e.g. <code bash>cd C:\php-sdk\phpdev\vc11\x86\php-5.6.4-src</code> 
 +  - Run: <code bash>buildconf</code> 
 +  - To get an overview of the compiling flags: <code bash>configure --help</code> 
 +  - Create your configure command: <code bash>configure --disable-all --enable-cli --enable-$remains</code> 
 +  - To build PHP, run: <code bash>nmake</code> 
 +  - If you want the resulting PHP builds and extensions to be zipped, after 'nmake' also run: <code bash>nmake snap</code> 
 +  - The compiled PHP is now under "C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS" If you ran 'nmake snap' the zip file will also be here. 
 +    * If you compiled with "--disable-zts" the compiled PHP will be under "C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release" 
 + 
 +==== Recompile after you have done some changes ==== 
 + 
 +  - Clean up old compiled binaries <code bash>nmake clean</code> 
 +  - If you need to update the 'configure' script <code bash>buildconf --force</code> 
 +  - Create your makefile: see [[internals/windows/release]]<code bash>configure --disable-all --enable-cli --enable-$remains</code> 
 +  - Compile <code bash>nmake</code> 
 + 
 +==== Building PECL extensions ==== 
 + 
 +Many PECL extensions already have prebuilt DLLs which can be downloaded from the extension page on the PECL web site. For example, on the [[https://pecl.php.net/package/APCu | APCu extension]] page, there are *DLL* links next to the release archive link. They lead you to a page where you can download the compiled extension for your desired PHP version and architecture. 
 + 
 +To build a PECL extension (for example APCu): 
 + 
 +  - Open the extension's page on PECL ([[https://pecl.php.net/package/APCu | APCu]]) 
 +  - Download the extension source either by: 
 +    * downloading a source archive 
 +    * fetching the source from the extension's repository (link can be found under *Browse Source*) 
 +  - Create a directory named **''pecl''** on the same level as your PHP source directory, e.g. ''C:\php-sdk\phpdev\vc11\x86\pecl'' 
 +  - Extract or clone the extension source code to the ''pecl'' directory 
 +    * if cloning, clone to a subdirectory, e.g. ''C:\php-sdk\phpdev\vc11\x86\pecl\apcu'' 
 +    * source code archive should already contain a subdirectory named e.g. ''apcu-4.0.7'' 
 +  - Open a command prompt, run the ''setvars'' script, and enter your PHP source directory 
 +  - Rebuild the configure script by running: <code bash>buildconf</code> 
 +  - Executing ''configure --help'' should now contain an option to enable APCu <code>--enable-apcu    Whether to enable APCu support</code> 
 +  - Configure and build: <code bash>configure --disable-all --enable-cli --enable-apcu</code><code>nmake</code> 
 +  - Test the binary with a ''php -m'' command, to make sure APCu is loaded 
 + 
 +At this point, your compiled extension will be located in the release directory. 
 + 
 +Additional Links: 
 +  * [[ http://www.ksingla.net/2010/05/adding-a-pecl-extension-to-your-php-build-environment/ | Adding a PECL extension to your PHP build environment ]] 
 +  * [[http://php.net/manual/en/install.pecl.windows.php | Installing a PHP extension ]] 
 + 
 +==== LDAP Support Notes ==== 
 + 
 +  - Add "--with-ldap" to your configure 
 +  - Make sure to package your generated binaries with libsasl.dll, which will not be built through this process - you can find it inside your C:\php-sdk\php53dev\vc9\x86\deps\bin\ folder, or you can download it from one of the PHP [[http://windows.php.net/download/|official binary packages]] 
 + 
 +===== Pitfalls ===== 
 + 
 +**fatal error C1900: [] mismatch between 'P1' version '200801116' and 'P2' version '20070207'** 
 + 
 +If you are using Visual Studio 2008 Express and Platform SDK 6.1 make sure you have the latest versions and check for version incompatibilities. There are known issues with old versions of VS 2008 Express and Platform SDK 6.1.
  
 The order in which you install the Visual Studio 2008 Express Edition and Platform SDK 6.1 is important due to the issue reported in [[http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc&displaylang=en#ctl00_ctl13_Overview|Windows SDK for Windows Server 2008 and .NET Framework 3.5 Overview]], [[http://blogs.msdn.com/b/windowssdk/archive/2009/08/07/windows-sdk-for-server-2008-v6-1-overwrites-vs2008-sp1-crt-files.aspx|Windows SDK for Server 2008 (v6.1) overwrites VS2008 SP1 CRT files]] and [[http://blogs.msdn.com/b/windowssdk/archive/2009/08/07/installing-windows-sdk-for-server-2008-v6-1-after-vs2008-sp1-causes-conflicts-with-security-update-kb971092.aspx|Installing Windows SDK for Server 2008 (v6.1) after VS2008 SP1 causes conflicts with Security Update (KB971092)]]. Install the SDK first, with any of its service packs and security updates before installing Visual Studio 2008 Express Edition. The order in which you install the Visual Studio 2008 Express Edition and Platform SDK 6.1 is important due to the issue reported in [[http://www.microsoft.com/downloads/en/details.aspx?FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc&displaylang=en#ctl00_ctl13_Overview|Windows SDK for Windows Server 2008 and .NET Framework 3.5 Overview]], [[http://blogs.msdn.com/b/windowssdk/archive/2009/08/07/windows-sdk-for-server-2008-v6-1-overwrites-vs2008-sp1-crt-files.aspx|Windows SDK for Server 2008 (v6.1) overwrites VS2008 SP1 CRT files]] and [[http://blogs.msdn.com/b/windowssdk/archive/2009/08/07/installing-windows-sdk-for-server-2008-v6-1-after-vs2008-sp1-causes-conflicts-with-security-update-kb971092.aspx|Installing Windows SDK for Server 2008 (v6.1) after VS2008 SP1 causes conflicts with Security Update (KB971092)]]. Install the SDK first, with any of its service packs and security updates before installing Visual Studio 2008 Express Edition.
  
 Make sure that you are running setenv /xp /x86. For example, setenv /xp /x64 or setenv /vista /x64 causes the above error message even if you are using Visual Studio 2008 Express SP1 and Platform SDK 6.1 (60001.18000.367) on a Vista 64bit system. Make sure that you are running setenv /xp /x86. For example, setenv /xp /x64 or setenv /vista /x64 causes the above error message even if you are using Visual Studio 2008 Express SP1 and Platform SDK 6.1 (60001.18000.367) on a Vista 64bit system.
 +
 +===== Utilities =====
 +
 +==== Resource Hacker ====
 +
 +Utility to show dependency information and other assembly information from a DLL. For instance, it shows which version of the Visual C++ Runtime the DLL was linked against.
 +
 +Get it here: http://angusj.com/resourcehacker/
internals/windows/stepbystepbuild.1327331058.txt.gz · Last modified: 2017/09/22 13:28 (external edit)