Running Wordpress with IIS and WinCache on Nano Server
- Introduction
- Setup Nano server
- Step 1: prepare Nano server with IIS role
- Step 2: expand disk size
- Setup PHP on Nano server
- Step 3: install PHP on Nano server
- Step 4: install vcuntime140.dll to %windir%\system32 on Nano Server
- Step 5: install IIS-Cgi and configure applicationhost.config for PHP
- Step 6: verify if php is correctly configured
- Setup Wordpress
- Step 7: install MySQL on Nano server
- Step 8: register MySql database server as a Windows service
- Step 9: create a database for Wordpress
- Step 10: configure PHP for MySQL
- Step 11: install Wordpress package on Nano server
- Step 12: configure Default Web Site
- Run
- Step 13: start http://<ComputerName>/wp-admin/install.php
- Enhance PHP performance with WinCach
- Step 14: Install WinCache
- Step 15: Verify WinCache
Introduction
This article shows how to set-up Wordpress on IIS of Nano server.
Setup Nano server
You will prepare Nano server here.
Step 1: prepare Nano server with IIS role
First you need to install IIS on Nano and then install httpPlatformHandler on your Nano server.
Installing IIS on Nano is already covered in the ariticle below, so I’ll skip those steps here for brevity.
Please notice that the article explains both "Installing IIS" and "Installing the ASP.NET Core Module (ANCM)".
You can skip installing the ASP.NET Core Module (ANCM) because ANCM is not required for running Tomcat on Nano server.
Step 2: expand disk size of Nano server
If you use the default disk size of the Nano server image (default hard disk is 4GB), you have to expand the disk size. Otherwise, you will fail to install MySQL because there is not enough disk space.
You can check the current disk size with running "Get-Disk" command from Remote powershell tab. [nano1]: PS C:\> Get-Disk Number Friendly Name Serial Number HealthStatus OperationalStatus Total Size Partition Style ------ ------------- ------------- ------------ ----------------- ---------- ---------- 0 Virtual HD Healthy Online 10 GB MBR |
If your disk size is 4 GB, shutdown your Nano server virtual machine and open the "Settings" dialog of your Nano server Virtual machine.
Then click the "Edit" button after selecting Hard Drive.
Select the "Expand" button, and set the new size with more than 10 GB. Click the "Finish" button to apply the change, and restart yocd\cdur Nano server virtual machine.
Setup PHP on Nano server
Wordpress requires PHP. Here you will learn how to install PHP on Nano server machine.
Step 3: install PHP on Nano server
In this step, you will set-up PHP on your Nano server.
Go to http://windows.php.net/downloads/qa/ and download the latest 64 bit PHP such as php-7.0.1RC1-nts-Win32-VC14-x64.zip.
The file name php-7.0.1RC1-nts-Win32-VC14-x64.zip shows that its version is PHP 7.0.1 RC1 and it is built with Microsoft Visual C v14. |
Unzip the downloaded zip file and copy the contents to a certain directory such as c:\php of your Nano server machine.
Your c:\php directory structure should be like this: [nano1]: PS C:\php> dir Directory: C:\php Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 12/14/2015 1:55 PM dev d----- 12/14/2015 1:55 PM ext d----- 12/14/2015 1:42 PM extras d----- 12/14/2015 1:55 PM lib d----- 12/14/2015 1:55 PM sasl2 -a---- 12/14/2015 11:47 AM 114688 deplister.exe -a---- 12/14/2015 11:47 AM 1360384 glib-2.dll -a---- 12/14/2015 11:47 AM 18432 gmodule-2.dll -a---- 12/14/2015 11:47 AM 25048064 icudt56.dll -a---- 12/14/2015 11:47 AM 2086912 icuin56.dll -a---- 12/14/2015 11:47 AM 52224 icuio56.dll … |
Step 4: install vcruntime140.dll to %windir%\system32 on Nano Server
PHP depends on the vcruntime140.dll file. If the vcruntime140.dll is not available on your Nano server, PHP cannot be executed. The vcruntime140.dll is available on any 64 bit Windows machine where the latest Visual Studio is installed. So, what you should do is to find the vcruntime140.dll file and copy the file to %windir%\system32 of your Nano server machine and confirm the file is copied correctly.
After you copy the vcruntime140.dll correctly to your Nano server machine, you need to confirm whether running "php.exe -?" shows the correct result on your remote powershell tab as the below screenshot. If the file is not copied correctly to the right place, it will silently fail showing an empty result when you execute "php.exe -?" because it fails to load the vcruntime140.dll file.
[nano1]: PS C:\windows\system32> dir .\vcruntime140.dll Directory: C:\windows\system32 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 6/25/2015 11:15 PM 88752 vcruntime140.dll
[nano1]: PS C:\windows\system32> cd \php
[nano1]: PS C:\php> .\php.exe -? Usage: php [options] [-f] <file> [--] [args...] php [options] -r <code> [--] [args...] php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...] php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...] php [options] -S <addr>:<port> [-t docroot] php [options] -- [args...] php [options] -a
-a Run interactively -c <path>|<file> Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f <file> Parse and execute <file>. -h This help -i PHP information -l Syntax check only (lint) … |
Step 5: install IIS-Cgi and configure applicationhost.config for PHP
In this step, you will install IIS-Cgi feature and update applicationhost.config to add the fastcgi module with the php installation directory path, c:\php.
Here is how to install IIS-Cgi feature. If you did not install the feature before, run the command below in order to install IIS-Cgi feature.
DISM.EXE /enable-feature /online /featureName:IIS-CGI /all
NOTE: If you see any error while running "DISM.EXE /enable-feature /online /featureName:IIS-CGI /all", try to run the same command again after running the following cmdlets on your Nano server, which is an work-around way of a known issue. Import-module iisadministration |
Now, you are ready to configure applicationhost.config for PHP.
On the Nano server machine, open %windir%\system32\inetsrv\config\applicationhost.config and configure highlighted config settings as the following (NOTE: You should adjust the directory path value with the actual value of your Nano machine's environment):
<defaultDocument enabled="true">
<files>
<add value="index.php" />
…
<fastCgi>
<application fullPath="C:\PHP\PHP-CGI.EXE" maxInstances="0" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\PHP" />
</environmentVariables>
</application>
</fastCgi>
...
<add name="FastCgiModule" image="%windir%\System32\inetsrv\iisfcgi.dll" />
</globalModules>
...
<add name="FastCgiModule" lockItem="true" />
</modules>
...
<handlers accessPolicy="Read, Script">
<!-- NOTE: place the following line of PHP-iisfcgi in the first line -->
<add name="PHP-iisfcgi" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\PHP\PHP-CGI.EXE" resourceType="Either" requireAccess="Script" />
...
You can update the above configuration settings with running following powershell commands on remote Powershell tab:
import-module iisadministration Reset-IISServerManager -Confirm:$false Get-IISConfigSection system.webServer/defaultDocument | Get-IISConfigElement -ChildElementName files | Get-IISConfigCollection | New-IISConfigCollectionElement -ConfigAttribute @{"value"="index.php"} Get-IISConfigSection system.webServer/fastCgi | Get-IISConfigCollection | New-IISConfigCollectionElement -ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE";"maxInstances"=0;"instanceMaxRequests"=10000} Get-IISConfigSection system.webServer/fastCgi | Get-IISConfigCollection | Get-IISConfigCollectionElement -ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE"} | Get-IISConfigElement -ChildElementName environmentVariables | Get-IISConfigCollection | New-IISConfigCollectionElement -ConfigAttribute @{"name"="PHP_FCGI_MAX_REQUESTS";"value"="10000"} Get-IISConfigSection system.webServer/fastCgi | Get-IISConfigCollection | Get-IISConfigCollectionElement -ConfigAttribute @{"fullPath"="C:\PHP\PHP-CGI.EXE"} | Get-IISConfigElement -ChildElementName environmentVariables | Get-IISConfigCollection | New-IISConfigCollectionElement -ConfigAttribute @{"name"="PHPRC";"value"="C:\PHP"} Get-IISConfigSection system.webServer/handlers | Get-IISConfigCollection | New-IISConfigCollectionElement -ConfigAttribute @{"name"="PHP-iisfcgi";"path"="*.php";"verb"="GET,HEAD,POST";"modules"="FastCgiModule";"scriptProcessor"="C:\PHP\PHP-CGI.EXE";"resourceType"="Either";"requireAccess"="Script"} -AddAt 0 |
Step 6: verify if php is correctly configured
Before going further, let's check whether php is correctly installed and configured.
Create phpinfo.php on the root directory of the Default Web Site such as c:\inetpub\wwwroot with the following file content:
<?php
phpinfo();
?>
Open a web browser and send a request to http://<ComputerName>/phpinfo.php (NOTE: replace <ComputerName> with your Nano server's machine name) and verify that it shows the correct result of the phpinfo.php.
Setup Wordpress
Wordpress needs a database, and here, I will demonstrate how to install MySql on the Nano server and how to initialize it. Then, I will show how to install Wordpress.
Step 7: install MySQL on Nano server
In this step, you will setup MySQL on your Nano server.
Go to https://www.mysql.com/ and download the latest 64 bit MySQL such as mysql-5.6.26-winx64.zip.
Unzip the downloaded zip file and copy the contents to a directory such as c:\MySQL of your Nano server machine.
Your c:\mysql directory structure should be like this:
[nano1]: PS C:\MySql> dir
Directory: C:\MySql
Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 12/14/2015 5:33 PM bin d----- 12/14/2015 5:34 PM data d----- 12/14/2015 5:34 PM docs d----- 12/14/2015 5:34 PM include d----- 12/14/2015 5:35 PM lib d----- 12/14/2015 5:45 PM mysql-test d----- 9/22/2015 3:22 PM scripts … |
Step 8: register MySql database server as a Windows service
In this step you will setup MySQL on your Nano server.
Run "mysqld.exe --install" from c:\MySql\bin directory of your Nano server and restart the machine.
Here is the screenshot of running the "mysqld.exe --install" command to register MySql as a Windows service and to restart the machine:
[nano1]: PS C:\> cd .\MySql\bin [nano1]: PS C:\MySql\bin> .\mysqld.exe --install Service successfully installed.
[nano1]: PS C:\MySql\bin> Restart-Computer;Exit |
After machine has restarted, run "get-process" and you will see the mysqld process running.
Here is the screenshot which shows the mysqld process running:
[nano1]: PS C:\> get-process
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id SI ProcessName ------- ------ ----- ----- ----- ------ -- -- ----------- 6 640 1632 ...63 0.02 288 0 csrss 5 832 3600 ...69 0.00 1080 0 EMT 0 0 4 0 0 0 Idle 16 2360 8676 ...87 0.13 344 0 lsass 15 585040 449588 626 0.33 228 0 mysqld … |
Step 9: create a database for Wordpress
Run the following command from C:\MySql\bin directory in order to create a new database which will be used by Wordpress:
.\mysql.exe -u root -e "create database nanoserver1_wordpress"
This screenshot shows how to create a new database and list up existing databases. I assume you used an empty password for the "root" database user. Otherwise, you will have to specify the password as well.
[nano1]: PS C:\> cd .\MySql\bin [nano1]: PS C:\MySql\bin> .\mysql.exe -u root -e "create database nanoserver1_wordpress" [nano1]: PS C:\MySql\bin> .\mysql.exe -u root -e "show databases;" Database information_schema mysql nanoserver1_wordpress performance_schema test |
Step 10: configure PHP for MySQL
Create a new php.ini file under c:\php directory with the following file content:
[PHP]
extension_dir=c:\php\ext
extension=php_mysqli.dll
This screenshot shows how I created the file with psedit and how I checked the file path. [nano1]: PS C:\> cd .\php [nano1]: PS C:\php> new-item php.ini
Directory: C:\php
Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/14/2015 6:05 PM 0 php.ini
[nano1]: PS C:\php> psedit php.ini ### Here you have to save the php.ini file with the above file content [nano1]: PS C:\php> type .\php.ini [PHP] extension_dir=c:\php\ext extension=php_mysqli.dll
[nano1]: PS C:\php> dir C:\php\ext\php_mysqli.dll Directory: C:\php\ext Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/14/2015 11:47 AM 131072 php_mysqli.dll |
Step 11: install Wordpress package on Nano server
In this step, you will install Wordpress on your Nano server.
Go to https://wordpress.org/ and download the latest package file such as wordpress-4.3.1.zip.
Unzip the downloaded zip file and copy the contents to a directory such as c:\wordpress of your Nano server machine.
Your c:\wordpress directory structure should be like this: [nano1]: PS C:\wordpress> dir Directory: C:\wordpress Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 12/14/2015 6:11 PM wp-admin d----- 12/14/2015 6:11 PM wp-content d----- 12/14/2015 6:12 PM wp-includes -a---- 9/3/2015 3:33 AM 418 index.php -a---- 9/3/2015 3:33 AM 19930 license.txt -a---- 9/15/2015 2:26 PM 7360 readme.html -a---- 9/3/2015 3:33 AM 4951 wp-activate.php … |
Now create wp-config.php file on c:\wordpress directory with the following file content:
<?php
define('DB_NAME', 'nanoserver1_wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
$table_prefix = 'wp_';
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
require_once(ABSPATH . 'wp-settings.php');
The screenshot below shows how I created the file with the psedit tool. It also shows the content of the file with the "type .\wp-config.php" command.
[nano1]: PS C:\> cd .\wordpress [nano1]: PS C:\wordpress> new-item wp-config.php Directory: C:\wordpress Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/14/2015 6:19 PM 0 wp-config.php
[nano1]: PS C:\wordpress> psedit .\wp-config.php ### Here you have to save the wp-config.php file with the above file content [nano1]: PS C:\wordpress> type .\wp-config.php <?php define('DB_NAME', 'nanoserver1_wordpress'); define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_HOST', 'localhost'); define('DB_CHARSET', 'utf8'); define('DB_COLLATE', ''); define('AUTH_KEY', 'put your unique phrase here'); define('SECURE_AUTH_KEY', 'put your unique phrase here'); define('LOGGED_IN_KEY', 'put your unique phrase here'); define('NONCE_KEY', 'put your unique phrase here'); define('AUTH_SALT', 'put your unique phrase here'); define('SECURE_AUTH_SALT', 'put your unique phrase here'); define('LOGGED_IN_SALT', 'put your unique phrase here'); define('NONCE_SALT', 'put your unique phrase here'); $table_prefix = 'wp_'; define('WP_DEBUG', false); if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); require_once(ABSPATH . 'wp-settings.php');
[jhkim-nano1]: PS C:\wordpress> |
Step 12: configure Default Web Site
Open the applicationhost.config file which is placed in c:\windows\system32\inersrv\config and edit the physicalPath of the Default Web Site with "c:\wordpress".
Run
Now you are ready to start. In this section you will learn how to initialize Wordpress and use it.
Step 13: start http://<ComputerName>/wp-admin/install.php
Restart IIS services first. You can use the commands "Stop-Service was -Force -Confirm:$false" and "Start-Service w3svc".
Now you are ready to start.
On any client machine from which you can connect to your Nano server machine, open a web browser such as IE and browse http://<ComputerName>/wp-admin/install.php (NOTE: replace <ComputerName> with the computer name of your Nano server) and you will see a page which shows the list of language names.
Select "English (United States)" and click Continue and now you will see the Welcome page. Fill in the form as you want to and click the "Install Wordpress" button.
And you will see the "Success!" page which has the "Log In" button.
Click the "Log In" button.
Type the user name and password that you used in the previous steps and click the "Log In" button.
If everything is okay, you will get to the Word press page.
Enhance PHP performance with WinCache
If you want better performance for the Wordpress web site or any PHP web sites running on IIS, you should use WinCache.
Here I will show how to install WinCache on Nano server and verify how it works.
Step 14: Install WinCache
Go to http://sourceforge.net/projects/wincache/files/development/wincache-2.0.0.2-dev-7.0-nts-vc14-x64.exe/download and download the latest 64 bit WinCache.
The file name will be like wincache-2.0.0.2-dev-7.0-nts-vc14-x64.exe.
Execute the downloaded file in order to unzip files in it.
Assuming you have installed PHP on c:\php directory, copy php_wincache.dll onto c:\php\ext directory of your Nano machine.
Edit c:\php\php.ini and add the line below.
extension=php_wincache.dll
This screenshot shows how I verified that the file has been correctly copied.
[nano1]: PS C:\php> dir .\ext\php_wincache.dll Directory: C:\php\ext Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/30/2015 12:02 PM 143360 php_wincache.dll
[nano1]: PS C:\php> type .\php.ini [PHP] extension_dir=c:\php\ext extension=php_mysqli.dll extension=php_wincache.dll
[jhkim-nano1]: PS C:\php> |
Step 15: Verify WinCache
One easy way to verify PHP and Wincache is to simply run "php.exe --ini" and make sure there is no error.
This screenshot shows the example of running ".\php.exe --ini". [nano1]: PS C:\php> .\php.exe --ini Configuration File (php.ini) Path: C:\Windows Loaded Configuration File: C:\php\php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) |
Another way to verify is to use wincache2.php, which is one of files installed by the WinCache.
Copy wincache2.php onto the root directory of your web site such as c:\wordpress.
Edit wincache2.php and change the value of USE_AUTHENTICAITION with 0 like the following:
FROM:
...
define('USE_AUTHENTICATION', 1);
TO:
...
define('USE_AUTHENTICATION', 0);
If you don't change the value of USE_AUTHENTICATION, you will see some error message regarding authentication. |
Okay, now you are ready to run the php file.
Open a web browser and browse http://<ComputerName>/wincache2.php (NOTE: replace <ComputerName> with your machine name).
You will see the “Windows Cache Extension for PHP – Statistics” page and that Wincache is working correctly on your Nano server machine.