mod_wsgi permission error on activate file

31 views
Skip to first unread message

Harald Fontius

unread,
Apr 16, 2023, 4:50:42 PM4/16/23
to modwsgi

I am trying to run a PYTHON FLASK application created in MS Visual Studio and exported it to a directory call “conjugationgame”.

In the VISUAL STUDIO environment it runs without problems. Now I want to install it on a LINUX Server hosted by IONOS.

UBUNTU  22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64) is installed. Apache2 is installed and shows this status:

apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-04-12 15:58:48 UTC; 1 day 23h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 15997 (apache2)
      Tasks: 71 (limit: 2193)
     Memory: 30.1M
        CPU: 55.237s
     CGroup: /system.slice/apache2.service
            
15997 /usr/sbin/apache2 -k start
            
75728 /usr/sbin/apache2 -k start
             
75729 /usr/sbin/apache2 -k start
            
75730 /usr/sbin/apache2 -k start
             └─75731 /usr/sbin/apache2 -k start

I tried to install a mod_wsgi virtual environment following @Luke Peter’s very good video tutorial (183) How to Deploy a Flask App to Linux (Apache and WSGI) - YouTube

In installed the application like this:

server_installation.png

I run pipenv install according to this answer to a problem with  mutablemapping python - AttributeError: module 'collections' has no attribute 'MutableMapping' - Stack Overflow

install pipenv.png 

Although I got an error running  pipenv install after changing the directory to var/www/conjugationgame.de/conjugationgame/:

Permission_error_pipenv install.png

Hard to read:

PermissionError: [Errno 13] Permission denied ‘var/www/conjugationgame.de/conjugationgame/._atomic-writelcmrxftk’ (might be the problem but I couldn’t find anything to solve it)

pipenv –venv gives the link to the virtual environment:

error_venv.png

With this link I created the wsgi file like this:

wsgi.png

and the config file like this

config.png

Checked the syntax of the config and restarted apache2.

restart config.png

When calling https://conjugationgame.de I get this error:

[Fri Apr 14 15:18:59.616298 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] mod_wsgi (pid=75730): Failed to exec Python script file '/var/www/conjugationgame.de/__init__.wsgi'., referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616378 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] mod_wsgi (pid=75730): Exception occurred processing WSGI script '/var/www/conjugationgame.de/__init__.wsgi'., referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616487 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] Traceback (most recent call last):, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616514 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927]   File "/var/www/conjugationgame.de/__init__.wsgi", line 4, in <module>, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616520 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927]     with open(activate_this) as file_:, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616569 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] PermissionError: [Errno 13] Permission denied: '/home/hfwds/.local/share/virtualenvs/conjugationgame-4RgIZZXj/bin/activate_this.py', referer: https://conjugationgame.de/

The activate file looks like this:


I tried whatever I could find – without success. Can anybody help?

I also tried user www-data and group www-data in the config file – same problem. I solved the problem before following the answer in this question:

python - Apache/Django/mod_wsgi - [Errno 13] Permission denied: - Stack Overflow

 activatefile.png

but I had to reinstall the application again and now the error is permanent.

 

Graham Dumpleton

unread,
Apr 16, 2023, 5:04:04 PM4/16/23
to mod...@googlegroups.com
Home directories on Linux distributions are often not accessible to other users. So changing permissions of directories/files under the home directory doesn't help since can't see into the actual home directory. You preferably should not stick your project code under a user home directory.

That said, one way around it is to set user/group on WSGIDaemonProcess to owner of the home directory, although that is not generally recommended as then your code runs as you and not a user with more restricted access. Anyway, you do seem to have that, so is a bit strange why that isn't working.

One thing to try in order to work out whether your application is in fact running in daemon mode and somehow Apache configuration is not broken is:


The only other thing can think of is you have AppArmor on Ubuntu enabled and configured in a way that prevents access to directories/files in that location by Apache httpd process. This happens quite a bit with SELinux on Red Hat type operating systems, but never run into anyone who actually bothers to run AppArmor.

BTW, to initialise virtual environments, it is better to avoid activate_this.py if can. See:

On 16 Apr 2023, at 10:08 pm, Harald Fontius <ted...@gmx.net> wrote:

I am trying to run a PYTHON FLASK application created in MS Visual Studio and exported it to a directory call “conjugationgame”.

In the VISUAL STUDIO environment it runs without problems. Now I want to install it on a LINUX Server hosted by IONOS.

UBUNTU  22.04.2 LTS (GNU/Linux 5.15.0-69-generic x86_64) is installed. Apache2 is installed and shows this status:

apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-04-12 15:58:48 UTC; 1 day 23h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 15997 (apache2)
      Tasks: 71 (limit: 2193)
     Memory: 30.1M
        CPU: 55.237s
     CGroup: /system.slice/apache2.service
            
15997 /usr/sbin/apache2 -k start
            
75728 /usr/sbin/apache2 -k start
             
75729 /usr/sbin/apache2 -k start
            
75730 /usr/sbin/apache2 -k start
             └─75731 /usr/sbin/apache2 -k start

I tried to install a mod_wsgi virtual environment following @Luke Peter’s very good video tutorial (183) How to Deploy a Flask App to Linux (Apache and WSGI) - YouTube

