Access via a Web CGI Application

I’m trying to access Fenics through a CGI script written in Python to allow my undergraduate PDE students to easily explore some elementary PDEs via a web application. I’ve got Fenics running and can solve the types of PDEs I’m interested in but, when I run it via a CGI, it fails for some unknown reason. I realize this is a long shot, as I see only one similar question on this forum. That question remains unanswered, presumably due to lack of detail. So here are the gory details:

I installed Fenics on a 2GB DigitalOcean instance running Ubuntu 20.04 using the following commands:

apt-get install software-properties-common
add-apt-repository ppa:fenics-packages/fenics
apt-get update
apt-get install fenics

I then installed Apache and enabled CGI:

apt update
apt install apache2
a2enmod cgi
systemctl restart apache2

I placed the following very simple script into my cgi-bin and ran chmod 755 to get the proper permission:

#!/usr/bin/python3

# Enable CGI Traceback doesn't work :(
import cgitb
cgitb.enable()

print("Content-type:text/html\n\n")

# from numpy import cos # <-- This works fine
from fenics import cos  # <-- Yields internal Server Error
print('cos(1/2) = ')
print(cos(1/2))

I’ve got two versions of this installed on my server. One for Fenics (as above) and one for NumPy (using the commented out import statement). The Numpy version works but the Fenics version yields an Internal Server Error. You can try both on my temporary server:

The Fenics places something like the following in my Apache error log:

[Tue Dec 15 12:41:04.675140 2020] [cgid:error] [pid 24116:tid 140531866793728] [
client 71.81.209.184:54233] End of script output before headers: test_fenics.py
terminate called after throwing an instance of ‘std::logic_error’

I would think that Fenics version is trying to access something that the Apache user (www-data) doesn’t have access to. Strangely, though, I can run the script from the command line as www-data using a command like the following and it works:

sudo -u www-data /usr/lib/cgi-bin/test_fenics.py

It’s also worth mentioning that I’ve tried essentially the same thing with a Conda based install with the exact same results. I’ve not been able to get a CGI working at all via a Docker install.