How to set up a Python HTTP server

Python is a high-level programming language currently used for a variety of purposes. The source code is easy to read, and typically requires fewer lines than source code written in C. Python has a small HTTP server built in to it, which allows you to use a system directory as a web server directory. The Python HTTP server is most beneficial to users who need a basic HTTP server, but don't want to spend time configuring a larger server such as Apache. If you're using the CentOS operating system and already have Python installed, you just need to start the Python HTTP server and verify that it's working.

DIFFICULTY Basic - 1 | Medium - 2 | Advanced - 3
RELATED PRODUCTS Linux-based VPS or dedicated servers

Here is a quick tutorial on how to set up a Python HTTP server.

Install Python

You'll normally install Python as part of your CentOS installation. Verify that Python is running by entering "python" from the command line. This command should produce output similar to the following:

If Python isn't already installed, you can install it with a yum command similar to the following:

$ yum -y install python27 python27-devel

Start Python

Assume for this example that you want /etc to be your HTTP server directory. Go to that directory and start the Python HTTP server with the following commands:

$ cd /etc
$ python -m SimpleHTTPServer

You should see the following message indicating that the HTTP server is serving port 8000 by default:

Serving HTTP on port 8000 ...

Display the server page

Assume that your IP address is Enter the following URL to display the server page:

If the directory in which the server is running doesn't have a file named index.html, the server page shows the contents of the directory. If the directory has a file named index.html, this file will determine the contents of the server page.

Was dit artikel nuttig?
Hartelijk dank voor je feedback. Gebruik het supporttelefoonnummer of de bovenstaande chatoptie als je een vertegenwoordiger van de afdeling Klantenondersteuning wilt spreken.
Fijn dat we konden helpen! Kunnen we nog iets voor je doen?
Dat spijt ons. Vertel ons wat je verwarrend vond of waarom je probleem niet is opgelost via de geboden oplossing.