标签 PHP 下的文章

PECL (PHP Extension Community Library) is conceptually very similar to PEAR. PECL contains C extensions for compiling into PHP. As C programs, PECL extensions run more efficiently than PEAR packages. If you follow the following procedure, you can build PECL extensions together with the PHP binary package.

I. Prerequisite: You must finish the Build PHP Binary with the default modules successfully.

II. Download the PECL source code:

  1. My example is trying to compile the xdebug and APC extensions.
    1. xdebug: Download it at http://pecl.php.net/package/xdebug
    2. APC: Download it at http://pecl.php.net/package/APC
  2. Unzip the downloaded zip files and put them under C:\php-sdk\php54dev\vc9\x86\pecl. They will look like the following screenshots:

III. Compile:

  1. Set the environment: Open the “Windows SDK 6.1 Shell” (it’s available from the start menu group) and execute the following commands in it. If you are using 64 bit system, don't try to change the parameter to /x64, otherwise during the make period, you will see tons of WARNING.
    set PATH=D:\php-sdk\bin;%PATH%
    setenv /x86 /xp /release
    cd c:\php-sdk\
    bin\phpsdk_setvars.bat

    You will get the following screen:
  2. Build the configuration file for creating the make file:
    cd C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src
    buildconf

    If you get an error like:
    Input Error: There is no script engine for file extension ".js".


    You need to edit the buildconf.bat file as below:

    Run the buildconf again:
    buildconf

    You will get the following screen:

    A new configuration file: configure.js will be created as below:

    Now, you can check the configuration options:
    configure --help

    If you get the following error again:
    Input Error: There is no script engine for file extension ".js".

    Please edit the configure.bat file and add /e:jscript after the /nologo.

    Run the configure --help again:
    configure --help

    If you installed the Cygwin, you can use the following commands to check if the APC and xdebug are included in the configuration file:
    configure --help | grep apc
    configure --help | grep xdebug

    If the APC and xdebug are included, you will see the following screen:
  3. Create the make file:
    configure --disable-snapshot-build --disable-debug-pack --disable-ipv6 --disable-zts --disable-isapi --disable-nsapi --without-t1lib --without-mssql --without-pdo-mssql --without-pi3web --without-enchant --enable-com-dotnet --with-mcrypt=static --disable-static-analyze --with-xdebug=shared --enable-apc

    If you run it successfully, you will see the screen as below. Pls check if the apc and xdebug extensions are included:
  4. Make the binary package by typing nmake:
    nmake

    Wait for a while, if you see this result, you succeeded.

    You will also find a new "Release" directory appeared under C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src as below. If you see the php_xdebug.dll, it means the xdebug DLL has been created.

    Check the module:
    C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src\Release\php.exe -m

    If you can see the apc in the screen as below, it means the apc module was compiled successfully in the PHP binary:

Congratulations! You are all done!

This 1st step will prove your environment setup is correct. Make sure you can finish this step successfully before going to the 2nd step.

