Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xWebAdministration: Moved PHP example from README.md into its own example file #539

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
- Updated hashtables in the repo to adhere to the style guidelines
described at https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#correct-format-for-hashtables-or-objects
([issue #524](https://github.com/PowerShell/xWebAdministration/issues/524))
- Moved example Sample_EndToEndxWebAdministration from readme.md to a
- Moved example Sample\_EndToEndxWebAdministration from README.md to a
separate .ps1 in `/examples/` ([issue #491](https://github.com/PowerShell/xWebAdministration/issues/491))
- Moved example Sample\_EndToEnd\_RegisterPhp.ps1 from README.md to its own .ps1 file under `/examples` ([issue #485](https://github.com/PowerShell/xWebAdministration/issues/485))
- Changes to xIisHandler
- Updated schema.mof to include descriptions for each property ([issue #453](https://github.com/PowerShell/xWebAdministration/issues/453)).
- Moved MSFT_xIisHandler localization strings to strings.psd1 ([issue #463](https://github.com/PowerShell/xWebAdministration/issues/463)).
Expand Down
150 changes: 150 additions & 0 deletions Examples/Resources/Sample_EndToEnd_RegisterPhp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<#
.SYNOPSIS
Download and set up PHP and necessary prerequisites on IIS.
.DESCRIPTION
An end-to-end example demonstrating how to install and configure PHP on IIS.
.NOTES
When configuring an IIS Application that uses PHP, you first need to register the PHP CGI
module with IIS. The following xPhp configuration downloads and installs the prerequisites
for PHP, downloads PHP, registers the PHP CGI module with IIS and sets the system
environment variable that PHP needs to run.
--
Note: This example is intended to be used as a composite resource, so it does not use
Configuration Data. Please see the Composite Configuration Blog on how to use this
configuration in another configuration:
http://blogs.msdn.com/b/powershell/archive/2014/02/25/reusing-existing-configuration-scripts-in-powershell-desired-state-configuration.aspx
.EXAMPLE
xPhp -PackageFolder "C:\packages" `
-DownloadUri "http://windows.php.net/downloads/releases/php-5.5.13-Win32-VC11-x64.zip" `
-Vc2012RedistDownloadUri "http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe" `
-DestinationPath "C:\php" `
-ConfigurationPath "C:\MyPhp.ini" `
-installMySqlExt $false
#>

# Composite configuration to install the IIS pre-requisites for PHP
Configuration IisPreReqs_php
{
param
(
[Parameter(Mandatory = $true)]
[Validateset("Present","Absent")]
[String]
$Ensure
)
foreach ($Feature in @("Web-Server","Web-Mgmt-Tools","web-Default-Doc", `
"Web-Dir-Browsing","Web-Http-Errors","Web-Static-Content",`
"Web-Http-Logging","web-Stat-Compression","web-Filtering",`
"web-CGI","web-ISAPI-Ext","web-ISAPI-Filter"))
{
WindowsFeature "$Feature$Number"
{
Ensure = $Ensure
Name = $Feature
}
}
}

# Composite configuration to install PHP on IIS
configuration xPhp
{
param
(
[Parameter(Mandatory = $true)]
[switch] $installMySqlExt,
[Parameter(Mandatory = $true)]
[string] $PackageFolder,
[Parameter(Mandatory = $true)]
[string] $DownloadUri,
[Parameter(Mandatory = $true)]
[string] $Vc2012RedistDownloadUri,
[Parameter(Mandatory = $true)]
[String] $DestinationPath,
[Parameter(Mandatory = $true)]
[string] $ConfigurationPath
)

Import-DscResource -Module xWebAdministration

# Make sure the IIS Prerequisites for PHP are present
IisPreReqs_php Iis
{
Ensure = "Present"
# Removed because this dependency does not work in
# Windows Server 2012 R2 and below
# This should work in WMF v5 and above
# DependsOn = "[File]PackagesFolder"
}

# Download and install Visual C Redist2012 from chocolatey.org
Package vcRedist
{
Path = $Vc2012RedistDownloadUri
ProductId = "{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}"
Name = "Microsoft Visual C++ 2012 x64 Minimum Runtime - 11.0.61030"
Arguments = "/install /passive /norestart"
}

$phpZip = Join-Path $PackageFolder "php.zip"

# Make sure the PHP archive is in the package folder
xRemoteFile phpArchive
{
uri = $DownloadURI
DestinationPath = $phpZip
}

# Make sure the content of the PHP archine are in the PHP path
Archive php
{
Path = $phpZip
Destination = $DestinationPath
}

if ($installMySqlExt )
{
# Make sure the MySql extention for PHP is in the main PHP path
File phpMySqlExt
{
SourcePath = "$($DestinationPath)\ext\php_mysql.dll"
DestinationPath = "$($DestinationPath)\php_mysql.dll"
Ensure = "Present"
DependsOn = @("[Archive]PHP")
MatchSource = $true
}
}

# Make sure the php.ini is in the Php folder
File PhpIni
{
SourcePath = $ConfigurationPath
DestinationPath = "$($DestinationPath)\php.ini"
DependsOn = @("[Archive]PHP")
MatchSource = $true
}

# Make sure the php cgi module is registered with IIS
xIisModule phpHandler
{
Name = "phpFastCgi"
Path = "$($DestinationPath)\php-cgi.exe"
RequestPath = "*.php"
Verb = "*"
Ensure = "Present"
DependsOn = @("[Package]vcRedist","[File]PhpIni")
# Removed because this dependency does not work in
# Windows Server 2012 R2 and below
# This should work in WMF v5 and above
# "[IisPreReqs_php]Iis"
}

# Make sure the php binary folder is in the path
Environment PathPhp
{
Name = "Path"
Value = ";$($DestinationPath)"
Ensure = "Present"
Path = $true
DependsOn = "[Archive]PHP"
}
}
141 changes: 0 additions & 141 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,147 +444,6 @@ This resource manages the IIS configuration section locking (overrideMode) to co

## Examples

### Registering PHP

When configuring an IIS Application that uses PHP, you first need to register the PHP CGI module with IIS.
The following **xPhp** configuration downloads and installs the prerequisites for PHP, downloads PHP, registers the PHP CGI module with IIS and sets the system environment variable that PHP needs to run.

Note: This example is intended to be used as a composite resource, so it does not use Configuration Data.
Please see the [Composite Configuration Blog](http://blogs.msdn.com/b/powershell/archive/2014/02/25/reusing-existing-configuration-scripts-in-powershell-desired-state-configuration.aspx) on how to use this configuration in another configuration.

```powershell
# Composite configuration to install the IIS pre-requisites for PHP
Configuration IisPreReqs_php
{
param
(
[Parameter(Mandatory = $true)]
[Validateset("Present","Absent")]
[String]
$Ensure
)
foreach ($Feature in @("Web-Server","Web-Mgmt-Tools","web-Default-Doc", `
"Web-Dir-Browsing","Web-Http-Errors","Web-Static-Content",`
"Web-Http-Logging","web-Stat-Compression","web-Filtering",`
"web-CGI","web-ISAPI-Ext","web-ISAPI-Filter"))
{
WindowsFeature "$Feature$Number"
{
Ensure = $Ensure
Name = $Feature
}
}
}

# Composite configuration to install PHP on IIS
configuration xPhp
{
param
(
[Parameter(Mandatory = $true)]
[switch] $installMySqlExt,
[Parameter(Mandatory = $true)]
[string] $PackageFolder,
[Parameter(Mandatory = $true)]
[string] $DownloadUri,
[Parameter(Mandatory = $true)]
[string] $Vc2012RedistDownloadUri,
[Parameter(Mandatory = $true)]
[String] $DestinationPath,
[Parameter(Mandatory = $true)]
[string] $ConfigurationPath
)
# Make sure the IIS Prerequisites for PHP are present
IisPreReqs_php Iis
{
Ensure = "Present"
# Removed because this dependency does not work in
# Windows Server 2012 R2 and below
# This should work in WMF v5 and above
# DependsOn = "[File]PackagesFolder"
}

# Download and install Visual C Redist2012 from chocolatey.org
Package vcRedist
{
Path = $Vc2012RedistDownloadUri
ProductId = "{CF2BEA3C-26EA-32F8-AA9B-331F7E34BA97}"
Name = "Microsoft Visual C++ 2012 x64 Minimum Runtime - 11.0.61030"
Arguments = "/install /passive /norestart"
}

$phpZip = Join-Path $PackageFolder "php.zip"

# Make sure the PHP archine is in the package folder
xRemoteFile phpArchive
{
uri = $DownloadURI
DestinationPath = $phpZip
}

# Make sure the content of the PHP archine are in the PHP path
Archive php
{
Path = $phpZip
Destination = $DestinationPath
}

if ($installMySqlExt )
{
# Make sure the MySql extention for PHP is in the main PHP path
File phpMySqlExt
{
SourcePath = "$($DestinationPath)\ext\php_mysql.dll"
DestinationPath = "$($DestinationPath)\php_mysql.dll"
Ensure = "Present"
DependsOn = @("[Archive]PHP")
MatchSource = $true
}
}

# Make sure the php.ini is in the Php folder
File PhpIni
{
SourcePath = $ConfigurationPath
DestinationPath = "$($DestinationPath)\php.ini"
DependsOn = @("[Archive]PHP")
MatchSource = $true
}

# Make sure the php cgi module is registered with IIS
xIisModule phpHandler
{
Name = "phpFastCgi"
Path = "$($DestinationPath)\php-cgi.exe"
RequestPath = "*.php"
Verb = "*"
Ensure = "Present"
DependsOn = @("[Package]vcRedist","[File]PhpIni")
# Removed because this dependency does not work in
# Windows Server 2012 R2 and below
# This should work in WMF v5 and above
# "[IisPreReqs_php]Iis"
}

# Make sure the php binary folder is in the path
Environment PathPhp
{
Name = "Path"
Value = ";$($DestinationPath)"
Ensure = "Present"
Path = $true
DependsOn = "[Archive]PHP"
}
}

xPhp -PackageFolder "C:\packages" `
-DownloadUri -DownloadUri "http://windows.php.net/downloads/releases/php-5.5.13-Win32-VC11-x64.zip" `
-Vc2012RedistDownloadUri "http://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe" `
-DestinationPath "C:\php" `
-ConfigurationPath "C:\MyPhp.ini" `
-installMySqlExt $false
```

### Create and configure an application pool

This example shows how to use the **xWebAppPool** DSC resource to create and configure an application pool.
Expand Down