In my quest to learn php extension development, I have been told I need to compile PHP from source. Given that it was a bit tricky, I thought I would document it here because chances are I'll need to refer back to this at some point. I did all of this on my Win XP machine. Details may vary on different OS versions. This is based largely on this wiki.
The following steps resulted in a build using Windows SDK 6.1.
3) Create a folder to put everything in. I used C:\php-sdk so that's what I'll refer to in the following steps.
4) Download and unpack the PHP Binary Tools Archive into C:\php-sdk. Make sure you see a bin and script folder in there.
5) Open the 6.1 SDK's CMD shell. I did this by selecting Start -> All Programs -> Microsoft Windows SDK v6.1 -> CMD Shell.
6) set some env vars:
setenv /x86 /xp /release
7) CD to this dir. Note I had to use the /d flag for some reason to get the cd command to work. You may or may not need it.
cd /d c:\php-sdk\
8) Set some vars:
9) build a directory tree:
If this command complains, try creating the directory [b]C:\php-sdk\php53dev[/code] first.
10) Download the PHP source you'd like to compile and extract it in C:\php-sdk\php53dev\vc9\x86. I downloaded my source from the link at the top of this page. DO NOT BOTHER with the binaries. Just get the source. The resulting folder should be something like C:\php-sdk\php53dev\vc9\x86\php-5.3.X
11) You need to fetch some code libraries that PHP uses and put them in the deps folder located at C:\php-sdk\php53dev\vc9\x86\deps. Rather than building them yourself, I recommend you download them from this page. Note that page may list more than one version of a given library. Get the latest one. I downloaded them all and saved the zip archives in my deps folder and unzipped them there. Each zip archive should contain a bin, lib, and maybe an include folder so make sure when you extract them into the deps folder that they should put their contents in the lib/bin/include folder there rather than in some other folder name.
12) In the CMD Shell window, change dirs again:
cd /d C:\php-sdk\php53dev\vc9\x86\php5.3-X
Again, I had to use the /d flag to get this to work. you may be able to leave it out.
13) In the CMD Shell, execute this command:
14) To get an idea of what your config options are, type this in the CMD Shell:
15) I chose this configuration and it seems to work. CMD Shell:
16) make the project. this should take some time. CMD Shell:
if you have problems, try this as it will remove old stuff and try to make everything all fresh. CMD Shell:
nmake clean all
17) if you want the resulting php to be zipped for redist, run this too:
18) the compiled php EXEs and DLLs are now under C:\php-sdk\php53dev\vc9\x86\php5.3-X\Release_TS.
You can try running the newly compiled version of PHP. NOTE that if you had php installed previously, you need to type the complete path to the new PHP.exe or you'll just be interacting with your previously installed version. Also, the newly compiled php doesn't find an INI file so you need the -n flag. Try this:
ase_TS\php.exe -n -i | more
This lets you page through the output of phpinfo() by hitting the space bar.
That's it for now. I'm not really sure how to install this just yet. There are some useful tips for setting your path and file assocations here and hereHints and tips are welcome.
I want to install php(any version) in my windows-7 system (64 bit). According to you instruction I have installed Windows-SDK v7 because its latest one along with vc++ 2010 because when I read the system requirement of SDK v7 in that they mention " you cannot use the .NET 4 tools with Visual Studio 2008". And I also face some problem during compilation when I used vc++ 2008. Now I am using Windows-7, Win-SDK v7, php-5.4.10-src, deps-5.4-vc9-x86. But after follow your instruction after doing nmake I got Linker error :--
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewLocationSet
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRange
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodeOb
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodePo
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodes
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangePointN
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangePoints
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrRangeToFunctio
php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrWrapLocationSe
php5ts.dll.def : error LNK2001: unresolved external symbol zError
php5ts.dll.def : error LNK2001: unresolved external symbol zlibCompileFlags
php5ts.dll.def : error LNK2001: unresolved external symbol zlibVersion
x64\Release_TS\php5ts.lib : fatal error LNK1120: 1601 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0
\VC\Bin\amd64\cl.exe"' : return code '0x2'
I don't think I was ever brave enough to compile PHP on Windows (or even use Windows for any server-related role ), but based on those compiler errors, it sounds like you're missing (or VS can't find) the libxml and zlib libraries.
I'm not super-duper windows guy, but if you check the original wiki you will see that they don't support VC 10. Also, as far as I can tell, the steps I published above use SetEnv to set /x86 and /xp -- I'm not certain but I believe this will mean that you are trying to compile a 32-bit PHP (**sigh**) and telling the compiler that windows xp is your target platform.
Unfortunately, the wiki has not been updated recently. I'll see if I can contact the PHP-DEV mailing lost or the PHP-DOC mailing lists and ask for a new set of instructions that is more current.
Thanks for giving me your precious time. I found the solution that day only. I want to share my experience with all of you so that my post will help others. Solution of the problem is , we have to complie the code in 32 bit environment. I mean to say that whatever is the cpu architercture(x86, x64) we have to compile the code in x86.
setenv /x86 /yourOS(x86/x64) /release
follow all the step that define above. On more thing you complie the php source files in x86 env. so you have to use the library code that php use is also for x86. This will remove linking error that I got during my exercise.
Sorry for my belated response. I have been traveling.
Thanks for the detail, Antrikssh. What value did *you* actually use for /yourOS(X86/X64) ?
Also, I got some detail from the PHP-DEV mailing list. The lines starting with > were my original questions.
Originally Posted by Pierre
> In particular, there are a couple of aspects to that wiki entry that look a
> bit old:
> * setenv flag of /x86 -- what about 64-bit?
x64 builds are not yet officially supported. However nothing prevents one to do it. It should build fine.
> * setenv flag of /xp -- what about win 7?
This sets the minimum windows version for PHP 5.3 or 5.4. It obviously creates bins compatible with Windows 7 or even windows 8.
5.5 will use windows 7 as a minimum version
> * setenv flag of /2008 -- what about VC++ 2010?
5.3 and 5.4 builds are done using vc9 (vs 2008). It is strongly recommended to use vc9 to build extensions targetting 5.3 or 5.4.
There was a response to Pierre's message from Jan Ehrhardt. Pierre's original comments start with >:
Originally Posted by Jan Ehrhardt
> x64 builds are not yet officially supported.
Not yet? That sounds if x64 will be supported sometime. Will it?
> However nothing prevents one to do it. It should build fine.
If you can get all dependencies right. For x86 many of them are
available at http://windows.php.net/downloads/php-sdk/
But, for instance, libiconv_a.lib is nowhere available as precompiled
binary for x64. And MS Visual C/C++ with "nmake" is no longer supported
by GNU since iconv 1.11.1. So you will have to cook your own Makefiles
or VCproj files. At the moment I am compiling 1.14 for x64 in VC10, but
with the v90 Platform Toolset, so you'll end up with VC9 libs after all.
About the deps on downloads/php-sdk: I see you are using different deps
for PHP 5.3 and PHP 5.4 nowadays. Are the differences great?
When I compile PHP for x86 I always use the same deps. Only for the non
standard extensions couchdb and eAccelarator I have to use different
sources because their PHP 5.4 adjustments are not backwards compatible.
> 5.3 and 5.4 builds are done using vc9 (vs 2008). It is strongly recommended
> to use vc9 to build extensions targetting 5.3 or 5.4.
What are the plans for 5.5? A transition to VC10? I once tried to use my
existing php-sdk setup to compile PHP 5.4 with VC10, but not all
compilations succeeded. Compilation failed for php_intl.dll failed with
I agree with your research because according to whatever I experienced during this exercise, I felt that working on php extension is not that much easier on x64 bit because lack of support. I don't know about the php-5.5 because I never worked on that but with php-5.4 source code have lot of issue regarding to Apache 2.2. Windows-SDk will build php5apache2_2.dll file but it won't work with the apache 2.2. Even php-5.4 is not working with the apache-2.2 it work with apache 2.4. Not even this issue I faced lot of issue regarding to php-5.4. So if you are working with php-extension, you have to work with x86 (in present scenario). I have used following combination that gave me correct working path for php-extension.
php-5.3 Source code.
dep folder for(php-5.3)
Windows- SDK(v.7) for 32 bit.
VC++ - 2010
Weedpacket, can you give me any detail about the problems you are having? I'd be happy to post it to the windows internal list.
Oh, I haven't had any problems - mainly because I haven't got around to trying it yet. It's a reference to Step 6 of the build process. It's not clear whether the policy is "it won't build for XP" or "we don't care if it doesn't build for XP".