PHP, Zend Framework and Other Crazy Stuff
Compiling PHP for Windows Vista using Visual C++ Express 2008 – Seriously!
Over the past week or so I’ve been figuring out how to compile PHP on Windows, specifically Windows Vista. It’s been an interesting ride since I’m not very familiar with compiling on Windows to start with. However with some perseverence, and the help of all *two* useful online sources of information for the task of compiling PHP on Windows, I got around to accomplishing it.
The main source of information available is an excellent guide written by Elizabeth Marie Smith in December 2006 about compiling PHP5 and PHP-GTK2 using Visual C++ Express. The other basically refers back to Elizabeth’s article and adds some details on needing ICU to compile PHP6. If you are currently using Windows XP and Visual C++ Express 2005, then you need look no further. This is the single most informative source about compiling PHP on Windows that I could locate.
If you are using Windows Vista, or intend updating/using Visual C++ Express 2008, then my blog entry is largely another coat of sugar on top of Elizabeth’s guide to clear up any difference between the two approaches. There certainly are differences, but they are not overwhelming – esp. since I’ll lay them out below
. This set of instructions assumes you are building for Vista (32bits). If you want to compile for 64bits for Vista, see http://msdn2.microsoft.com/en-us/library/x4d2c09s(VS.90).aspx which may help.
You need to download, and install:
1. Virtual Clone Drive 5
2. 7-Zip or WinRAR
3. Microsoft Visual Studio 2008 Express
4. Microsoft Windows SDK for Vista Update
5. Microsoft .NET Framework SDK 2.0
Installing The Windows Vista Compilation Environment
The reason for downloading Virtual Clone Drive is to allow us to mount ISO disk images. The downloads for VCE2008 and the Windows SDK for Vista are especially large, and I just found it handy to download the ISO versions so I could install multiple times without going through the web install options multiple times, or for multiple machines. WinRAR or 7-Zip should be available to decompress standard gzip/bzip tarballs where a zip download option does not exist. Download and install these at your leisure.
So, the first major download is Microsoft Visual Studio 2008 Express. This was released in the last month (as of writing) so I chose to use it. You can use VCE2005 on Vista but VCE2008 skips a lot of the setup tasks VCE2005 required to integrate with the Windows SDK.
At the bottom of the download page you can find the all-in-one ISO download. It packs quite a punch but includes the C++, C#, VB and Web Developer editions of Visual Studio Express including SQL Server, .NET Framework 3.5 (required!) and Silverlight. Actually MS seem to be pushing Silverlight (sort of a Flash alternative) since the page has Silverlight elements that prompt you to download and install the runtime.
If you took the web install option, just follow the setup instructions and accept the default installation path. You don’t require Silverlight or SQL Server to compile PHP so feel free to deselect those options. If you downloaded the ISO you need to mount the ISO disk image using Virtual Clone Drive. To do so open My Computer, right-click the virtual drive, select “mount…”, find the ISO image to mount, and accept. It should now autorun and execute the setup program – see the instructions at the beginning of this paragraph. Note installation may take some time. Start up VCE at least once (sometimes wants to setup the environment) and make sure the register it (you’ll need an MS Passport or Email account to do this, e.g. Hotmail).
A word of interest. VCE2008 will also install v6.0A of the Windows SDK. I tried compiling PHP using this SDK version but it didn’t seem to work out well. If you have any success doing so let me know via a comment. Otherwise let’s press on and install v6.0 of the Windows SDK which VCE2008 seems to prefer using anyway.
The second major download is Microsoft Windows SDK for Vista Update. Please be aware this is updated from time to time and the current update is dated March 2007. New versions are generally commented on in the attached Additional Information of the download page. Again, this the ISO download which is pretty heavy. There’s an alternative web install option if you have a speedy reliable connection. Download and mount the ISO using Virtual Clone Drive as described earlier. During setup accept the default options and proceed. As with VCE2008, installation may take some time to complete.
The third download is the Microsoft .NET Framework SDK 2.0. Download and install using the default options. I’m not completely certain where PHP needs the .NET SDK – I can compile PHP with some standard options without it installed. Giving the benefit of the doubt, it’s probably needed somewhere for something for someone so there’s no harm installing it and avoiding any future obscure problems. Unlike the Windows SDK which VCE2008 will automatically detect and include, you need to integrate the .NET SDK into VCE2008. This is accomplished by editing VCE’s vcvars32.bat file – try looking for it in:
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat
To edit, you first need to copy it to your desktop (you’ll find other Vista editing VCE files is a task in futility even if you have an administrator account). Open in a text editor like notepad, and locate the lines setting the environmental variables PATH, INCLUDE and LIB. At the end of each, you should append the relevant path to the .NET Framework SDK BIN, INCLUDE and LIB directories just before the closing variable. Make sure you have semi-colons (;) between each added path. There’s nothing else needed – vcvars32.bat is executed automatically whenever the VCE2008 Command Line tool is started, and it will detect other needed paths for the Windows SDK installed earlier.
If you’re still here, give yourself a pat on the back. The torture is almost over. The very last step is to fix some problem PHP has finding a file called winres.h which doesn’t exist. What you need to do is locate the file called WinResrc.h in C:\Program Files\Microsoft SDKs\Windows\v6.0\Include, copy it to the desktop, rename it to winres.h, and copy it back into the Windows SDK v6.0 include directory. You won’t be able to copy&rename it on the spot, because Vista really doesn’t like that
.
Downloading PHP and Libraries To Allow Compilation
You have three main choices about what to compile. PHP 5.2.X where the source code for the latest stable version is available. PHP 5.2/5.3-dev which has regular snapshots of the source code for this development branch published to http://snaps.php.net/. Or PHP 6 development which also has published snapshots. I’m using PHP 5.3-dev.
Note: Under Windows Vista, possibly given the updated from XP’s Windows Platform SDK to Vista’s Windows SDK (no “Platform), there is a bug in PHP 5.2.X which causes a compilation error in source code related to ipv6 (presumably) in ./main/network.h of the source code. You can comment out the offending line reported in the compile error to force a successful compile of PHP 5.2 but it will probably break ipv6 which may not be a good thing. The error is not evident when compiling PHP 5.3-dev so it will likely not be a problem by the time PHP 5.3.0 is released.
Whatever your choice, download the source code.
Create a root directory on C:\ called “PHPDEV”. Copy the PHP source code archive into this directory and extract it using WinRAR or 7-Zip. Since I despise command line typing I usually rename it to “php-x.x” so it’s easier to navigate there without remembering the timestamp
.
Next you need to download the libraries and header files PHP and it’s extensions may need. These are not included in the source code package but available from individual websites and download locations. Luckily, Edin Kadribašić keeps an archive of these in a single easy to update download which includes the standard ones and those needed for PECL extensions. So download http://files.edin.dk/php/win32/zip.zip, copy it to C:/PHPDEV, and extract it there.
If you intend compiling PHP6, you will also require the ICU (International Components for Unicode) libraries available from http://www.icu-project.org/download/. The current release is 3.8.x, and if you check the ICU4C download page the downloads include binary distributions for Win32. The mscv8 prefix refers to these been built for the Microsoft MSCVR80 C runtime – which VCE2008 tends to use. Older downloads of ICU4C for version 3.6.x were built for MSCVR71 if required. Download and extract into C:/PHPDEV.
And we’re done. If you were bothered by the number of directories don’t worry – when compiling PHP, the required files will be looked for in sibling directories of the PHP source code automatically.
Compiling PHP on Windows Vista using Visual C++ Express 2008
Now we get to the good part, where we find out if this all worked or failed miserably. If it does fail don’t get too dejected – I’ve given up on this working first time out. I find I have to restart my PC a few times before VCE gets the messages and starts using the right environmental variables. This might just be my PC though – registering VCE2008 failed a few times before I managed to get through.
Note: PHP compiled under this set of instructions will require the MSCVR80 Microsoft C runtime (also fondly known as mscvr80.dll) which is generally available on Windows Vista. Windows XP or earlier probably uses mscvr71.dll which generally means you should install MSCVR80 on any XP system (if not already present) if you intend deploying your newly compiled PHP there. Get it from http://www.microsoft.com/downloads/details.aspx?familyid=32BC1BEE-A3F9-4C13-9C99-220B62A191EE&displaylang=en.
So! From the Start Menu, find the Visual Studio Express 2008 folder and click it. From Tools, select the VCE2008 Command Line tool. It should open a standard MS-DOS console window – the main thing is that it should also have executed vcvars32.bat automatically so this console is ready to start some heavy duty compiling.
Navigate to your PHP source code directory at C:\PHPDEV\php-5.3 (or whatever yours may be called). Compiling PHP from hereon out should be fairly typical – just bear in mind some options may require you to download additional libraries. For example, we already know PHP6 requires the additional ICU4C libraries. Many others will use the files we downloaded from Edin’s site.
From the command line run:
buildconf.bat
This will generate a configure script containing all the possible options to configure PHP with. This includes the typical configure options, and others based on the available extensions.
You can run the following the list all the available options:
cscript /nologo configure.js –help
We’ll test everything using a simple configure line. I’m re-reading Sara Goleman’s book so I’ll borrow the starting configure line from there since it seems suitable (as well as minimal!). This is a good first step before jumping into adding new configure options. It will only create a command line executable, adding configure options for Apache/MySQL or other exotics is left to your own devices.
cscript /nologo configure.js –without-xml –without-wddx –without-simplexml –without-dom –without-libxml –disable-zlib –without-sqlite –disable-odbc –disable-cgi –enable-cli –enable-debug –without-iconv
Once you’ve run the above, there’s only one more step. Take a deep breath, relax and run:
nmake
This usually takes a while, and generates a ludicrous number of warnings. Warnings under Windows are par for the course so they’re nothing to get worried about. Takes about 5-10 minutes on my PC, and slower on older machines. Once it’s done (hopefully without experiencing any compile errors; a bit more fatal than mere warnings
) you should find it’s created a new directory in your PHP source code location called Debug_TS. Inside there’s a sparkly new php.exe file waiting for you. Unlike a traditional Windows PHP binary, don’t expect to see many .dll files for extensions – .dll extensions are only generated if an extension has been compiled “shared”, otherwise it’s just lumped into PHP. You may also notice the absence of a php.ini file (or it’s dist/recommended templates). This is normal. I’ll explain
Change to the Debug_TS directory where the PHP binary is located, and run the command:
php -v
You should now have executed PHP using the command line, and received a few lines of output giving the PHP version, and it’s compile time. From here you can experiment with configure options to get exactly what you need and delve ever deeper into the dark world of compiling PHP on Windows…;).
Last bit – to install PHP somewhere after installation, set the installation path using the –enable-prefix=C:\path\to\php configure option before compiling. Once compiled, call:
nmake install
That’s all I have for now. If anything more needs explaining I’ll edit this blog entry for it. In the meantime I hope this small article helps someone out who like me is crazy enough to need to compile PHP on Windows for some reason
. Good luck!
Related posts:
| Print article | This entry was posted by Pádraic Brady on December 17, 2007 at 2:22 pm, and is filed under Irishisms, PHP General, PHP Security. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
-
Elizabeth Smith
-
http://blog.astrumfutura.com Pádraic Brady
-
http://www.aatraders.com Mark Dickenson
-
http://blog.astrumfutura.com Pádraic Brady
-
Compiler
-
Leo
-
http://cmsreview.net sf
-
http://www.celebies.com Spaiz
-
http://blog.astrumfutura.com Pádraic Brady
-
http://liquidsoft.eu Georgi Sokolov
-
Sebastian
-
Mark Jeffries
