Can I run two web servers on the same computer?

A web server is tied to a specific port. Normally, this is port 80. If the port is not explicitly specified, this is the port that a browser will attempt to hit.

You can get your alternate server to run on a different port ( 8080 or 8081 seem to be popular alts for web servers, but the choice is yours ).

This'll stop the conflict from happening. Everything going to port 80 hits your old server. Everything going to 8080 ( or whatever port you decide to run your server on ) will hit your simple python server.

To hit your other server, use a URL like :-

http://localhost:8080/


Make them listen to different ports and you will be fine.

The default web port is 80. When you open some url in browser without specifying a port, 80 is used by default.

You can configure your web server to listen to a different port but then you will also need to specify it explicitly in the url:

http://localhost:8080

When choosing a port pay attention that this particular port number is not yet in use by any software you have installed and running on your box. Otherwise, as you correctly guessed, there will be a conflict.

P.S. Just a few days ago doing reinstallation I got IIS not able to start (seemingly without reason). Turned out the new version of Skype occupied this default port! Had to remove its setting "Use port 80 and 443 as alternatives for incoming connections".


If you actually want to run separate servers to test out server software see the other answers, but...

It sounds like (because you are a developer, not a sysadmin right?) you really just want to run Python and PHP sites on the same computer. So, forgive me if I'm reading into your question, but this setup allows me to run both kinds of sites on the same computer with the same port (port 80) in one server, Apache.

I make new entries in my /etc/hosts file (or C:\Windows\System32\drivers\etc\hosts on Windows) and point them to 127.0.0.1:

127.0.0.1      localhost

# development projects
127.0.0.1      somephpsite.com.local
127.0.0.1      www.somephpsite.com.local
127.0.0.1      otherpythonsite.com.local
127.0.0.1      www.otherpythonsite.com.local

Then in Apache I add VirtualHosts for each site:

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    <Directory "/Users/Robert/Projects/SomeSite/somephpsite.com">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    DocumentRoot "/Users/Robert/Projects/SomeSite/somephpsite.com"
    ServerName somephpsite.com.local
    ServerAlias www.somephpsite.com.local
    ErrorLog "/Users/Robert/Projects/SomeSite/error.log"
    CustomLog "/Users/Robert/Projects/SomeSite/access.log" common
</VirtualHost>

<VirtualHost *:80>
    <Directory "/Users/Robert/Projects/OtherSite/otherpythonsite.com">
        Order allow,deny
        Allow from all
    </Directory>
    DocumentRoot "/Users/Robert/Projects/OtherSite/otherpythonsite.com/static"
    Alias /(.*(\.css|\.gif|\.ico|\.jpg|\.js|\.pdf|\.txt)) /Users/Robert/Projects/OtherSite/otherpythonsite.com/static/$1
    WSGIScriptAlias / /Users/Robert/Projects/OtherSite/otherpythonsite.com/wsgi.py
    ServerName otherpythonsite.com.local
    ServerAlias www.otherpythonsite.com.local
    ErrorLog "/Users/Robert/Projects/OtherSite/error.log"
    CustomLog "/Users/Robert/Projects/OtherSite/access.log" common
</VirtualHost>

So, the PHP sites run in the DocumentRoot like they always do. And the Python sites run in WSGI. And they both run in Apache. Then to test, I just add ".local" in whatever browser I'm using to work on my local copy.