lazyload the images

最新精選 Featured post

異世界穿越作品整合

訂閱

訂閱 FB 專頁

每月雙數周日為固定發佈日

訂閱FB 專頁,有新發佈時將會立即看見。
Youtube 頻道經常會有電玩錄影

16/02/2020

how to install apache PHP on IIS

文章分類: , ,

How to install Apache PHP on IIS
安裝PHP在IIS中運行


Summary Tasks

  1. Install Visual C++ 14 (this is required by PHP7.0)
  2. Install PHP7.0 on Windows for IIS web server
  3. Config PHP
  4. Verify PHP on windows
  5. Add web site on IIS
  6. Integrate PHP on IIS
  7. Verify PHP on IIS

Each step will have a validation stage, please validate your step is successful or not.
每一步驟最後也有驗證階段,以確保每步並無出錯
安裝步驟都比較直接,便不花時間續字續句翻譯,簡單英語必需學起來,因為很多教材資訊來源都是英文。
杜芬宅已經整理過資訊,只列精要。

1. Install Visual C++ 14

Make sure you download and install the x86 version (vcredist_x86.exe) even if you use a 64-bits OS because PHP needs some 32-bit libraries.
But in my experiences, install x86 version only was doesn't work until I install both of x86 and x64

For example:
If you're running PHP 7.0.x you need to ensure the VC++14 runtime is installed:

If you're running PHP 5.5.x you need to ensure the VC++11 runtime is installed:
http://www.microsoft.com/en-us/download/details.aspx?id=30679

If you're running PHP 5.4.x then you need to install the VC++9 runtime:
http://www.microsoft.com/en-us/download/details.aspx?id=5582


More recent versions of PHP are built with VC14, VC15 or VS16 (Visual Studio 2015, 2017 or 2019 compiler respectively) and include improvements in performance and stability.
- The VC14, VC15 and VS16 builds require to have the Visual C++ Redistributable for Visual Studio 2015-2019

Visual Studio VC Download page,
CHI
https://support.microsoft.com/zh-hk/help/2977003/the-latest-supported-visual-c-downloads
ENG
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
included:
Visual Studio 2015、2017 和 2019 (VC14, VC15, VC16)
Visual Studio 2013 (VC++ 12.0)
Visual Studio 2012 (VC++ 11.0)
Visual Studio 2010 (VC++ 10.0) SP1
Visual Studio 2008 (VC++ 9.0) SP1

direct download x86 version
https://aka.ms/vs/16/release/VC_redist.x86.exe
direct download x64 version
https://aka.ms/vs/16/release/VC_redist.x64.exe
Download and install vc_redist.x86.exe (Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 x86)

Validate:
Go to control panel > Programs and Features
Find “Microsoft Visual C++ 2015-2019 Redistributable (x86)”

官方網站說明,PHP 在windows 環境上需要 Microsoft Visual C++ Redistributable for Visual Studio,較舊的PHP使用舊的VC++開發,如是近期版本的PHP,安裝VC++ 2015-2019便可以

2. Install PHP7.0

Visit https://windows.php.net/download/

If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP.
With Apache you have to use the Thread Safe (TS) versions of PHP.

PHP's thread-safety is highly disputed. It's a use-if-you-really-really-know-what-you-are-doing ground.

download the PECL modules on http://pecl.php.net/ for windows if needed
PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

By default, the PHP release already included some common extensions, download additional extensions on pecl.php.net if you really know what to do.

Select a PHP version, click [zip] button to download


For previous version, visit https://windows.php.net/downloads/releases/archives/

You should download the recently and stable version, PHP 7.0+ is not the latest version, just a trail in my writing.

Download “php-7.0.33-nts-Win32-VC14-x86.zip”

Extract on somewhere, such as “C:\IIS_PHP\PHP7.0\”

You may find the below files depends on your downloaded version.

  • php.ini-recommended
  • php.ini-development
  • php.ini-production

Rename php.ini-production to “php.ini”

下載最新的PHP 版本,如果PHP在windows上跑,下載 Non-Thread Safe (NTS) 版本
選好版本後按 [zip] 下載,解壓到任何路徑,將php.ini-production 重新命名 “php.ini”。
php.ini是一個重要的調置(config)檔案
(杜芬宅︰雖然很少看中文,譯成調置應該沒有錯吧)

3. Config PHP on IIS

Open php.ini in text editor.
Please refer to the official document provided by Microsoft(URL) to amend the php.ini.

config the php.ini for windows IIS environment

  • uncomment cgi.force_redirect and set it to 0
  • uncomment fastcgi.impersonate and should be set as 1
  • uncomment session.save_path, assign a session folder location, for example: C:\IIS_PHP\PHP7.0\sessions
  • uncomment extension_dir, assign the extension directory, for example: extension_dir=ext
    remove the ";" to uncomment the extensions which will required for your application





