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
Next revisionBoth sides next revision
internals:windows:stepbystepbuild [2015/03/26 00:01] – fixed heading levels cmbinternals:windows:stepbystepbuild [2016/07/04 14:16] – The developer command prompt for VS2015 doesn't necessarily work cmb
Line 8: Line 8:
   - 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 ====
  
-  * PHP officially supports building with Microsoft's Visual C++ compilers.  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]].  The following VC versions are supported: +PHP officially supports building with Microsoft's 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:
-    * Visual C++ 6.0 for PHP 5.2 +
-    * Visual C++ 9.0 (Visual Studio 2008 or Visual C++ 2008) for PHP 5.3 and 5.4.  You can use the Express versions as well. +
-    * Visual C++ 11.0 (Visual Studio 2012) for PHP 5.5+.  You can use the Express versions as well.+
  
-  * If using VC9 or earlier, you will need the correct Windows SDK or Platform SDK to match your compiler See this [[internals:windows:windowssdk|page]] for the supported versions. +  * Visual C++ 9.0 (Visual Studio 2008 or Visual C++ 2008) for **PHP 5.4**. 
-  * Various tools, see [[http://windows.php.net/downloads/php-sdk/]] for binary versions of them.+  * 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+**. 
 + 
 +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)
  
 ==== Setup ==== ==== Setup ====
  
-=== Quick 'n' Easy ===+  * If compiling **PHP 5.4**: 
 +    * Install Visual Studio 2008 
 +    * Install [[http://www.microsoft.com/en-us/download/details.aspx?id=11310|Windows SDK 6.1]] 
 +  * If compiling **PHP 5.5 or 5.6**: 
 +    * Install Visual Studio 2012. If using the express version, install "[[https://www.microsoft.com/en-us/download/details.aspx?id=34673|Visual Studio 2012 Express for Windows Desktop]]" 
 +  * If compiling **PHP 7.0+**: 
 +    * Install Visual Studio 2015
  
-  - If compiling **PHP 5.3 or 5.4**+==== Command prompt ==== 
-    - Install Visual Studio 2008 (no matter what version -expresspro or others; all should work) and install it + 
-    - Get and install Windows SDK 6.1 +Each version of Visual Studio (or Windows SDK) provides a command prompt environment for compiling (available from the Start Menu group). 
-  If compiling **PHP 5.5+**: + 
-    - Install Visual Studio 2012. If using the express version, install "Visual Studio 2012 Express for Windows Desktop+    * 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> 
-  - Get PHP via [[http://git.php.net | git ]] +    If compiling **PHP 5.5 or 5.6** open the **"VS2012 x86 Native Tools Command Prompt"** 
-  - Create the folder “c:\php-sdk“ +    If compiling **PHP 7.0+** open either the **"VS2015 x64 Native Tools Command Prompt"** or the **"VS2015 x86 Native Tools Command Prompt"**. 
-  - Unpack the binary-tools.zip archive (http://windows.php.net/downloads/php-sdk/) into this directorythere should be one sub-directory called “bin” and one called “script“ + 
-  - If compiling **PHP 5.3 or 5.4**+All commands in the rest of this document should be run in the appropriate command prompt. 
-    - Open the "Windows SDK 6.1 shell" (it's available from the start menu group) and execute the following command in it<code bash>setenv /x86 /xp /release</code> + 
-  If compiling **PHP 5.5+**: +===== Download prerequisites ===== 
-    Open "VS2012 x86 Native Tools Command Prompt" (it's available from the start menu group)+ 
-  - Execute the following commands: <code bash>cd c:\php-sdk\</code> <code bash>bin\phpsdk_setvars.bat</code> <code bash>bin\phpsdk_buildtree.bat phpdev</code> +  - Get the PHP source, there are two alternatives: 
-  - If compiling for **vc11**: +    * download a source archive ([[http://windows.php.net/download/|Stable releases]], [[http://windows.php.net/qa/|QA releases]]) 
-    - Copy c:\php-sdk\phpdev\vc9 to c:\php-sdk\phpdev\vc11 (the buildtree script hasn't been updated for vc11) +    * clone the [[http://git.php.net/|PHP Git repository]] ([[https://github.com/php/php-src|GitHub mirror]]) 
-  - Now extract the PHP source code to C:\php-sdk\phpdev\**vcXX**\x86 with your favorite unpacker (7-zip should handle it) where **vcXX** is the compiler version you are usingFor example C:\php-sdk\phpdev\vc11\x86\<php-source-directory> +  - Get the binary tools
-  - In the same directory (C:\php-sdk\phpdev\vcXX\x86) there is a "deps" folder Here you will need to extract all the libraries required to build PHP.  We have packaged the required deps for most of the core extensions at http://windows.php.net/downloads/php-sdk/. Simply download the appropriate file that matches your PHP version and extract to C:\php-sdk\phpdev\vcXX\x86\deps +    * available from [[http://windows.php.net/downloads/php-sdk/]] 
-    See alsohttp://wiki.php.net/internals/windows/libs +    * the binary tools archives are named php-sdk-binary-tools-YYYYMMDD.zipget the latest one 
-  - Change directory to the location of your PHP source code<code bash>cd C:\php-sdk\phpdev\vcXX\x86\php-source-directory</code>+  - 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>   - Run: <code bash>buildconf</code>
   - To get an overview of the compiling flags: <code bash>configure --help</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>   - Create your configure command: <code bash>configure --disable-all --enable-cli --enable-$remains</code>
-    **Note:** The deps located at http://windows.php.net/downloads/php-sdk/ 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, i.e.: c:\php-sdk\phpdev\vcXX\x86\deps) +  To build PHP, run: <code bash>nmake</code>
-  - 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>   - 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.   - 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"+    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 ===+==== Recompile after you have done some changes ====
  
   - Clean up old compiled binaries <code bash>nmake clean</code>   - Clean up old compiled binaries <code bash>nmake clean</code>
Line 61: Line 91:
   - Compile <code bash>nmake</code>   - Compile <code bash>nmake</code>
  
-=== Adding PECL extensions (using 'dbase' as an example) ===+==== Building PECL extensions ====
  
-  - <code bash>cd C:\php-sdk\phpdev\vcXX\x86</code> +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 page where you can download the compiled extension for your desired PHP version and architecture.
-  - Get the dbase extension code through Subversion +
-  - <code bash>svn co http://svn.php.net/repository/pecl/dbase/trunk pecl/dbase</code> +
-  - <code bash>cd php-source-directory</code> +
-  - <code bash>buildconf</code> +
-  - Executing <code bash>configure --help</code> should now contain dbase option +
-  - <code bash>configure --enable-cli --enable-dbase</code> +
-  - <code bash>nmake</code> +
-  - Test the binary with a <code bash>php -m</code> command, to make sure dbase exists+
  
-  * Additional Links: +To build a PECL extension (for example APCu):
-    * [[ 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 ===+  - 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   - 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]]   - 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 ====+===== Pitfalls ====
 + 
 +**fatal error C1900: [] mismatch between 'P1' version '200801116' and 'P2' version '20070207'**
  
-**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.
-** +
-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.
Line 92: Line 132:
 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 ====+===== Utilities =====
  
-=== Resource Hacker ===+==== 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. 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/ Get it here: http://angusj.com/resourcehacker/
internals/windows/stepbystepbuild.txt · Last modified: 2019/11/15 21:57 by nikic