Posts Tagged ‘web server’

h1

Skype and Web Servers

08/08/2009

I briefly had a problem with the web server that’s running my personal wiki yesterday.  Try as I might it just wouldn’t start-up.  I hadn’t had a problem before and after three or four attempts at clicking the start option I took a step back and surveyed my machine – a useful option in many circumstances.

I spotted the culprit straight away as I had come across the issue before – Skype.  When Skype starts up if the default port (51907 on my current instance of Skype) is unavailable (because another application is using it or more likely a firewall is blocking it) it tries to set-up on a port that is more likely to be available – 80 or 443 which are used by web servers for insecure and secure traffic respectively.

Whilst there is an advanced option in Skype to force it away from these two alternative ports often there are no other convenient ones to choose from.  This is because it is good practice security to block unused ports and Skype isn’t always a top runner so to speak on ports to have open.

The moral of the story is simple – start your web server before you start Skype.

However this got me to wondering what else might pick a port that could conflict and how would you know what it was without just systematically working through all the applications and services you have running … which for me could be a large number.  My solution was to use some DOS commands.  NETSTAT can be used to examine what ports are in use by what processes.  TASKLIST can be used then to identify the executable.

To smooth things over a little I’ve concocted a little script to automate this process.  It’s really just a bit of a nicer front end to the whole thing and whilst several command prompt windows may briefly flash up as it runs, the script will take in the information from the commands and process them to filter out the pertinent information.

Option Explicit

Dim objCommandPort
Dim astrResults
Dim astrInfoLine
Dim strOutput
Dim strPortCommand
Dim strPID
Dim strApps

strPortCommand = "netstat -ano" 

set objCommandPort = New clsDOSCommandExecutor

objCommandPort.ExecuteCommand(strPortCommand)
strOutput = objCommandPort.GetOutput
astrResults = split(strOutput, vbCrLf)

strApps = "PORT: APPLICATION" & vbCrLf
AssessPort "80"
strApps = strApps & vbCrLf
AssessPort "443"

MsgBox strApps, vbInformation + vbOKOnly, "Applications using web server ports"

Sub AssessPort(p_strPort)
 Dim intCounter

 For intCounter = 1 to Ubound(astrResults)
 If inStr(astrResults(intCounter), ":" & p_strPort) > 0 Then
 astrInfoLine = split(astrResults(intCounter))
 strPID = astrInfoLine(ubound(astrInfoLine))
 strApps = strApps & vbCrLf & p_strPort & ": " & AppOnPort(strPID)
 End If
 Next
End Sub

Function AppOnPort(p_strPID)
 Dim objCommandPID
 Dim strPIDCommand
 Dim strPIDOut
 Dim astrPIDOut

 set objCommandPID = New clsDOSCommandExecutor
 strPIDCommand = "tasklist /fi ""PID eq " & p_strPID & """"

 objCommandPID.ExecuteCommand(strPIDCommand)

 strPIDOut = Right(objCommandPID.GetOutput, len(objCommandPID.GetOutput) - inStrRev(objCommandPID.GetOutput, "=" & vbcrlf))
 astrPIDOut = split(strPIDOut)

 AppOnPort = Replace(astrPIDout(0), vbCrLf, "")
End Function

Class clsDOSCommandExecutor
 Dim objShell, objExec
 Dim strCommand
 Dim strError
 Dim objError
 Dim objOutput
 Dim strOutput

 Sub ExecuteCommand(p_strCommand)
 strCommand = "cmd /c " & p_strCommand
 Set objShell = CreateObject("Wscript.Shell" )

 objShell.Exec(strCommand)

 Set objExec = objShell.Exec(strCommand)

 Do Until objExec.Status
 Wscript.Sleep 200
 Loop

 Set objError = objExec.StdErr
 strError = objError.ReadAll

 Set objOutput = objExec.stdOut
 strOutput = objOutput.ReadAll
 End Sub

 Function GetOutput()
 GetOutput = strOutput
 End Function

 Function GetError()
 GetError = strError
 End Function

 Function Failed()
 If strError = "" Then
 Failed = false
 Else
 Failed = true
 End If
 End Function
End Class
Advertisements
h1

A portable web server where I want it

13/07/2009

I’ve been tinkering recently with some things around portable applications which I will probably post more about in the hopefully not too distant future.  One of the things I’ve been trawling around for and busily configuring are various free web server packages that are “portable”.  Unfortuately it has taken a fair bit of effort to actually track down and configure something that is portable enough.   The problem for me is that I have a particular need to locate the web server within a particular sub folder and in the case of most software packages this is not an option.

Most implementations are based around Apache (e.g. micro apache, XAMPP, TWAMP, WAMP, USB Web Server) but there are a few other options out there I also looked at  such as RITlabs TinyWeb.  Some of these experience problems when they are not installed to the root of a drive and others have a problem when the installation path contains spaces.  My desired installation path unfortunately is not in the root folder and does contain spaces which ruled out most of the options.

I found two options that did seem to cope with the path.  These were WAMP and USB Web Server.  My preference is for USB Web Server and I’ll explain why…

When installed my WAMP system tray application did not match up to the one shown on the web site.  Even though it was running, the status told me that it wasn’t and there was no option to stop/start individual applications such as Apache and MySQL.  Moreover WAMP comes as an installation package which adds an entry into the registry – at least for the add/remove software entry … which seems blatantly false for something that is supposed to be portable.

USB Web Server on the other hand does work as expected and does allow me to stop and start specific web related services and even to move it to a different folder (you have to close it in between).  The one thing I would like is to be able to specify which web services it should run at start-up.  It runs Apache, MySQL and SMTP by default, but I’d really just like to run Apache and free up my RAM without specifically having to manually turn them off.  I tried various renames of folders and changing of settings, but everything I tried either had no effect or stopped Apache running as well.  I’m guessing that there’s some sort of start-up chain at work rather than independent requests.  But maybe someone else knows what to change to address this or perhaps the developer will provide this option in a future release.

So if you want a truly portable web server try USB Web Server.