Step2: Install and Configure PHP

Last updated: 2020-05-14 17:50:46

    Scenario

    This document uses a CVM running Windows Server 2012 R2 as an example to describe how to configure PHP 5.3 and earlier versions or versions later than 5.3 in a Windows CVM.

    Prerequisites

    Directions

    Installing PHP 5.3 or earlier

    The PHP official website no longer provides the installation packages for versions earlier than PHP 5.2. If you require a version earlier than PHP 5.2, search for and download it from the CVM. Alternatively, download it locally and then upload the installation package to the CVM. For more information on how to upload files to a Windows CVM, see Uploading Files Through MSTSC to a Windows CVM from Windows. The following procedure uses PHP 5.2.13 as an example.

    1. Open the PHP installation package in the CVM.
    2. Click Next.
    3. On the "Web Server Setup" page, select IIS FastCGI and click Next, as shown in the following figure:
      .
    4. Complete PHP installation as prompted.
    5. Create a PHP file such as hello.php in C:/inetpub/wwwroot.
    6. In the created hello.php file, add the following code and save the file.
       <?php
       echo "<title>Test Page</title>";
       echo "hello world";
       ?>
    7. On the desktop, open the browser and visit http://<Public IP address of the Windows CVM>/hello.php and check whether the environment is successfully configured.
      If the page shown below appears, the configuration was successful.

    Installing a version later than PHP 5.3

    Versions later than PHP 5.3 do not have an installation package and are installed by using a zip file or debug pack. The following demonstrates how to install PHP in a Windows Server 2012 R2 environment by using a zip file.

    Downloading software

    1. In the CVM, go to the PHP official website and download the compressed PHP installation package, as shown in the following figure:

      To run PHP under IIS, you must select the x86 installation package for Non Thread Safe. If your server is running Windows Server 32-bit (x86), replace IIS with Apache and select the x86 installation package for Non Thread Safe.

    2. Based on the name of the downloaded PHP installation package, download and install the Visual C++ Redistributable installation package.
      The following table lists the Visual C++ Redistributable installation packages that need to be downloaded and installed for the PHP installation package.
      PHP Installation Package NameDownload Address of the Visual C++ Redistributable Installation Package
      php-x.x.x-nts-Win32-VC16-x86.zipMicrosoft Visual C++ Redistributable for Visual Studio 2019
      php-x.x.x-nts-Win32-VC15-x86.zipMicrosoft Visual C++ Redistributable for Visual Studio 2017
      php-x.x.x-nts-Win32-VC14-x86.zipMicrosoft Visual C++ Redistributable for Visual Studio 2015
      For example, if the name of the downloaded PHP installation package is PHP-7.1.30-nts-Win32-VC14-x86.zip, download and install the Microsoft Visual C++ Redistributable for Visual Studio 2015 installation package.

    Installation and configuration

    1. Decompress the downloaded PHP installation package, for example, to C:\PHP.
    2. Copy the php.ini-production file in C:\PHP and change the file extension to .ini, that is, rename it to php.ini, as shown in the following figure:
    3. On the desktop, click to open Server Manager, as shown in the following figure:
    4. In the left sidebar, click IIS.
    5. In the right IIS management window, right-click the server name in the Server column and choose Internet Information Services (IIS) Manager, as shown in the following figure:
    6. In the "Internet Information Service (IIS) Manager" window, click the server name in the left sidebar to go to the server homepage, as shown in the following figure:
      For example, click the 10_141_9_72 server name to go to the 10_141_9_72 homepage.
    7. On the 10_141_9_72 homepage, double-click Handler Mappings to go to the "Handler Mappings" page, as shown in the following figure:
    8. In the Actions column on the right, click Add Module Mapping to open the "Add Module Mapping" window.
    9. In the "Add Module Mapping" window, enter the following information and click OK, as shown in the following figure:

      The main parameters include:
      • Request path: enter *.php.
      • Module: select "FastCgiModule".
      • Executable (optional): select the php-cgi.exe file in the PHP installation package, that is, C:\PHP\php-cgi.exe.
      • Name: enter a custom name, such as FastCGI.
    10. In the window that appears, click OK.
    11. Click the 10_141_9_72 server name in the left sidebar to return to the 10_141_9_72 homepage.
    12. On the 10_141_9_72 homepage, double-click Default Document to go to the default document management page, as shown in the following figure:
    13. In the Actions column on the right, click Add to open the "Add Default Document" window.
    14. In the "Add Default Document" window, set Name to index.php and click OK, as shown in the following figure:
    15. Click the 10_141_9_72 server name in the left sidebar to return to the 10_141_9_72 homepage.
    16. On the 10_141_9_72 homepage, double-click FastCGI Settings to open the FastCGI setting management page, as shown in the following figure:
    17. On the FastCGI setting management page, select the FastCGI application and click Edit, as shown in the following figure:
    18. In the "Edit FastCGI Application" window, set Monitor changes to file to the php.ini file path, as shown in the following figure:
    19. In C:\inetpub\wwwroot, create a PHP file, such as index.php.
    20. In the created index.php file, add the following code and save the file.
      <?php
      phpinfo();
      ?>
    21. On the desktop, open the browser and visit http://localhost/index.php to check whether the environment is configured successfully.
      If the page shown below appears, the configuration was successful.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help