How to compile PHP from Source on Windows
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: How to compile PHP from Source on Windows

  1. #1
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851

    How to compile PHP from Source on Windows

    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.

    1) Download and install Visual C++ Express. I used VC2008 Express:
    http://www.microsoft.com/express/downloads/

    2) Download and install 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:
    Code:
    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.
    Code:
    cd /d c:\php-sdk\
    8) Set some vars:
    Code:
    bin\phpsdk_setvars.bat
    9) build a directory tree:
    Code:
    bin\phpsdk_buildtree.bat php53dev
    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:
    Code:
    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:
    Code:
    buildconf
    14) To get an idea of what your config options are, type this in the CMD Shell:
    Code:
    configure --help
    15) I chose this configuration and it seems to work. CMD Shell:
    Code:
    configure --enable-apache2-2handler --with-curl --enable-fileinfo --enable-mbstring --enable-mbregex --with-mcrypt --with-openssl --with-pgsql --enable-sockets --with-mysql --with-mysqli --enable-pdo --with-pdo-mysql --with-pdo-mssql --with-pdo-pgsql --enable-soap --with-xmlrpc --with-xsl
    16) make the project. this should take some time. CMD Shell:
    Code:
    nmake
    if you have problems, try this as it will remove old stuff and try to make everything all fresh. CMD Shell:
    Code:
    nmake clean all
    17) if you want the resulting php to be zipped for redist, run this too:
    Code:
    nmake snap
    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:
    Code:
    C:\php-sdk\php53dev\vc9\x86\php-5.3.3\Rele
    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.
    Last edited by sneakyimp; 07-28-2010 at 07:48 PM.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  2. #2
    Not Yet Involved Shrike's Avatar
    Join Date
    Oct 2003
    Location
    The Eighth, Sursamen
    Posts
    2,277
    Nice post there, worthy of a sticky.
    The Hundredth Idiot

  3. #3
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851
    Why can I not edit this post? I'd like to make some corrections.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    Quote Originally Posted by sneakyimp View Post
    Why can I not edit this post?
    You can only edit your post(s) for a certain number of hours after the initial post was made.

    If you want to make corrections, feel free to post them as a new reply and I'd be glad to merge them into your original post above.

  5. #5
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851
    Thanks BG. Gonna take a bit...i'm trying to sort out debugging setup at the moment. total nightmare.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    13
    Hello sneakyimp,
    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
    Nodes
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRange
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodeOb
    ject
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodePo
    int
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangeNodes
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangePointN
    ode
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrNewRangePoints

    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrRangeToFunctio
    n
    php5ts.dll.def : error LNK2001: unresolved external symbol xmlXPtrWrapLocationSe
    t
    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'
    Stop.

    Regards and Thanks,

    Antrikssh...

  7. #7
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    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.

  8. #8
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851
    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.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  9. #9
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,862
    Quote Originally Posted by sneakyimp
    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.
    If you can get PHP 5.5 built to run on Windows XP it would be a bonus
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  10. #10
    Junior Member
    Join Date
    Jun 2012
    Posts
    13
    Hello Everyone,

    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.

    May this will help some one......

    Thanks and Regards,
    Antrikssh...........

  11. #11
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851
    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.
    Quote 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 >:
    Quote 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
    these errors:

    C:\php-sdk\php54dev>nmake php_intl.dll | find "error"

    Microsoft (R) Program Maintenance Utility Version 10.00.40219.01
    Copyright (C) Microsoft Corporation. All rights reserved.

    .\win32/php_stdint.h(101) : error C2371: 'int_fast16_t' : redefinition;
    different basic types
    .\win32/php_stdint.h(105) : error C2371: 'uint_fast16_t' : redefinition;
    different basic types
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
    Studio 10.0\VC\BIN\cl.exe"' : return code '0x2'
    Stop.

    I did not dig into it to find out how to solve it, because I also got
    VC++ Runtime errors. VC9 is good enough for the moment.

    Jan
    And then a follow-on message from Jan:
    Quote Originally Posted by Jan Ehrhardt
    php_intl version PECL-3.0.0b1 compiled fine with VC10. And the VC++
    Runtime errors were caused by php_couchbase.dll. No big deal.
    I'm not sure exactly what all this means as I haven't had time to try anything myself. Hope this helps. If you like, you can follow the goings-on in the internals mailing list here.

    I also got this response:
    Quote Originally Posted by Anatoliy
    that wiki page is pretty much up to date. Also, if you have windows
    specific questions, there is internals-win@lists.php.net .
    Let me know if you guys want me to ask a specific question over there.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  12. #12
    Junior Member
    Join Date
    Jun 2012
    Posts
    13
    Hi,
    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.

    Windows-Xp(SP-3 32BIT)
    php-5.3 Source code.
    Apache 2.2
    dep folder for(php-5.3)
    Windows- SDK(v.7) for 32 bit.
    VC++ - 2010

    Thanks and Regards,
    Antrikssh...
    Last edited by Antrikssh; 01-02-2013 at 06:21 AM.

  13. #13
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,851
    Quote Originally Posted by Weedpacket View Post
    If you can get PHP 5.5 built to run on Windows XP it would be a bonus
    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.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

  14. #14
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,862
    Quote Originally Posted by sneakyimp
    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".
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  15. #15
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,414
    Quote Originally Posted by Weedpacket View Post
    "we don't care if it doesn't build for XP".
    ... which isn't a bad policy at all, considering that XP lost support from its creators back in 2009.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •