Saturday 6 November 2010

Build P4PHP on Windows

How do I build P4PHP on Windows?

Note that this article provides further detail for the steps listed in the P4PHP release notes, which can be found in the following location:

http://www.perforce.com/perforce/doc.current/user/p4phpnotes.txt

In order to obtain a P4PHP binary for Windows, you will need to set up a PHP build environment. This article describes the necessary steps needed to set up such an environment, as well as instructions on how to build PHP and P4PHP using that environment.

Building P4PHP on Windows will require the following three things:

A properly set up build environment, including Visual Studio with the right SDK and some binary tools used by the build system.

Prebuilt libraries and headers for third party libraries that PHP uses, placed in the proper location in the build environment.

The P4PHP source (ftp://ftp.perforce.com/perforce/r09.2/bin.tools/p4php.tgz).

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.

Microsoft Visual C++ -- PHP officially supports building with Visual C++ 6.0 or with Visual C++ 9 (also known as Visual C++ 2008). You can use the Express versions as well. MinGW and other compilers are NOT supported or even known to work. For more information and how to get the compiler see the supported versions. This article supposes that you are using Visual Studio 2008 Express.  Make sure the compiler has been updated with the latest service patch (SP1 at the time of this writing.)

PHP/P4PHP can also be compiled with Visual Studio 2010, as it includes the VS9 compiler.

The correct Windows SDK or Platform SDK to match your compiler. See Supported Windows/Platform SDK for the supported versions. SDK 6.1 is the one used by Visual Studio 2008, but SDK 7 will work as well.

Various tools. See http://pecl2.php.net/downloads/php-windows-builds/php-libs/binary-tools.zip for binary versions of them. The libbind and pcre libraries are not required.

Get Visual Studio 2008 or 2010. You can use any of the commercial editions or the Express Edition.

Get and install windows SDK 6.1 or SDK 7.1

Get a PHP 5.3 snapshot (do not extract yet!)

Create the folder c:\php-sdk

Unpack the binary-tools.zip archive (http://pecl2.php.net/downloads/php-windows-builds/php-libs/) into this directory; there should be one sub-directory called "bin" and one called "script".

Choose Start -> Microsoft Windows SDK v6.1 -> CMD Shell, and then enter the following commands:

setenv /x86 /xp /releasecd c:\php-sdk\bin\phpsdk_setvars.batbin\phpsdk_buildtree.bat php53dev

Now, extract the snapshot from (3) to C:\php-sdk\php53dev\vc9\x86 with your unpacker of choice (WinRAR should handle it) so that the following directory gets created: C:\php-sdk\php53dev\vc9\x86\php-

In the same directory ( C:\php-sdk\php53dev\vc9\x86 ) there is a "deps" folder, extract any of your required libraries inside that folder ( see http://wiki.php.net/internals/windows/libs ), but make sure their top-level contains "/include" and "/lib" (some of them have an extra directory level in there). You can find the pre-compiled libraries that you need here:  http://pecl2.php.net/downloads/php-windows-builds/php-libs/ ( VC9 is Visual Studio 2008, remember - you do not need libbind or pcre ).

Run in the windows-sdk-shell:

cd C:\php-sdk\php53dev\vc9\x86\php-

buildconf - this will clear any existing configuration.

To get an overview of the compiling flags:
configure --help

Create your configure command:
configure --disable-all --enable-cli --enable-pdo (and use --enable- to enable any other desired extensions).
Warning: some extensions need libraries, header files and helper apps, see libs, fetch the version you need and extract the archive in the deps directory: c:\php-sdk\php53dev\vc9\x86\deps). You will need to enable --with-pdo to be able to create the default PHP.

Run nmake.

The compiled php is now under C:\php-sdk\php53dev\vc9\x86\php-\Release_TS.

Now that you have a build environment capable of building PHP, we can build the P4PHP extension. We will build P4PHP as a DLL that can be added to the PHP installation.

Map p4php to the directory C:\php-sdk\php53dev\vc9\x86\php-\ext\p4_php. Note the directory is "p4_php", not "p4-php". This is because "p4-php" is a macro variable, and using this as a directory name would break the build.

In the SDK shell, go back to C:\php-sdk\php53dev\vc9\x86\php-. Reset the configuration:

buildconf

Configure with the following options. ",shared" instructs the compiler to create a dll.

configure --disable-all --enable-cli --enable-pdo --with-perforce=,shared  

Run nmake

nmake

php_perforce.dll should now be in the Release_TS directory.

To test it, you can copy the dll into the "ext" directory of an existing php installation.

To enable PHP to actually use the dll, you need to either run php from the command line with the option php.exe -d extension=php_perforce.dll, or you can hard-wire it in the php.ini file in the php distribution. See Installation, below.

Once you have built PHP/P4PHP, you will need to install it. This involves three steps:

Copy the PHP release tree (The Release_TS directory) to C:\PHP5. This is the recommended location. It can be placed elsewhere, but then you will need to edit the php.ini file so that it can find its extensions.
Create a php.ini file in the C:\Windows directory, or copy (as Administrator) one of the php.ini files in the PHP source tree to C:\Windows\php.ini: C:\Windows\system32>copy C:\php-sdk\php53dev\vc9\x86\php-\php.ini-production C:\Windows\php.ini 1 file(s) copied.

Edit the php.ini file to add the line extension=php_perforce.dll

NOTE: You can skip this step if not planning on doing anything other than testing P4PHP. Creating/Editing a php.ini file is outside the scope of this document. Just use php -d extension=php_perforce.dll when loading your test scripts. Add the C:\PHP5 directory to the PATH variable. (Start Menu -> Control Panel -> System ->Advanced Settings -> Environment Variables)

You can perform some quick tests of P4PHP. Note that the Windows version of PHP does not support interactive mode, so you will need to write up a script and then run it.

Before you do that, make sure that php is in the PATH and that Perforce is being loaded.

C:\users\bruno\Documents\local>php -VUsage: php [options] [-f] [--] [args...] php [options] -r [--] [args...] php [options] [-B ] -R [-E ] [--] [args...] php [options] [-B ] -F [-E ] [--] [args...] php [options] -- [args...] php [options] -a -a Run interactively -c | Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f Parse and execute . -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -r Run PHP without using script tags -B Run PHP before processing input lines -R Run PHP for every input line -F Parse and execute for every input line -E Run PHP after processing all input lines -H Hide any passed arguments from external tools. -s Output HTML syntax highlighted source. -v Version number -w Output source with stripped comments and whitespace. -z Load Zend extension . args... Arguments passed to script. Use -- args when first argument starts with - or script is read from stdin --ini Show configuration file names --rf Show information about function . --rc Show information about class . --re Show information about extension . --ri Show configuration for extension .C:\users\bruno\Documents\local>php -m[PHP Modules]CoredateeregpcrePDOperforceReflectionSPLstandard[Zend Modules]

If you see "perforce" listed in the modules then it is being loaded properly. Proceed to testing.

Place the following in a file named p4php_info.php.

identify());$p4->port = 'localhost:1666';$p4->user = 'bruno';$p4->connect();print_r($p4->run('info'));$p4->disconnect();?>

Now run p4php_info.php. You should see something like the following:

C:\users\bruno\Documents\local>php -f p4php_info.phpPerforce - The Fast Software Configuration Management System.Copyright 1995-2010 Perforce Software. All rights reserved.Rev. P4PHP/NTX86/2009.2/239532 (2009.2 API) (2010/03/24).Array( [0] => Array ( [userName] => bruno [password] => enabled [clientName] => test-ws [clientRoot] => c:\Users\bruno\Documents\local [clientCwd] => C:\Users\bruno\Documents\local [clientHost] => tombstone [clientAddress] => 192.0.0.1:1666 [serverName] => Bruno P4D [serverDescription] => Bruno test service [monitor] => enabled [security] => enabled [serverAddress] => Bruno:1666 [serverRoot] => C:\Program Files\Perforce\Server [serverDate] => 2010/03/29 15:09:00 -0700 Pacific Daylight Time [serverUptime] => 102:44:51 [serverVersion] => P4D/NTX64/2009.2/228098 (2009/12/16) [serverLicense] => none ))

View the original article here

No comments:

Post a Comment