Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <#PSScriptInfo
  2. .VERSION 1.1
  3.  
  4. .GUID 9c74d64a-774d-4f5a-a8c4-485fd079e7bd
  5.  
  6. .AUTHOR Oliver Lipkau <oliver@lipkau.net>
  7.  
  8. .COMPANYNAME
  9.  
  10. .COPYRIGHT Lipkau.net
  11.  
  12. .TAGS localhost php start-WebServer host server
  13.  
  14. .LICENSEURI https://opensource.org/licenses/MIT
  15.  
  16. .PROJECTURI
  17.  
  18. .ICONURI
  19.  
  20. .EXTERNALMODULEDEPENDENCIES
  21.  
  22. .REQUIREDSCRIPTS
  23.  
  24. .EXTERNALSCRIPTDEPENDENCIES
  25.  
  26. .RELEASENOTES
  27. #>
  28.  
  29. <#
  30. .SYNOPSIS
  31. Start a local http server
  32.  
  33. .DESCRIPTION
  34. Start a local http server on a specific port.
  35.  
  36. REQUIRES: php to be installed and available in $env:path
  37.  
  38. .NOTES
  39. Author : Oliver Lipkau <oliver@lipkau.net>
  40. Source : https://gist.github.com/lipkau/105f07f8dacd3800dcd62d4dbad5539c
  41.  
  42. .INPUTS
  43. System.String
  44. System.Integer
  45.  
  46. .EXAMPLE
  47. Start-WebServer -Path "C:\www\myProject\public" -Port 8080
  48. -----------
  49. Description
  50. Makes the specified Path availble at http://localhost:8080
  51. #>
  52.  
  53. Param()
  54.  
  55. function Start-WebServer
  56. {
  57. [CmdletBinding()]
  58. param(
  59. # Specifies the path which should be made available in http server.
  60. [ValidateScript({(Test-Path $_ -IsValid)})]
  61. [Parameter(Position = 0, Mandatory = $false)]
  62. [string]$Path = $pwd.Path,
  63.  
  64. # Specifies the port of the http server.
  65. [Parameter(Position = 1, Mandatory = $false)]
  66. [int]$Port = 80
  67. )
  68.  
  69. Begin {
  70. function Test-PHPinPath
  71. {
  72. $env:path -split ";" | ForEach-Object -Begin {$containsPHP = @()} -Process {$containsPHP += Test-Path "$_\php.exe"} -End {$containsPHP -contains $true}
  73. }
  74.  
  75. if (Test-PHPinPath) {
  76. Throw "Could not find php.exe in PATH"
  77. }
  78.  
  79. Start-Process -WorkingDirectory $Path -FilePath php -ArgumentList @("-S localhost:$Port")
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement