Restarting apache web server from PowerShell script (log)

1.5k views Asked by At

I have a powershell script that restarts the Apache Web server on my machine. The script works fine, but the log reports an error. The error seems to be coming from Powershell, not Apache, since if I just do a

.\httpd.exe -k config 

I get no errors, and the first like

.\http.exe -k restart 

does not give an errors either. (note: Powershell complains on line #11, not #10 the first invoke of httpd.exe). I am using powershell V4, on Windows 7.

So I want to understand what Powershell is doing here, since I think that Apache is working fine.

Here is the script:

# This PowerShell script restarts apache
start-transcript -Path install.log -Append
Write-Host "apache.ps1 Script`r`n"

$sixtyfour = [Environment]::Is64BitProcess
$exe = "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin\httpd.exe"

Write-Host "64-Bit Powershell: "$sixtyfour
& $exe -k restart  *>> install.log
Write-Host ""
& $exe -k config  *>> install.log

Here is the log:

httpd.exe : Reconfiguring the Apache2.2 service
At G:\wwwroot\setup\apache.ps1:11 char:1
+ & $exe -k config  *>> install.log
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Reconfiguring the Apache2.2 service:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

The Apache2.2 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
1

There are 1 answers

0
Dr.YSG On BEST ANSWER