We’ll be using a freshly installed server with Ubuntu Server 16.04, Ubuntu Desktop should also work.

By default Ubuntu 16.04 ships with Python 3 but you won’t be able to call it if you issue the following at shell:

You’ll instead be greeted by this error message:

Instead if you issue the following, you’ll get the proper version:

So to get the OS to call python when we just type python at the terminal we need to do the following:

Note: If you have an older version of python installed you will need to first remove the link to it and then create the new one, here’s how:

Moving on, time to install the package manager for python, pip

Now to install Apache, 

Create a directory to hold the python files

Next, to register python with apache we must disable multithreading processes

Now to give apache permission to run the scripts

Next, modify apache’s configuration to set Python files as runnable and allow them to be executed

Add the following block right under the Virtualhost start declaration, usually right after the first line:

Next, change Apache’s default document root to your newly created pythontest directory, look for the word DocumentRoot in the same config and change to:

Restart Apache:

Now it’s time to test things, create a index.py file in the set directory and add the sample Hello World script:

Add the following:

Save, and hit your server’s IP in your browser and you should see the “Hello World!” text.

Note: Python3 requires updated syntax to function properly, you may see HTTP 500 Internal Server errors with the old syntax