setup apache2 + python like this.
in other words: how to print-output a lot of <html> special characters inline from a python script, that is run by apache2 webserver.
how hard can it be right?
vim /var/www/html/index.py
#!/usr/bin/env python3 """ this will allow to use inline python for dynamic website output :) """ __author__ = "user@domain.com" import sys sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="utf-8", newline=None, buffering=1) print("Content-Type: text/html") print() print(""" <html> <head> crazy html js css goes here </head> <body> </body> </html> """) # per default for security reasons, apache2 should run as non-root user www-data # fix permissions chown -R www-data: /var/www/
now start browser to http://127.0.0.1/index.py
Links:
- https://dwaves.de/2024/01/21/gnu-linux-how-to-setup-apache2-python3-aka-a-python-based-test-webserver-lampy-how-to-100x-faster-speed-python-with-cython/
- on CentOS7, RHEL7 it is called httpd
creditz:
thanks to Johann Patrak: “learned the hard way that Python does not always use UTF-8 for sys.stdin/stderr/stdout.”
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!