In installed the application like this:

<server_installation.png>


I run pipenv install according to this answer to a problem with  mutablemapping python - AttributeError: module 'collections' has no attribute 'MutableMapping' - Stack Overflow

<install pipenv.png> 

Although I got an error running  pipenv install after changing the directory to var/www/conjugationgame.de/conjugationgame/:


<Permission_error_pipenv install.png>

Hard to read:

PermissionError: [Errno 13] Permission denied ‘var/www/conjugationgame.de/conjugationgame/._atomic-writelcmrxftk’ (might be the problem but I couldn’t find anything to solve it)

pipenv –venv gives the link to the virtual environment:


<error_venv.png>

With this link I created the wsgi file like this:


<wsgi.png>

and the config file like this


<config.png>

Checked the syntax of the config and restarted apache2.


<restart config.png>

When calling https://conjugationgame.de I get this error:

[Fri Apr 14 15:18:59.616298 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] mod_wsgi (pid=75730): Failed to exec Python script file '/var/www/conjugationgame.de/__init__.wsgi'., referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616378 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] mod_wsgi (pid=75730): Exception occurred processing WSGI script '/var/www/conjugationgame.de/__init__.wsgi'., referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616487 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] Traceback (most recent call last):, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616514 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927]   File "/var/www/conjugationgame.de/__init__.wsgi", line 4, in <module>, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616520 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927]     with open(activate_this) as file_:, referer: https://conjugationgame.de/

[Fri Apr 14 15:18:59.616569 2023] [wsgi:error] [pid 75730:tid 139907032913472] [client 91.23.91.105:56927] PermissionError: [Errno 13] Permission denied: '/home/hfwds/.local/share/virtualenvs/conjugationgame-4RgIZZXj/bin/activate_this.py', referer: https://conjugationgame.de/

The activate file looks like this:



I tried whatever I could find – without success. Can anybody help?

I also tried user www-data and group www-data in the config file – same problem. I solved the problem before following the answer in this question:

python - Apache/Django/mod_wsgi - [Errno 13] Permission denied: - Stack Overflow

 <activatefile.png>

but I had to reinstall the application again and now the error is permanent.

 

--
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/af11814c-bee5-49ed-9af2-1d8a6fb8c438n%40googlegroups.com.
<config.png><server_installation.png><restart config.png><error_venv.png><wsgi.png><activatefile.png><Permission_error_pipenv install.png><install pipenv.png>

Harald Fontius

unread,
Apr 17, 2023, 8:42:49 AM4/17/23
to modwsgi
Hi Graham, thank you very much for your comments and recommendations. 

1. I do not have  AppArmor enabled - at least I am not aware of
2. I have checked my installation implementing the suggested test applicationn "myapp" described here - it worked fine. So the installation seems to be ok. 
3. I haven't  found the file mod_wsgi.so neither with LD_LIBRARY_PATH set nor without. So I run mod_wsgi-express module-config and received this answer:
LoadModule wsgi_module "/home/hfwds/.local/lib/python3.10/site-packages/mod_wsgi/server/mod_wsgi-py310.cpython-310-x86_64-linux-gnu.so"
WSGIPythonHome "/usr"

what bothers my is that the pyhton home is /user - actually I found python3.10 here: /usr/local/lib/python3.10 but the wsgi_module seem to be under /home/hfwds/.local/lib/python3.10/
I seem to have 2 different python3.10 installations. Might this be a problem? BTW: the one under /usr/ is the latest. 
4. I checked your recommendation with the virtual environments. Actually it seems that I do not necessarily need a virtual environment as I do not plan to have "multiple distinct Python environments for the same version of Python," as described here
So I just want to run one python application that start with __init__.py load view.py that holds the logic runing a flask python project installed here.  
server_installation.png
I still struggeling how the wsgi file would look like to  start this. Any recommendation: Thank you again in advance. 
Kind regard from Germany 
Harald 

Harald Fontius

unread,
Apr 17, 2023, 11:09:44 AM4/17/23
to modwsgi
Now I removed the virtual environment and change wsgi-file to this:
Screenshot 2023-04-17 170647.png
and the config file accordingly and the application starts! 
Now I am struggeling with my sqlite db. Obviously it not enough to just have in the document root like in the test system. If you have a hint for this would be highly recommended! 

Graham Dumpleton

unread,
Apr 17, 2023, 7:09:41 PM4/17/23
to mod...@googlegroups.com
For the database, just make sure not using a relative path to its location. Calculate an absolute path as otherwise it placement will be dictated what the current working directory Apache runs as, which may not be a desirable location. See:

On 18 Apr 2023, at 1:09 am, Harald Fontius <ted...@gmx.net> wrote:

Now I removed the virtual environment and change wsgi-file to this:
-- 
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/9e63aac0-6616-4bb5-86a9-8258c00fa5c9n%40googlegroups.com.
<Screenshot 2023-04-17 170647.png>

Harald Fontius

unread,
Apr 18, 2023, 9:34:15 AM4/18/23
to modwsgi

Thank you very much – yes that was the problem. It works now.

Kind Regards Harald 

Reply all
Reply to author
Forward
0 new messages