Sunday, 5 January 2014

Build your own PHP on Windows

Before you Begin

Building PHP on Windows will require three things
  1. A properly set up build environment, including a compiler with the right SDK's and some binary tools used by the build system
  2. Prebuilt libraries and headers for third party libraries that PHP uses in the correct location
  3. The PHP source

The Build Environment

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.

Requirements

  • PHP officially supports building with Microsoft's Visual C++ compilers. 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. The following VC versions are supported:
    • Visual C++ 6.0 for PHP 5.2
    • Visual C++ 9.0 (Visual Studio 2008) for PHP 5.3 and 5.4. You can use the Express versions as well.
    • Visual C++ 11.0 (Visual Studio 2012) for PHP 5.5+. You can use the Express versions as well.
  • If using VC9 or earlier, you will need the correct Windows SDK or Platform SDK to match your compiler. See this page for the supported versions.
  • Various tools, see http://windows.php.net/downloads/php-sdk/ for binary versions of them.

Setup

Quick 'n' Easy
  1. If compiling PHP 5.3 or 5.4:
    1. Install Visual Studio 2008 (no matter what version - express, pro or others; all should work) and install it
    2. Get and install Windows SDK 6.1
  2. If compiling PHP 5.5+:
    1. Install Visual Studio 2012 ( VS 2012 Downloads). If using the express version, install “Visual Studio 2012 Express for Windows Desktop”
  3. Get PHP via git or a snapshot (do not extract yet!)
  4. Create the folder “c:\php-sdk“
  5. Unpack the binary-tools.zip archive (http://windows.php.net/downloads/php-sdk/) into this directory, there should be one sub-directory called “bin” and one called “script“
  6. If compiling PHP 5.3 or 5.4:
    1. Open the “Windows SDK 6.1 shell” (it's available from the start menu group) and execute the following command in it:
      setenv /x86 /xp /release
  7. If compiling PHP 5.5+:
    1. Open “VS2012 x86 Native Tools Command Prompt” (it's available from the start menu group):
  8. Execute the following commands:
    cd c:\php-sdk\
    bin\phpsdk_setvars.bat
    bin\phpsdk_buildtree.bat phpdev
  9. Now extract the PHP source code to C:\php-sdk\phpdev\vcXX\x86 with your favorite unpacker (7-zip should handle it) where vcXX is the compiler version you are using. For example C:\php-sdk\phpdev\vc11\x86\<php-source-directory>
  10. In the same directory (C:\php-sdk\phpdev\vcXX\x86) there is a “deps” folder. Here you will need to extract all the libraries required to build PHP. We have packaged the required deps for most of the core extensions at http://windows.php.net/downloads/php-sdk/. Simply download the appropriate file that matches your PHP version and extract to C:\php-sdk\phpdev\vcXX\x86\deps
  11. Change directory to the location of your PHP source code:
    cd C:\php-sdk\phpdev\vcXX\x86\php-source-directory
  12. Run:
    buildconf
  13. To get an overview of the compiling flags:
    configure --help
  14. Create your configure command:
    configure --disable-all --enable-cli --enable-$remains
    1. Note: The deps located at http://windows.php.net/downloads/php-sdk/ should include the libraries needed to build most the core extensions. However, some other extensions may need additional libraries, header files and helper apps. See libs, fetch the version you need and extract the archive into the deps directory, i.e.: c:\php-sdk\phpdev\vcXX\x86\deps)
  15. Build PHP, run:
    nmake
  16. If you want the resulting PHP builds and extensions to be zipped, after 'nmake' also run:
    nmake snap
  17. The compiled PHP is now under “C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release_TS”. If you ran 'nmake snap' the zip file will also be here.
    1. If you compiled with ”–disable-zts” the compiled PHP will be under “C:\php-sdk\phpdev\vcXX\x86\php-source-directory\Release”
Recompile after you have done some changes
  1. Clean up old compiled binaries
    nmake clean
  2. If you need to update the 'configure' script
    buildconf --force
  3. Create your makefile: see release
    configure --disable-all --enable-cli --enable-$remains
  4. Compile
    nmake
Adding PECL extensions (using 'dbase' as an example)
  1. cd C:\php-sdk\phpdev\vcXX\x86
  2. Get the dbase extension code through Subversion
  3. svn co http://svn.php.net/repository/pecl/dbase/trunk pecl/dbase
  4. cd php-source-directory
  5. buildconf
  6. Executing
    configure --help
    should now contain a dbase option
  7. configure --enable-cli --enable-dbase
  8. nmake
  9. Test the binary with a
    php -m
    command, to make sure dbase exists
LDAP Support Notes
  1. Add ”–with-ldap” to your configure
  2. Make sure to package your generated binaries with libsasl.dll, which will not be built through this process - you can find it inside your C:\php-sdk\php53dev\vc9\x86\deps\bin\ folder, or you can download it from one of the PHP official binary packages

Pitfalls

fatal error C1900: [] mismatch between 'P1' version '200801116' and 'P2' version '20070207'
If you are using Visual Studio 2008 Express and Platform SDK 6.1 make sure you have the latest versions and check for version incompatibilities. There are known issues with old versions of VS 2008 Express and Platform SDK 6.1.
The order in which you install the Visual Studio 2008 Express Edition and Platform SDK 6.1 is important due to the issue reported in Windows SDK for Windows Server 2008 and .NET Framework 3.5 Overview, Windows SDK for Server 2008 (v6.1) overwrites VS2008 SP1 CRT files and Installing Windows SDK for Server 2008 (v6.1) after VS2008 SP1 causes conflicts with Security Update (KB971092). Install the SDK first, with any of its service packs and security updates before installing Visual Studio 2008 Express Edition.
Make sure that you are running setenv /xp /x86. For example, setenv /xp /x64 or setenv /vista /x64 causes the above error message even if you are using Visual Studio 2008 Express SP1 and Platform SDK 6.1 (60001.18000.367) on a Vista 64bit system.

Wednesday, 4 September 2013

How to Install IIS 7 and Setup a Static Website

Why install IIS? The most obvious answer is because you need a web server that is easy to configure and work with. IIS 7 in Windows Server 2008 is a completely different animal than it has been in the past.
It seems Microsoft may have finally created a version of IIS that will compete against Apache for functionality and performance. IIS 7 is a giant step forward for the IIS platform with the following enhancements:
  • Modular Design – In the past it was an all or nothing install for IIS, but not so anymore. With the ability to only load the modules that you need for server operation you increase both performance and security
  • New Management Interface – IIS 7 has a completely new interface that allows you to quickly and easily change the settings you need to for each site. Also in this version is the ability to edit all the website settings in a text based configuration file
  • Share tasks with site owners – If you are hosting multiple sites you can delegate administrative control to developers or content owners
In this article we will explore installing and enabling the basic features of IIS 7 and placing a static website into service. For this article, I will assume that you have installed Server 2008 and know how to launch Server Manager.

Installing IIS 7 on Windows Server 2008

Since the IIS web server is not installed by default, the first thing we have to do is install IIS as a role for the server we are working on.
1. Click on Start -> Administrative Tools -> Server Manager
How to Install IIS 7 - 1
2. In Server Manager scroll down to Roles Summary, and click on Add Roles
How to Install IIS 7 - 2
3. The Add Roles Wizard starts at this point and warns you that if you are going to add a role to make sure:
  • The administrator account has a strong password
  • Network settings, such as static IP, are configured
  • The latest security updates from Windows Updates are installed
How to Install IIS 7 - 3
4. Click Next to go the Add Server Role page. Place a checkmark next to Web Server (IIS) and then click on the button Next
How to Install IIS 7 -
5. The next page will give you some basic information on IIS Web Servers and a few links with extra information if needed. Click on the button Next to continue
How to Install IIS 7 -
6. The next window is the Select Role Services. This very important screen will allow you to add only the modules necessary for your planned installation of IIS.
When you choose a module in this screen in the upper right corner you will get more information about what the module is for. For our example we are going to load the following modules:
  • Static Content – Lets the Web server publish static Web file formats, such as HTML pages and image files.
    Use Static Content to publish files on your Web server that users can view using a Web browser.
  • Default Document – Lets you configure a default file for the Web server to return when users do not specify a file in a URL.
    Default Documents make it easier and more convenient for users to reach your Web site.
  • HTTP Errors – Allows you to customize the error messages returned to users’ browsers when the Web server detects a fault condition.
    Use HTTP Errors to provide users with a better user experience when they run up against an error message. Consider providing users with an e-mail address for staff who can help them resolve the error.
  • HTTP Redirection – Provides support to redirect user requests to a specific destination.
    Use HTTP redirection whenever you want customers who are using one URL to actually end up at another URL. This is helpful in many situations, from simply renaming your Web site, to overcoming a domain name that is difficult to spell, or forcing clients to use a secure channel.
  • HTTP Logging – Provides logging of Web site activity for this server.
    When a loggable event, usually an HTTP transaction, occurs, IIS calls the selected logging module, which then writes to one of the logs stored in the files system of the Web server. These logs are in addition to those provided by the operating system.
  • Request Filtering – Screens all incoming requests to the server and filters these requests based on rules set by the administrator.
    Many malicious attacks share common characteristics, like extremely long requests, or requests for an unusual action. By filtering requests, you can attempt to mitigate the impact of these types of attacks.
  • IIS Management Console – Provides infrastructure to manage IIS 7 by using a user interface.
    You can use the IIS management console to manage a local or remote Web server that runs IIS 7. To manage SMTP or FTP, you must install and use the IIS 6 Management Console.
How to Install IIS 7 - 6
7. Click Next to get to the Confirm Installation Selections screen to verify your chosen settings.
How to Install IIS 7 - 7
8. Click Install and installation will start
How to Install IIS 7 - 8
9. After installation you should see the Installation Results page. Click Close to finish the process.
How to Install IIS 7 - 9
10. In the Server Manager window, under Roles Summary, you should now see Web Server (IIS)
How to Install IIS 7 - 10
11. Let’s go ahead and open IIS Manager by going to Start -> Administrative Tools -> Internet Information Services (IIS) Manager
How to Install IIS 7 - 11
12. Once IIS Manager opens, expand out the web server and then expand the Sites folder. Right click on sites and then click on Add Web Site
How to Install IIS 7 - 12
13. In the Add Web Site window we have some basic information to fill out for a static site:
  • Site Name – Name of the site, this will be either domain.com or *.domain.com (Where * would represent a sub domain name such as www or blog for example)
  • Physical Path – The location on the local server that will hold the files for the website. If you did not set this up beforehand you can create a folder through this interface
  • Type – choose either http or https depending on whether your site will use Secure Socket Layer (SSL) certificate or not
  • IP Address – From the dropdown you can specify what IP the website should answer on or use the default switch of All Unassigned
  • Host Name – If you would like this site to respond to other domain names you can put these here
How to Install IIS 7 - 13
You have now installed IIS 7 and configured a static website. Just place your html files in the directory you specified when creating the site and you are good to go.
How to Install IIS 7 - 14

Pages