Recently I challenged myself to see how far we can go with PowerShell DSC and non Microsoft Products. My goal in this challenge was to install and configure PHP and MySQL on a blank Windows Server 2012 R2 offline server.
Why would someone do this?
Because I wanted gain a better understanding on how far PowerShell DSC configurations are useful in challenging tasks with non Windows or Microsoft Products. Another outcome should be a fully functional PHP server to host PIWIK for a SharePoint Farm.
And why would someone try this on a offline server without any connection to the internet? This a very common scenario I’m facing with customers.
What do we start with?
As I’m writing this blog, PHP version 7.2 is the current one. I used to work with PHP before in several projects and used XAMPP to host my applications for development purposes. XAMPP bundles Apache, PHP and MySQL. To get started with XAMPP on a windows system is a breeze.
Installing all that stuff manually works fine and there are many options available supporting the installations: e.g. the IIS Web Platform Installer – But not in an offline scenario. The same fact is preventing me from using chocolatey in PowerShell DSC. I do not have an offline option.
I started with the following example provided through the xWebAdministration DSC Resource:PowerShellDsc/xWebAdministration – Examples: Registering PHP
Install the necessary Windows Features and disable not needed IIS Pools
I use the following lines of PowerShell to configure Windows Server and IIS with DSC:
After completing the IIS configuration we can start with the installation of PHP and MySQL.
Configuration of PHP and the WinCache Extension
With PHP 7.1 there are several installation options available. I opted for the Non Thread Save version of PHP and downloaded this version on my client and made it available on the server.
Additionally you will need to download:
The installation of PHP is fairly simple. It consists of the following steps:
- Install Microsoft Visual C++ 2017
- Extract the PHP zip file to your “installation” folder
- Copy the WinCache DLL to the ext folder in your PHP “installation” folder
- Rename the php.ini-production to php.ini
- Enable the WinCache extension in the php.ini
- Add the Php Handler
- Configure the Path for PHP
Steps 1 to 4 are regualr DSC Resources:
- Package Resource
- Archive Resource
- File Resource
- File Resource
- See below
- xIisModule Resource – Currently with one Issue
- Environment Resource
For Step 5 we have to write some Code using the script resource:
Configuration of MySQL
The MySQL Part is fairly simple. Download the current MySQL Version:
- MySQL Installer Community (18.104.22.168)
- Visual C++ Redistributable Packages for Visual Studio 2013 – Version 12.0.40660 (Version is important!)
and open this example provided through the xMySql Resource to finish your DSC configuration:
I modified the package resource to match the current MySQL version:
The installation process of PHP and MySQL on a Windows Server 2012 R2 is straight forward. Adding the WinCache Extension was tricky.
Biggest challenge: The examples provided in the github repsitories of xWebAdministration, xMySql were not up to date. The Guids and used versions differ from the current ones.
The next step would be to
- Create a new IIS Web Application
- Configure this IIS Web Application for HTTPS
- Provision and configure PIWIK