I uploaded my php.ini to Gitgist, you may use this for UAT environment.
https://gist.github.com/dolphinotaku/a63655e1a21f1073b42604989f902222

4. Verify PHP on windows:

Open a command prompt, run "cmd.exe"
execute the following command to verify that PHP installed successfully:
C:\IIS_PHP\PHP7.0>php -info


You should see the PHP7.0 information and current settings

5. Add web site on IIS

Please refer to the official document provided by Microsoft
How to set up your first IIS Web site

6. Integrate PHP on IIS

Turn on the IIS CGI feature

the steps of enable CGI are little different between windows server and windows.
if you not sure you are on windows or windows server.
press [win] key + R, run winver, to find your windows version

for windows server 2008, please refer the steps belows

  1. Click "Turn Windows features on or off" will open Server Manager,
  2. go Roles > Web Server (IIS) on left
  3. scroll down on right, find the "Role Services" accordion, you may see the installed Role Services (CGI is not installed fornow)
  4. Click "Add Role Services", check the CGI option and Click "Next"
  5. Before install/add services, please close the IIS
  6. Click "Install" and wait
  7. Clcik "Close" after installation succeeded







for windows, please refer the steps belows

  1. Turn Windows features on or off
  2. Internet Information Services (IIS)
  3. World Wide Web Services (WWWS)
  4. Application Development Features
  5. CGI

after turned on CGI, click [OK]




Update IIS FastCGI Settings

Open IIS Manager, Double-click on the "FastCGI Settings" icon.
In the FastCGI Settings, find the Actions panel on right, click on "Add applications...".
Browse and locate the php-cgi.exe, e.g C:\IIS_PHP\PHP7.0\php-cgi.exe
Click "OK"


Update IIS Handler Mappings

Open IIS Manager, Connections panel on the left of the screen, click on the hostname.
Double-click on the Handler Mappings icon.
In the Handler Mappings, find the Actions panel on right, click on "Add Module Mapping".

Request path: *.php
Module: FastCgiModule
Executable (optional): C:\IIS_PHP\PHP7.0\php-cgi.exe
Name: type anything

Click “OK”



Add PHP default document

Open IIS Manager, Connections panel on the left of the screen, click on the hostname.
Double-click on the Default Document icon.
Add index.php as the default document,

you may refer to the apache setting, default.php and home.php also seems as the default document in the setting.


7. Verify PHP on IIS

create a plain text file and named as info.php
copy and paste the below content in it and save
<?php phpinfo(); ?>
store at the site root, e.g C:\Application\site\info.php
open a browser, go to http://localhost/info.php
it will shows


Reference


PHP for Windows Home
https://windows.php.net/

PHP Archives for Windows
https://windows.php.net/downloads/releases/archives/

Planning Step 2: Plan PHP Settings
https://docs.microsoft.com/en-us/iis/application-frameworks/scenario-build-a-php-website-on-iis/planning-step-2-plan-php-settings

How to set up your first IIS Web site
https://support.microsoft.com/en-gb/help/323972/how-to-set-up-your-first-iis-web-site

What is thread safe or non-thread safe in PHP?
https://stackoverflow.com/questions/1623914/what-is-thread-safe-or-non-thread-safe-in-php

PHP For Windows: Binaries and sources Releases
https://windows.php.net/download/

How to Install PHP 5 for IIS 6
https://www.wikihow.com/Install-PHP-5-for-IIS-6

msvcr110.dll is missing from computer error while installing PHP
https://stackoverflow.com/questions/21397073/msvcr110-dll-is-missing-from-computer-error-while-installing-php

The Program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the program to fix this problem.
https://answers.microsoft.com/en-us/windows/forum/windows_8-winapps/the-program-cant-start-because-msvcr110dll-is/f052d325-3af9-4ae5-990b-b080799724db

Download Microsoft Visual C++ Redistributable (All Versions)
https://www.itechtics.com/microsoft-visual-c-redistributable-versions-direct-download-links/#Microsoft_Visual_C_Redistributable_2010

最新支援的 Visual C++ 下載
https://support.microsoft.com/zh-hk/help/2977003/the-latest-supported-visual-c-downloads

Using FastCGI to Host PHP Applications on IIS 7
https://docs.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis

500 error on fresh install of IIS and PHP
https://serverfault.com/questions/613927/500-error-on-fresh-install-of-iis-and-php/613940#613940

The FastCGI process exited unexpectedly
https://stackoverflow.com/questions/23007551/the-fastcgi-process-exited-unexpectedly

No comments:

Post a Comment