How to install mod_wsgi for apache2 on Ubuntu 18.04.6 LTS

254 views
Skip to first unread message

Dennis Allard

unread,
Feb 20, 2022, 1:36:38 AM2/20/22
to modwsgi
I followed a couple of HOWTO tutorials and it just does  not work.

My server is running Ubuntu 18.04.6 LTS.

I wish to be able to install mod_wsgi so that I can serve HTTPS requests using Python.

My server has LetsEncrypt and I run various web sites on  it using php in some  cases.

I tried to install and configure mod_wsgi per the following HOWTOs:



Everything seems to install fine (although the second link  about fails to mention the need to run  `a2enmod wsgi` which at one point pregvented  me  from restarting  apache!).  Anyway, I do get to the  point that I see this:

[2022-02-19 20:15:50 root@oceanpark:~/history]# apachectl -M | grep wsgi
 wsgi_module (shared)

And I installed the standard hello world script:

[2022-02-19 20:15:52 root@oceanpark:~/history]# cat /etc/apache2/conf-enabled/wsgi.conf
WSGIScriptAlias /wsgi /home/httpd/html/wsgy.py

[2022-02-19 20:17:20 root@oceanpark:~/history]# cat /home/httpd/html/wsgy.py
def application(environ,start_response)
  status = '200 OK'
  html = '<html>\n' \
         '<body>\n' \
         'Eureka, mod_wsgi works!\n' \
         '</body>\n' \
         '</html>\n'
  response_header = [('Content-type','text/html')]
  start_response(status, response_header)
  return [html]

[2022-02-19 20:17:28 root@oceanpark:~/history]#

I then restart my web server (via `systemctl restart apache2`).

I then browse  to oceanpark.com/wsgi which returns a Web  page saying:

Internal Server Error

There is absolutely nothing useful output  to my apache server error logs.  Nothing in  access.log, nothing in error.log.  Nada.

WTF?

Can anyone suggest what I might be doing wrong and how on earth can I see an "Internal Server Error" in my Web browser yet not  see anything in either the access or error logs of apache?

Most importantly, HOW do I install mod_wsgi so that I can use Python to process GET and POST requests to my apache server?

I see very little activity on this Google Group and for that matter, very limited resources  concerning how to use Python as an  apache  module.  So what on earth to people use to use Python as backend for their  apache web servers?

Cheers,
Dennis Allard





Graham Dumpleton

unread,
Feb 20, 2022, 5:28:56 PM2/20/22
to mod...@googlegroups.com

On 20 Feb 2022, at 3:30 pm, Dennis Allard <all...@oceanpark.com> wrote:

I followed a couple of HOWTO tutorials and it just does  not work.

My server is running Ubuntu 18.04.6 LTS.

I wish to be able to install mod_wsgi so that I can serve HTTPS requests using Python.

My server has LetsEncrypt and I run various web sites on  it using php in some  cases.

I tried to install and configure mod_wsgi per the following HOWTOs:



So you didn't use the mod_wsgi docs site at all to work out how to configure Apache for your WSGI application?


Everything seems to install fine (although the second link  about fails to mention the need to run  `a2enmod wsgi` which at one point pregvented  me  from restarting  apache!).  Anyway, I do get to the  point that I see this:

[2022-02-19 20:15:50 root@oceanpark:~/history]# apachectl -M | grep wsgi
 wsgi_module (shared)

And I installed the standard hello world script:

[2022-02-19 20:15:52 root@oceanpark:~/history]# cat /etc/apache2/conf-enabled/wsgi.conf
WSGIScriptAlias /wsgi /home/httpd/html/wsgy.py

But where was that put in the Apache config file? Is it inside of a VirtualHost? Is the same VirtualHost setup for PHP?

Would need to see the whole virtual host configuration to understand whether this would even work in the context you put it.

[2022-02-19 20:17:20 root@oceanpark:~/history]# cat /home/httpd/html/wsgy.py
def application(environ,start_response)

You are missing a colon at the end of the preceding line if that is what you actually used.

  status = '200 OK'
  html = '<html>\n' \
         '<body>\n' \
         'Eureka, mod_wsgi works!\n' \
         '</body>\n' \
         '</html>\n'
  response_header = [('Content-type','text/html')]
  start_response(status, response_header)
  return [html]

[2022-02-19 20:17:28 root@oceanpark:~/history]#

I then restart my web server (via `systemctl restart apache2`).

I then browse  to oceanpark.com/wsgi which returns a Web  page saying:

Internal Server Error

There is absolutely nothing useful output  to my apache server error logs.  Nothing in  access.log, nothing in error.log.  Nada.

What URL did you use to access the WSGI application?

Did you check main Apache server host error logs as well as any virtual host error logs? What LogLevel is set for Apache logging.

WTF?

Can anyone suggest what I might be doing wrong and how on earth can I see an "Internal Server Error" in my Web browser yet not  see anything in either the access or error logs of apache?

Quite possibly depending on how else your Apache is setup, your request could also be getting handled by an existing PHP application.

Most importantly, HOW do I install mod_wsgi so that I can use Python to process GET and POST requests to my apache server?

You are better off using a Python web framework such as Flask. Don't try and construct things yourself using raw WSGI.



I see very little activity on this Google Group and for that matter, very limited resources  concerning how to use Python as an  apache  module.  So what on earth to people use to use Python as backend for their  apache web servers?

Cheers,
Dennis Allard






--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/cd4a9c3b-da19-49a9-970f-3d94f5525ad3n%40googlegroups.com.

Jian Wu

unread,
Feb 27, 2022, 7:19:07 AM2/27/22
to mod...@googlegroups.com
Dear community,

I am using Django with mod_wsgi and have been very satisfied. I am running this setup from a Linux server with Apache. I am wondering if there is a way for me to monitor if my server gets overburdened. Right now I am running it with a single CPU core server, and I am not sure if I should upgrade it to more cores. At peak hour I get around 50 visitors to my site per 30 minutes, and I am wondering if there are some tools that allow me to follow how busy the server is and if I need to upgrade my server?

Thanks!

Best regards,
Jian

Graham Dumpleton

unread,
Feb 27, 2022, 5:14:40 PM2/27/22
to mod...@googlegroups.com
You can use application performance monitoring tools from companies such as New Relic, DataDog and Elastic. Just be aware that these tools will impose a bit of a performance overhead, so if you are already at the limit of capacity, then adding these tools could cause things to degrade. In the long run this additional overhead would usually be more than made up by improvements you make to your application based on the data these tools can capture.

Alternatively, if you already have systems in place for collecting metrics, such as InfluxDB, Graphite etc, then you could hook into the capabilities of mod_wsgi to emit its own metrics. It doesn't cover everything mod_wsgi can do in this area these days, but you can get some insight on some of the metrics tracking capabilities of mod_wsgi by reading.


The mod_wsgi package actually has better APIs available now than what is described there, but not sure anything has ever been posted about them except maybe minor mentions in release notes. Unless though you have the capability to store metrics already, or are prepared to put the effort into setting up a system to do so, this path would not be for you.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages