Skip to content

Instantly share code, notes, and snippets.

@ihabunek
Created June 26, 2015 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihabunek/47eed8bb22808b092301 to your computer and use it in GitHub Desktop.
Save ihabunek/47eed8bb22808b092301 to your computer and use it in GitHub Desktop.
Changes to PHP wiki
====== Build your own PHP on Windows ======
===== Before you Begin =====
Building PHP on Windows will require three things
- A properly set up build environment, including a compiler with the right SDK's and some binary tools used by the build system
- Prebuilt libraries and headers for third party libraries that PHP uses in the correct location
- The PHP source
===== The Build Environment =====
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 ====
* 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:
* Visual C++ 9.0 (Visual Studio 2008 or Visual C++ 2008) for 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.
* Various tools, see [[http://windows.php.net/downloads/php-sdk/]] for binary versions of them.
==== Setup ====
=== Quick 'n' Easy ===
- If compiling **PHP 5.3 or 5.4**:
- Install Visual Studio 2008 (no matter what version -express, pro or others; all should work) and install it
- Get and install Windows SDK 6.1
- If compiling **PHP 5.5+**:
- 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]]"
- Get PHP via [[http://git.php.net | git ]]
- 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“
- If compiling **PHP 5.3 or 5.4**:
- 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+**:
- 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>
- If compiling for **vc11**:
- Copy c:\php-sdk\phpdev\vc9 to c:\php-sdk\phpdev\vc11 (the buildtree script hasn't been updated for vc11)
- 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 using. For example C:\php-sdk\phpdev\vc11\x86\<php-source-directory>
- 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
- See also: http://wiki.php.net/internals/windows/libs
- Change directory to the location of your PHP source code: <code bash>cd C:\php-sdk\phpdev\vcXX\x86\php-source-directory</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>
- **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)
- 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>
=== Adding PECL extensions (using 'dbase' as an example) ===
- <code bash>cd C:\php-sdk\phpdev\vcXX\x86</code>
- 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 a 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:
* [[ 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.
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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment