Configure EasyApache-Experimental for Python with mod_wsgi
I would like to run Django (python) on my cPanel VPS. My current web host runs on CloudLinux, and as I understand it, that is a requirement for the Setup Python App. I also understand there is an aspect of this tool called Passenger, and that I'm entirely unfamiliar with. I'm looking for some more flexibility on software versions, hence why I'm looking into a VPS. I have come across the following link:
I understand I can go through the EasyApache4 Experimental Repository to install mod_wsgi. Can anyone provide come guidance on how I would continue configuring cPanel, and most likely Apache, to serve a Django site? The Setup Python App places the following .htaccess in the web root:
The Quick Configuration Guide here: Is mildly similar, but doesn't reference the virtualenv that is to be used by Django:
but it also indicates "any static files contained in the DocumentRoot will be hidden and requests against URLs pertaining to the static files will instead be processed by the WSGI application." This seems somewhat different from the CloudLinux way which allows Apache to still serve any content in the document root. I know this is all at my own risk, but I don't mind learning something, and will just redo the VPS if the cPanel installation is fubar'd. Anyone have some guidance?
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/path-to-application-directory"
PassengerBaseURI "/"
PassengerPython "/home/user/virtualenv/name-of-application-directory/3.7/bin/python3.7"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION ENDThe Quick Configuration Guide here: Is mildly similar, but doesn't reference the virtualenv that is to be used by Django:
WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgibut it also indicates "any static files contained in the DocumentRoot will be hidden and requests against URLs pertaining to the static files will instead be processed by the WSGI application." This seems somewhat different from the CloudLinux way which allows Apache to still serve any content in the document root. I know this is all at my own risk, but I don't mind learning something, and will just redo the VPS if the cPanel installation is fubar'd. Anyone have some guidance?
-
I have not yet figured out how to install and point to Python 3.7 however...
Does a CentOS cPanel install make use of Python in any way? I used a symbolic link to point to python36, and it seems to work after reloading Apache. I was thinking this could work until I find a better solution at the server configuration level and to work with virtualenv.0 -
HI @CanadaGuy We do use python 2.7.5: # python --version Python 2.7.5
As far as installing a newer version of Python, we don't provide support for that but I did find a few tutorials online that suggested ways this can be done: Install Python 3.x in WHM-cPanel Server - Sysally Building Python2.7 and Python3 on CentOS and cPanel - The Wonderful World Of Linux I can't speak for the validity of these but I did look them over, there are a number of other tutorials out there as well. Thanks!0 -
HI @CanadaGuy We do use python 2.7.5:
Is there a list of scripts that use the default Python install? I'd be interested in verifying they could run under Python 3, unless you already know it doesn't. **edit** I guess this is pretty irrelevant. Installing python3 in parallel isn't the trouble, it is the server configuration I'm having difficulty with.0 -
Hi @CanadaGuy I do not have a list, though amongst other items I can tell you mailman and SpamAssassin are both python based. The links I shared should have provided some information on how to run Python3 on the server though I'm sure there are other tutorials out there. 0 -
Hi @CanadaGuy I am not sure if you have solved this or not. This is the steps I took to serve Django App, I am sure someone might find it useful. 1. Install Python3.6 2. Install mod-alt-passenger package which comes with CloudLinux 3. Uploaded the django app on a directory ( let's say it is /home/user/approot/) 4. Install virtual environment, I installed it in the app root ( /home/user/approot/env) 5. Activate the virtual environment and install required packages. 6. Run manage.py runserver to check if the server runs without any error. ( I did it as a final check if I missed anything) 7. Build the passenger_wsgi.py, this is my very simple passenger_wsgi.py, advanced = "appname.settings" from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
7. Now to overwrite Apache settings. Create a include.conf file and follow the0
Please sign in to leave a comment.
Comments
6 comments