I have the following directive in my apache2_site.conf file:
CustomLog "|/home/me/myjlog.py %h \"%r\"" common
which should create a log in my MySQL server. myjlog.py
starts with:
#!/usr/bin/python3
import pymysql
import sys
ip=sys.argv[1]
req=sys.argv[2]
...
However, for each request to my site, the logging in my database isn't done.
What appears in /var/log/apache2/error.log
is:
AH00106: piped log program '/home/me/myjlog.py %h "%r"' failed unexpectedly
Traceback (most recent call last):
File "/home/alibaba/myjlog.py", line 2, in <module>
import pymysql
ModuleNotFoundError: No module named 'pymysql'
It seems that python doesn't recognize the module pymysql
. However this module is installed for users me
and root
...
How may I guarantee access to pymysql
to apache2
?
EDIT:
1 - I don't use any virtual environment on this server.
2 - After setting chmod -R g+rx /home/me/.local
and chmod -R a+rx /home/me/.local
, I run sudo -u www-data python3 -m site
and obtained:
sys.path = [
'/home/me',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/me/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/me/.local' (exists)
USER_SITE: '/home/me/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True
But still the CustomLog
directive can't access pymysql
.