Build PHP on Windows: Beta
← Home
Setting up your environment to build PHP is a REAL hassle, and involves a LOT of trial and error. Unfortunately I cannot guarantee these instructions will work for you, and it is a shame there is no automated way (script) to set this up for you. You'll need to be patient and really try to understand what is happening when something goes wrong.
Note: using git clone on my C drive fails, so I opted to use a non-system drive (E) which worked fine.
- Install VS2012, restart after installation is complete.
- Download the PHP SDK binary tools (get a php-sdk-binary-tools-{date}.zip from http://windows.php.net/downloads/php-sdk/) and extract them to E:\php-sdk\
- Run the "VS2012 x86 Native Tools Command Prompt" located in Start → All Programs → Microsoft Visual Studio 2012 → Visual Studio Tools
- Run the following commands:
E:
cd E:\php-sdk
bin\phpsdkvars.bat
bin\phpsdk_buildtree.bat phpdev
cd phpdev
mkdir E:\php-sdk\phpdev\vc11
mkdir E:\php-sdk\phpdev\vc11\x86
cd E:\php-sdk\phpdev\vc11\x86
- Now download the dependency package from: http://windows.php.net/downloads/php-sdk/
- Extract the package in the "E:\php-sdk\phpdev\vc11\x86" directory, you should end up with:
- E:\php-sdk\phpdev\vc11\x86\deps\
- bin\
- include\
- lib\
- share\
- ssl\
- ...\
- Now clone the PHP source into the x86 directory like so:
cd
git clone -b PHP-5.6 https://github.com/php/php-src
Note: This is where I had problems, if the drive you are using is also your system drive (such as C), then git clone may fail on this drive (not sure why). As an alternative, just download the PHP source and extract there. Ultimately I just resolved to use my E drive instead, since I planned to build the latest version often.
- Run:
cd php-src
- Optional: if you plan to work on PHP, make your own branch first.
git checkout -b myFeatureBranchName
- Run these commands:
buildconf
configure --with-prefix=E:\php-sdk-output\x86\php-5.6.0
nmake
nmake test
nmake snap
- Get dependencies:
- Downloand http://windows.php.net/downloads/php-sdk/deps-5.5-vc11-x86.7z
- Extract to E:\php-sdk\phpdev\vc11\x86
Build Xdebug for PHP
- Download the latest source from http://xdebug.org/download.php
- Extract the source to E:\php-sdk\phpdev\vc11\x86\pecl\
you end up with source files in E:\php-sdk\phpdev\vc11\x86\pecl\xdebug-x.x.x
- PHP will look for the files you add to the pecl folder, just like it does the deps folder. Now got back to the php-src directory:
cd E:\php-sdk\phpdev\vc11\x86\php-src
- Run the following command:
nmake clean
buildconf --force
configure --enable-debug --with-prefix=E:\php-sdk-output\x86\php-5.6.0 --with-xdebug=shared
nmake
nmake snap
Build PHP (x64) on Windows 7 with VS 2012 (VC11):
- do everything in x86 build, but replace step 5 with:
Run the "VS2012 x64 Cross Tools Command Prompt" located in Start → All Programs → Microsoft Visual Studio 2012 → Visual Studio Tools
- replace step 4 with:
cd E:\php-sdk
bin\phpsdk_setvars.bat
bin\phpsdk_buildtree.bat phpdev
cd phpdev
mkdir E:\php-sdk\phpdev\vc11
mkdir E:\php-sdk\phpdev\vc11\x64
cd E:\php-sdk\phpdev\vc11\x64
- Get dependencies:
- Downloand http://windows.php.net/downloads/php-sdk/deps-5.5-vc11-x64.7z
- Extract to E:\php-sdk\phpdev\vc11\x64
- replace step 7 with:
buildconf
configure --with-prefix=E:\php-sdk-output\x64\php-5.6.0
nmake
nmake test
nmake snap
Build (updated) OpenSSL Static Release libs
This is required if you want to use the configure option "--enable-phar-native-ssl". Which enables SSL in Phar.
- Download and install Active Perl from :http://www.activestate.com
- Download latest source from http://www.openssl.org/source/ (should be marked in red, or at least tagged with "[LATEST]")
- Extract the source to E:\openssl-src
- Open a git bash, then run the following commands:
mkdir E:\openssl-release
cd E:\openssl-src
perl Configure VC-WIN32 --prefix=E:\openssl-release
ms\do_ms
nmake -f ms\nt.mak
nmake -f ms\nt.mak test
nmake -f ms\nt.mak install
cd E:\openssl-release\lib
rename ssleay32.lib to ssleay32st.lib
rename libeay32.lib to libeay32st.lib
- Take the renamed libs and move them to "E:\php-sdk\phpdev\vc11\x86\deps\lib".
- Now rebuild PHP:
cd E:\php-sdk
bin\phpsdkvars.bat
cd E:\php-sdk\phpdev\vc11\x86\php-src
nmake clean
buildconf --force
paste your configure w/ your desired options (or use the one below)
nmake snap
Your files should be zipped in the file: E:\php-sdk\phpdev\vc11\x86\php-src\Release_TS\php-5.6.0-dev-Win32-VC11-x86.zip and E:\php-sdk\phpdev\vc11\x86\php-src\Release_TS\pecl-5.6.0-dev-Win32-VC11-x86.zip.
Notes: When you make changes to the environment (add new dependencies or modules) "nmake clean & buildconf --force) may not be enough. You may have to remove the php-src directory and re-download again. I found this to be the best way to get rid of compile errors after making changes to the build environment.
Finally this is these are the flags I passed to configure when building:
configure --with-prefix=E:\php-sdk-output\x86\php-5.6.0 ^
--enable-pdo ^
--enable-phar-native-ssl ^
--enable-soap=shared ^
--enable-mbstring=shared ^
--enable-mbregex=shared ^
--with-curl=shared ^
--with-mp=auto ^
--with-mysql=shared ^
--with-mysqli=shared ^
--with-openssl=shared ^
--with-sqlite3=shared ^
--with-tidy=shared ^
--with-xdebug=shared ^
--with-pdo-mysql=shared ^
--with-pdo-odbc=shared ^
--with-pdo-pgsql=shared ^
--without-t1lib ^
> ../configure.txt
Notice at the end I dump the output to a file
Disclaimers
This page is likely to change on a regular bases, until I consider the process accurate and stable, so check back regularly.