/opt/alt/python39/bin/lswsgi: No such file or directory - django

I have a shared Cpanel host with the Litespeed web server. I want to deploy a Django application on it. After creating a Python application inside the Cpanel where I have not deployed the application on the host I try loading the website, and instead of displaying the Django version, I face 503 Unavailable!!
Also inside the "stderr.log" file, there is the following error.
/usr/local/lsws/fcgi-bin/lswsgi_wrapper: line 9: /opt/alt/python39/bin/lswsgi: No such file or directory
I'm creating the application with Python 3.9.
But it works when I create it with Python 3.8 and show the following message when I load the web,
It works!
Python 3.8.6

The issue is mostly caused by the lack of the Python 3.9 WSGI package. On out-of-date versions of LiteSpeed, the package needs to be installed manually.
To work around this, first ensure that LiteSpeed is up to date. LiteSpeed must be at version 5.4.10 for this to work. Once that is confirmed, execute the following script from LiteSpeed. It will pull the required Python Selector packages:
/usr/local/lsws/admin/misc/enable_ruby_python_selector.sh
Refer cpanel support

Related

mod_wsgi on Python 3.10 does not update Django templates without Apache restart

I have been running a Django server on Python 3.8 with Apache and mod_wsgi for some time now, and decided it was time to upgrade to Python 3.10. I installed Python 3.10 on my server, installed the Django and mod_wsgi packages, copied the 3.10 build of mod_wsgi.so to Apache's modules folder, and everything works great ... however, it seems with this build of mod_wsgi, changes to template files do not take effect unless I restart Apache.
As an example, I added a random HTML template file to my website, and started the server with some initial text in that template. Running on the Python 3.8, I am able to change the contents of that template (e.g. echo "More Text" >> test_template.html) and upon refreshing my browser the new text will show up. However doing the same test in 3.10, the new text will not show up. I have tried different browser sessions and hard reloading, it is not a caching issue on the client side, and looking at the response sizes in Apache's access log confirms the data being sent to the client changes in 3.8 but not in 3.10.
I have stood up a test server to isolate the problem, and have narrowed it down to specifically changing the mod_wsgi build (which of course changes the entire Python version used by Django). Still, that confirms it should not be a caching setting of Apache, or any mis-configuration of Django templates, and I have followed the steps here to confirm I am running mod_wsgi in Daemon mode (as I have been for years on this server, this is a long-standing server configured seemingly without issue for Python 3.8).
Lastly, running the Django development server (using base manage.py runserver command) reflects template changes on the fly without issue, and without a server reboot. So as far as I can tell this seems to be a mod_wsgi quirk.
The specific Apache | mod_wsgi | Python version combinations is as follows:
Apache/2.4.41 (Ubuntu) mod_wsgi/4.6.8 Python/3.8
Apache/2.4.41 (Ubuntu) mod_wsgi/4.9.4 Python/3.10
...as reported by Apache's error.log, confirming the modules are loading as expected.
Does anyone know if this is a known issue with Python 3.10 builds of mod_wsgi? Perhaps is there a new setting I'm forgetting? My understanding of Django templates is that they should always reflect changes immediately (without a server restart), however code changes require a restart (or touching of the wsgi.py script); I have never had to restart the server for template changes prior to this change. Any help is appreciated-
Edit: Just tried upgrading my Python 3.8 version of mod_wsgi to the same version (4.9.4), and it still works fine, so there is something about Python 3.10 vs 3.8, or another installed python package. I will keep testing...
I ended up making a post under the mod_wsgi github project, and traced the issue back to a change in Django's behavior in this commit
Full details of that post can be found here
Tl;dr; is there is a caching template loader, which used to only be enabled when DEBUG = False was set, but was updated to always be in effect. I'm not sure why my Python 3.8 build did not have this change, as I had upgraded both builds to the latest Django build available (4.6.1), but my original install was years ago so it's quite possible a fresh install would not have had this issue.
If you still want to disable cached templates as I did, you have to override the template loaders in your Django settings:
TEMPLATES = [
{
'OPTIONS': {
'loaders': ['django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader']
},
},
]

Apache webserver with app using GDAL not working on windows

I am trying to deploy a django project using POSTGIS on my windows 11 PC with Apache 2.4.
The web page is working as long as I am not using 'django.contrib.gis'.
When I add 'django.contrib.gis' to my INSTALLED_APPS and define GDAL_LIBRARY_PATH to point to my gdal installation things stop working.
Specifically, trying to access the web app ends up in infinitely loading the page. Weird enough there are no errors in the apache error log. The apache service starts fine.
As far as I can see gdal install is correct as the app is working fine on the same machine with the same python environment with the django development server.
Actually, I have the same issue with other python libraries that need some dlls, like opencv.
So my guess is that it is a security related issue, but I do not find any clues on how to solve it.
Any ideas?
I tried also to grant rights to the directory where gdal is install in apache conf. But no luck.