I. Environment and related Packages:

  1. Microsoft Visual C++ 2008 Express Edition with SP1:
    1. Another name is MSVC9. Download it at http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express
    2. The recent PHP binary packages are compiled in MSVC9 environment. This tutorial is for MSVC9. Please don't use the Microsoft Visual C++ 2010 or later, which will not be compatible with the current PHP Windows Binaries.
    3. If you want MSVC6 environment, you need to install the Microsoft Visual C++ 6.0 and Windows Server 2003 SP1 Platform SDK at http://www.microsoft.com/en-us/download/details.aspx?id=6510
  2. Windows SDK 6.1:
    1. You must use the Windows SDK instead of the SDK included in above MSVC9. For building PHP5.3, you need to use Windows SDK 6.1 (Windows SDK for Windows Server 2008 and .NET Framework 3.5, http://www.microsoft.com/en-us/download/details.aspx?id=11310#Overview). For more information regarding the SDK, please seehttps://wiki.php.net/internals/windows/windowssdk
  3. PHP SDK Binary Tools:
    1. Download a zip file from http://windows.php.net/downloads/php-sdk/. What I downloaded on 8/7/2012 was php-sdk-binary-tools-20110915.zip
    2. Unzip it, rename and move the folder to C drive. The file structure will look like the following screenshot:
  4. Dependable libs:
    1. Download a zip file from http://windows.php.net/downloads/php-sdk/. What I downloaded was deps-5.4-vc9-x86.7z on 8/3/2012.
    2. Create directory tree like: C:\php-sdk\php54dev\vc9\x86
    3. Unzip the zip file and move the deps directory under C:\php-sdk\php54dev\vc9\x86. So, it will be like the following screenshot:
  5. PHP5.4 Sources:
    1. Download the source code from http://windows.php.net/download/ (click the "Download source code" link)
    2. After unzip move it under C:\php-sdk\php54dev\vc9\x86\, You can name this folder to what you like. Mine is as below:

      Now you are ready to compile!

II. Compile:

  1. Set the environment: Open the “Windows SDK 6.1 Shell” (it’s available from the start menu group) and execute the following commands in it. If you are using 64 bit system, don't try to change the parameter to /x64, otherwise during the make period, you will see tons of WARNING.
    set PATH=D:\php-sdk\bin;%PATH%
    setenv /x86 /xp /release
    cd c:\php-sdk\
    bin\phpsdk_setvars.bat

    You will get the following screen:
  2. Build the configuration file for creating the make file:
    cd C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src
    buildconf

    If you get an error like:
    Input Error: There is no script engine for file extension ".js".


    You need to edit the buildconf.bat file as below:

    Run the buildconf again:
    buildconf

    You will get the following screen:

    A new configuration file: configure.js will be created as below:

    Now, you can check the configuration options:
    configure --help

    If you get the following error again:
    Input Error: There is no script engine for file extension ".js".

    Please edit the configure.bat file and add /e:jscript after the /nologo.

    Run the configure --help again:
    configure --help

    If you can get the following screen, it means you successfully created the configuration file:
  3. Create the make file:
    configure --disable-snapshot-build --disable-debug-pack --disable-ipv6 --disable-zts --disable-isapi --disable-nsapi --without-t1lib --without-mssql --without-pdo-mssql --without-pi3web --without-enchant --enable-com-dotnet --with-mcrypt=static --disable-static-analyze

    If you run it successfully, you will see the screen as below:

  4. Make the binary package by typing nmake:
    nmake

    Wait for a while, if you see this result, you succeeded.

    You will also find a new "Release" directory appeared under C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src as below:
  5. Test the PHP Binary files:
    # Check PHP Version
    C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src\Release\php.exe -v
    # It is same to phpinfo()
    C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src\Release\php.exe -i
    # Check PHP modules
    C:\php-sdk\php54dev\vc9\x86\php-5.4.5-src\Release\php.exe -m
    

    If you can get the results properly, you are all done!

Although I think that running PHP and MySQL applications on Linux is more natural and easy to be implemented, sometimes I am still asked to install PHP applications on Windows and use MS SQL Server as database.

My environment is:

  • Windows 2003R2 in VirtualBox
  • IIS 6
  • MS SQL Server 2005

1. Install PHP on IIS:
1.1 Download the PHP:

1.1.1 For the latest version of PHP for Windows, please go to:
http://windows.php.net/download/

1.1.2For the older version of PHP, please go to:
http://www.php.net/releases/

Because I need to install ODBTP Database Connector to connect to MS SQL Server, and the ODBTP said that it only support several version of PHP including 5.1.1, I have to install PHP 5.1.1 instead of the latest version.

When you download, you need to select Windows binary.

1.2 Unzip the the file downloaded and rename move it to a folder under C drive called:
C:\php511

In case you want to test another version of PHP, you can download another one and name it as:
C:\php532 or similar. But you need to change other configuration as below to make it work.

1.3 Setup System Environment:
1.3.1 Right click "My Computer" and select "Properties", or go to "Start" --> "Run" --> Type: sysdm.cpl, a "System Properties" window will pop up.

Select "Advanced" --> "Environment Variables". At "System variables", click "Path", then click "Edit", add "C:\php511" (same as the path in above (2)) at the end. It should be like:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\php511

The purpose of this variable is telling system the location of the PHP's Dlls and Executable files.

1.3.2You also need to add a new System variable here. Please click "New", type the "Variable name" as "PHPRC", "Variable value" as "C:\php511".

The purpose of this variable is telling the location of php.ini (PHP Configuration File) to the system.

1.4 Install and Configure IIS Extension to run PHP:
There are 3 options to run PHP on IIS: CGI, ISAPI and FastCGI. Here is the comparison of the three:

Performance (from low to high): CGI < FastCGI < ISAPI
Stability (from low to high): ISAPI < FastCGI < CGI

It is very obvious that the FastCGI is the most balanced option. FastCGI is an IIS Extension provided by Microsoft to make IIS more supportive to PHP and other Open Source applications.

1.4.1 Download and Install FastCGI:

Go to: http://www.server7.iis.net/download/FastCGI to download the x86 or x64 version installation file according to your computer's architecture.

Click the installation file fcgisetup_1.5_rtw_x86.msi and follow the instruction to install it.

1.4.2 Configure the FastCGI to make it work with the PHP you installed:

1.4.2.1 Web Service Extensions --> FastCGI Handler

Open your IIS Manager which is located in "Administrative Tools", or you can just run "inetmgr". In the "Web Service Extensions", you will see a "FastCGI Handler" was already there, also it was "Allowed". It should be always allowed, otherwise your PHP and FastCGI will not work.

PHP IIS

1.4.2.2 Add .php Application Extensions Mapping:

In the same IIS Manager, right click the "Web Sites", select "Properties" --> "Home Directory" --> "Configuration" --> "Mapping",