Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CustomLog directive with pipe (python, mysql)

40 views
Skip to first unread message

João Carlos Sousa Dias

unread,
Nov 17, 2021, 6:10:15 PM11/17/21
to
Hello,

I am trying to create a site with the Apache2 web server with a .conf file like:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName 00000000000000000.net
ServerAdmin webm...@00000000000000000.net

Redirect / https://www.google.com/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

CustomLog "|/home/me/logger.py %h \"%r\"" common

SSLEngine on

SSLCertificateFile /.../cert.pem
SSLCertificateKeyFile /.../key.pem

</VirtualHost>
</IfModule>

Yes, I want double logging. Where the python file /home/me/logger.py is:

#!/usr/bin/python3
import pymysql

connection=....

Thus imports pymysql package (installed for the me user, also with access by root).

However the second CustomLog fails: the error.log file shows:

[Wed Nov 17 06:34:36.554862 2021] [core:notice] [pid 7912:tid 139954445958080] A
H00094: Command line: '/usr/sbin/apache2'
Traceback (most recent call last):
File "/home/alibaba/myjlog.py", line 2, in <module>
import pymysql
ModuleNotFoundError: No module named 'pymysql'
AH00106: piped log program '/home/me/logger.py %h "%r"' failed unexpectedly
Traceback (most recent call last):
File "/home/me/logger.py", line 2, in <module>
import pymysql
ModuleNotFoundError: No module named 'pymysql'

The package pymysql is not accessible by the user used by apache (www-data) and this user has no area in the disk. I already changed the permissions of the package directory (chown -R 755 /home/me/.local). Also, the result of the command

sudo -u www-data python3 -m site

is:

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

However the inacessibility of pymysql to apache is the origin of the current error.

How can I write in my mysql database from the apache? Can I use the current method?
0 new messages