Browse Source

PHP for Windows

Pēteris Ņikiforovs 12 years ago
parent
commit
305786a28f
6 changed files with 125 additions and 11 deletions
  1. 67 11
      installer.ps1
  2. 8 0
      php-codeigniter/setup.py
  3. 17 0
      php-codeigniter/web.config
  4. 8 0
      php-kohana/setup.py
  5. 17 0
      php-kohana/web.config
  6. 8 0
      php/setup.py

+ 67 - 11
installer.ps1

@@ -1,5 +1,5 @@
 $basedir = "C:\FrameworkBenchmarks"
-$workdir = $basedir + "\installs"
+$workdir = "$basedir\installs"
 New-Item -Path $workdir -Type directory -Force | Out-Null
 
 #
@@ -19,6 +19,16 @@ Install-WindowsFeature Web-Mgmt-Console
 Install-WindowsFeature NET-Framework-45-ASPNET
 Install-WindowsFeature Web-Asp-Net45
 
+# Enable detailed error pages
+$env:Path += ";C:\Windows\system32\inetsrv"; [Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
+appcmd set config -section:system.webServer/httpErrors -errorMode:Detailed | Out-Null
+
+# URL Rewrite
+$rewrite_url = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi"
+$rewrite_local = "$workdir\rewrite_2.0_rtw_x64.msi"
+(New-Object System.Net.WebClient).DownloadFile($rewrite_url, $rewrite_local)
+Start-Process "msiexec" "/i $rewrite_local /passive" -Wait
+
 #
 # Tools for building .NET projects on the server
 #
@@ -41,26 +51,72 @@ Start-Process "msiexec" "/i $webdeploy_local /passive" -Wait
 # node.js
 #
 Write-Host "Installing node.js...`n"
-$nodeinstaller_file = "node-v0.10.5-x64.msi"
-$nodeinstaller_url = "http://nodejs.org/dist/v0.10.5/x64/" + $nodeinstaller_file
-$nodeinstaller_local = $workdir + "\" + $nodeinstaller_file
-(New-Object System.Net.WebClient).DownloadFile($nodeinstaller_url, $nodeinstaller_local)
+$node_installer_file = "node-v0.10.5-x64.msi"
+$node_installer_url = "http://nodejs.org/dist/v0.10.5/x64/$node_installer_file"
+$node_installer_local = "$workdir\$node_installer_file"
+(New-Object System.Net.WebClient).DownloadFile($node_installer_url, $node_installer_local)
 
-Start-Process $nodeinstaller_local '/passive' -Wait
+Start-Process $node_installer_local '/passive' -Wait
 $env:Path += ";C:\Program Files\nodejs"; [Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
 
 #
 # Python
 #
 Write-Host "Installing Python...`n"
-$pythoninstaller_file = "python-2.7.4.amd64.msi"
-$pythoninstaller_url = "http://www.python.org/ftp/python/2.7.4/" + $pythoninstaller_file
-$pythoninstaller_local = $workdir + "\" + $pythoninstaller_file
-(New-Object System.Net.WebClient).DownloadFile($pythoninstaller_url, $pythoninstaller_local)
+$python_installer_file = "python-2.7.4.amd64.msi"
+$python_installer_url = "http://www.python.org/ftp/python/2.7.4/$python_installer_file"
+$python_installer_local = "$workdir\$python_installer_file"
+(New-Object System.Net.WebClient).DownloadFile($python_installer_url, $python_installer_local)
 
-Start-Process $pythoninstaller_local '/passive' -Wait
+Start-Process $python_installer_local '/passive' -Wait
 $env:Path += ";C:\Python27"; [Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
 
+#
+# PHP
+#
+Write-Host "Installing PHP...`n"
+
+# Download PHP
+$php_installer_file = "php-5.4.14-nts-Win32-VC9-x86.zip"
+$php_installer_url = "http://windows.php.net/downloads/releases/$php_installer_file"
+$php_installer_local = "$workdir\$php_installer_file"
+(New-Object System.Net.WebClient).DownloadFile($php_installer_url, $php_installer_local)
+
+# Install PHP
+$php = "C:\PHP"
+[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
+[System.IO.Compression.ZipFile]::ExtractToDirectory($php_installer_local, $php) | Out-Null
+$env:Path += ";" + $php; [Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::Machine)
+
+# php.ini
+$phpini = "$php\php.ini"
+Copy-Item "$php\php.ini-production" $phpini
+(Get-Content $phpini) -Replace ";date.timezone =", "date.timezone = UTC" | Set-Content $phpini
+(Get-Content $phpini) -Replace "display_errors = Off", "display_errors = On" | Set-Content $phpini
+(Get-Content $phpini) -Replace "short_open_tag = Off", "short_open_tag = On" | Set-Content $phpini
+(Get-Content $phpini) -Replace '; extension_dir = "./"', "extension_dir = `"$php\ext`"" | Set-Content $phpini
+(Get-Content $phpini) -Replace ";extension=", "extension=" | Set-Content $phpini
+
+# IIS with PHP via FastCGI
+Install-WindowsFeature Web-CGI | Out-Null
+appcmd set config -section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe', arguments='', maxInstances='4', instanceMaxRequests='10000', queueLength='1000', rapidFailsPerMinute='1000', idleTimeout='300', activityTimeout='30', requestTimeout='90',protocol='NamedPipe', flushNamedPipe='False']" /commit:apphost | Out-Null
+appcmd set config -section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe'].environmentVariables.[name='PHPRC', value='C:\PHP\php.ini']" /commit:apphost | Out-Null
+appcmd set config -section:system.webServer/handlers /+"[name='PHP FastCGI', path='*.php', modules='FastCgiModule', verb='*', scriptProcessor='C:\PHP\php-cgi.exe', resourceType='File', requireAccess='Script']" /commit:apphost | Out-Null
+
+# phpinfo() test file
+Set-Content "c:\inetpub\wwwroot\phpinfo.php" "<?php phpinfo(); ?>"
+
+# wincache
+$wincache_url = "http://heanet.dl.sourceforge.net/project/wincache/wincache-1.3.4/wincache-1.3.4-5.4-nts-vc9-x86.exe"
+$wincache_local = "$workdir\wincache-1.3.4-5.4-nts-vc9-x86.exe"
+(New-Object System.Net.WebClient).DownloadFile($wincache_url, $wincache_local)
+Start-Process $wincache_local "/q /T:$php\ext" -Wait
+Move-Item "$php\ext\wincache*" "c:\inetpub\wwwroot"
+Set-ItemProperty "c:\inetpub\wwwroot\wincache.php" -name IsReadOnly -value $false
+(Get-Content "c:\inetpub\wwwroot\wincache.php") -Replace "'USE_AUTHENTICATION', 1", "'USE_AUTHENTICATION', 0" | Set-Content "c:\inetpub\wwwroot\wincache.php"
+Add-Content $phpini "`n`n[PHP]`n"
+Add-Content $phpini "extension=php_wincache.dll"
+
 #
 # Firewall
 #

+ 8 - 0
php-codeigniter/setup.py

@@ -1,6 +1,7 @@
 import subprocess
 import sys
 import setup_util
+import os
 from os.path import expanduser
 
 home = expanduser("~")
@@ -10,6 +11,10 @@ def start(args):
   setup_util.replace_text("php-codeigniter/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
 
   try:
+    if os.name == 'nt':
+      subprocess.check_call('icacls "C:\\FrameworkBenchmarks\\php-codeigniter" /grant "IIS_IUSRS:(OI)(CI)F"', shell=True)
+      subprocess.check_call('appcmd add site /name:PHP /bindings:http/*:8080: /physicalPath:"C:\\FrameworkBenchmarks\\php-codeigniter"', shell=True)
+      return 0
     subprocess.check_call("sudo chown -R www-data:www-data php-codeigniter", shell=True)
     subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-codeigniter/deploy/php-fpm.pid", shell=True)
     subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-codeigniter/deploy/nginx.conf", shell=True)
@@ -18,6 +23,9 @@ def start(args):
     return 1
 def stop():
   try:
+    if os.name == 'nt':
+      subprocess.check_call('appcmd delete site PHP', shell=True)
+      return 0
     subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
     subprocess.call("sudo kill -QUIT $( cat php-codeigniter/deploy/php-fpm.pid )", shell=True)
     subprocess.check_call("sudo chown -R $USER:$USER php-codeigniter", shell=True)

+ 17 - 0
php-codeigniter/web.config

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <system.webServer>
+   <rewrite>
+    <rules>
+     <rule name="Hide index.php" stopProcessing="true">
+      <match url="index.php/.*" ignoreCase="false" />
+      <conditions>
+       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
+       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
+      </conditions>
+      <action type="Rewrite" url="index.php?uri=" appendQueryString="true" />
+     </rule> 
+    </rules>
+   </rewrite>
+ </system.webServer> 
+</configuration>

+ 8 - 0
php-kohana/setup.py

@@ -1,6 +1,7 @@
 import subprocess
 import sys
 import setup_util
+import os
 from os.path import expanduser
 
 home = expanduser("~")
@@ -10,6 +11,10 @@ def start(args):
   setup_util.replace_text("php-kohana/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
 
   try:
+    if os.name == 'nt':
+      subprocess.check_call('icacls "C:\\FrameworkBenchmarks\\php-kohana" /grant "IIS_IUSRS:(OI)(CI)F"', shell=True)
+      subprocess.check_call('appcmd add site /name:PHP /bindings:http/*:8080: /physicalPath:"C:\\FrameworkBenchmarks\\php-kohana"', shell=True)
+      return 0
     subprocess.check_call("sudo chown -R www-data:www-data php-kohana", shell=True)
     subprocess.check_call("sudo php-fpm --fpm-config config/php-fpm.conf -g " + home + "/FrameworkBenchmarks/php-kohana/deploy/php-fpm.pid", shell=True)
     subprocess.check_call("sudo /usr/local/nginx/sbin/nginx -c " + home + "/FrameworkBenchmarks/php-kohana/deploy/nginx.conf", shell=True)
@@ -18,6 +23,9 @@ def start(args):
     return 1
 def stop():
   try:
+    if os.name == 'nt':
+      subprocess.check_call('appcmd delete site PHP', shell=True)
+      return 0
     subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
     subprocess.call("sudo kill -QUIT $( cat php-kohana/deploy/php-fpm.pid )", shell=True)
     subprocess.check_call("sudo chown -R $USER:$USER php-kohana", shell=True)

+ 17 - 0
php-kohana/web.config

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <system.webServer>
+   <rewrite>
+    <rules>
+     <rule name="Hide index.php" stopProcessing="true">
+      <match url="." ignoreCase="false" />
+      <conditions>
+       <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
+       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
+      </conditions>
+      <action type="Rewrite" url="index.php?uri=" appendQueryString="true" />
+     </rule> 
+    </rules>
+   </rewrite>
+ </system.webServer> 
+</configuration>

+ 8 - 0
php/setup.py

@@ -16,6 +16,10 @@ def start(args):
   setup_util.replace_text("php/deploy/nginx.conf", "root .*\/FrameworkBenchmarks", "root " + home + "/FrameworkBenchmarks")
   
   try:
+    if os.name == 'nt':
+      subprocess.check_call('appcmd add site /name:PHP /bindings:http/*:8080: /physicalPath:"C:\\FrameworkBenchmarks\\php"', shell=True)
+      return 0
+    
     #subprocess.check_call("sudo cp php/deploy/php /etc/apache2/sites-available/", shell=True)
     #subprocess.check_call("sudo a2ensite php", shell=True)
     #subprocess.check_call("sudo chown -R www-data:www-data php", shell=True)
@@ -28,6 +32,10 @@ def start(args):
     return 1
 def stop():
   try:
+    if os.name == 'nt':
+      subprocess.check_call('appcmd delete site PHP', shell=True)
+      return 0
+    
     subprocess.call("sudo /usr/local/nginx/sbin/nginx -s stop", shell=True)
     subprocess.call("sudo kill -QUIT $( cat php/deploy/php-fpm.pid )", shell=True)