Django webserver automatically shuts off on local server when I try to access the admin section

I'm a noob trying to learn Django for the first time, I created a project in a virtualenv on Windows 10. It worked well in the beginning where I was able to login to the admin section after running '''python manage.py runserver'''
But now when I run the same command I'm able to see the Django landing page but as soon as I try to hit http://localhost:8000/admin/ or http://127.0.0.1:8000/admin the server automatically disconnects and I get the "This site can’t be reached" error on Chrome.
I tried changing the port number by running python manage.py runserver 0.0.0.0:8001 but it didn't work. I tried to check if the port (8000) is currently in use by running the cmd (as an admin) netstat -a -b but couldn't find any issues.
The server just quits without any error message
Edit: Currently using Python 3.7.0 and django-3.0.1
There's a ticket about this issue: https://code.djangoproject.com/ticket/31067.
This seems to be a bug in Python 3.7.0, and appears to be fixed in Python 3.7.1. It's still unknown what the exact trigger is for this bug.
Since Django officially only supports the latest patch release of a Python series, this won't be fixed in Django. You can either upgrade your Python version to the latest patch release of 3.7, or downgrade Django to 2.2.
It's a Django 3.0 issue as I've seen. There are so many issues on GitHub, regarding this error.
You may try downgrading to Django 2.* versions for now. Version 2.1/2.2 works fine.

Django site on Webfaction - how the flow of information works, and integrating with Pycharm remote dev

I have been learning Django in the development mode for a two months and I am up to speed with most basic aspects of python + django now. However, I was using the built-in runserver till this time
Now, I have got a Webfaction hosting account and wanted to know the following
1) Webfaction sets up the project with a certain Django version (say 1.6.4) and Python version (say 2.7) initially
The project directory (for say project MYAPP) is /<>/webapps/MYAPP
When the site is running in production mode, how does the apache server know which Python version, and which site-packages versions to use with the MYAPP source code to render the site?
I can see that the MYAPP folder has a lib/python2.7 folder, however when I am connected to SSH terminal, and do a "which python", i see :
which python
/usr/local/bin/python
so, do I take that this is the Python executable that is being used for rendering the website instead of the one in webapps/MYSITE/lib/python2.7 folder? How does the information/data flow about which programs to use during rendering the site with apache mod_wsgi work?
2) I was using a virtualenv in the development mode during testing. How do I use this on webfaction in production mode?
3) I am using Pycharm IDE. It worked well for the development mode. I can see that it has a remote interpreter configuration and a Deployment setting/option.
The python path that the remote interpreter settings tool detects automatically is the python executable at /usr/local/bin/python
Is this fine, or should I be pointing it to the more local python2.7 in the webapps/lib folder?
Thanks a lot of the answers and pls let me know if you need any supplemental info
Note to the OP: This should really be three separate questions.
1) For WebFaction, your Django app will use the Python version (and libraries, etc.) defined in:
~/webapps/<appname>/apache2/conf/httpd.conf
Specifically, you'll want to look at what is defined for WSGIPythonPath (which should mostly match up with WSGIDaemonProcess unless you modify the config and are doing something strange).
Note that which python just tells you what the default python is in your shell. This has nothing to do with the config file for the webapp.
2) You may want to expand on this as to exactly what your use case is and why the default Django webapp created by WebFaction doesn't fit your needs. But the short answer is:
Create a virtualenv on your WebFaction account.
Install Django, etc. into the virtualenv.
Edit the httpd.conf file I mentioned above to use your virtualenv instead.
I've done this with both a Django webapp made via the WebFaction control panel and via a custom mod_wsgi webapp. So it does work. Just make sure to use the right Python version when making your virtualenv.
3) I don't use PyCharm so I can't answer this (one reason why this question should be split up).

ubuntu django and apache, cannot find the site

I am brand new to web app development and thought I would try django as I am familiar with python. I followed the following guide: http://www.lennu.net/2012/05/14/django-deployement-installation-to-ubuntu-12-dot-04-server/ to deploy a django page to the letter. However, I now realize that this guide was for the server version of the OD and i'm running the desktop version. When I try to open my site in chrome (amitash.r) it fails with a page not found. Now when I open localhost, I get an internal server 500 error. All my config files are exactly as stated in the guide. Any fixes?
Can you post your mod_wsgi script and Apache VirtualHost file?
Following the instructions from the link you gave, the mod_wsgi script should be in:
/srv/my_project/app/conf/apache/django.wsgi
The VirtualHost file location from the link should be:
/etc/apache2/sites-available/DOMAIN
Make sure you enabled your site. If you named your file DOMAIN, like the instructions, you should enable the site using:
a2ensite DOMAIN