I have developed a Django 1.8 application using Python 3.3. I am trying to deploy the application on a university dedicated server with Red Hat Enterprise Linux Server release 7.2 (Maipo). (Note: RHEL does not let me install newer versions of Django and Python)
I had difficulty with installing mod_wsgi using the RHEL Apache and I ended up installing:
pip install -U mod_wsgi-httpd
pip install mod_wsgi
Everything works perfectly when I use the following setup:
python manage.py runmodwsgi --setup-only --port=80 --user=iman --group=root --server-root=/etc/mod_wsgi-express-80
However, when I want to setup HTTPS, using the following setup does not return any error message, but the website does not show up neither with http:// nor with https:// prefixes.
python manage.py runmodwsgi --setup-only --port=80 --user=iman --group=root --server-root=/etc/mod_wsgi-express-80 --https-only --https-port=443 --ssl-certificate-file=/etc/sslcert/iman.crt --ssl-certificate-key-file=/etc/sslcert/private/iman.key --ssl-ca-certificate-file=/etc/sslcert/certs/ca-bundle.crt --server-name=iman123.university.edu
Here are helpful resources that I found about mod_wsgi:
mod_wsgi docs
GitHub repository
Running HTTPS and client authentication with mod_wsgi-express
pip install mod_wsgi-express left out mod_ssl.so
Thank you so much for your time and concern and apologies in advance if I am doing something wrong.
Related
UPDATE 1: PIL and RDKIT produced import errors because the .dll files were not placed in /venv//Lib/site-packages
I removed both packages from environment and commented out their code from my project.
Next I updated the base base environment:
conda update conda #from base env
Then I upgraded pip and setuptools and reinstalled pillow:
python -m pip install pip --upgrade
pip install setuptools --upgrade
pip install pillow
I can now add my PIL content back to the project and it will work just fine on the production server, without rdkit installed.
RDKIT is only available as a conda install, it still does not install properly and breaks PIL in the process(rdkit depends on pillow). I have reinstalled from both the rdkit and conda-forge channels. Neither work.
What is the proper way to fix this problem? I feel like the hack around of moving .dll files is risky and not a good solution.
UPDATE 0: RDKIT will not load into any server
I created a basic django project similar to what you would find in the tutorial with no static files. The project successfully published to the Apache server describe below in the original post and in Windows 10 IIS. Next modified the models.py to import rdkit and both servers gave the import error and the site would not display.
Original post:
RDKIT is the only package not loading into our production server.
We successfully set up a Wampserver to run Apache and host our Django project . . .but have to comment out all the code associated with rdkit for it to work. This inhibits many required features.
There were no issues using rdkit in Django's test server.
Primary wsgi error:
from .rdBase import rdkitVersion as __version__\r, referer: http://localhost/APP/
ImportError: DLL load failed: The specified module could not be found.\r, referer: http://localhost/APP/
Relevant packages and version details:
Windows 10
Django 2.2
Python 3.7
conda 4.8.2
rdkit 2019.09.3 conda-forge
Wampserver 3.2
Apache 2.4.41
mod-wsgi 4.7.1
postgresql 10
The methods in this blog describe how we setup the production server. With one minor change, we did not alter the httpd_vhosts.conf file and only setup the standard localhost.
The error is reproducible by trying to import rdkit(or one of its methods) into any file needed to host a web application in the described environment.
We found this 2016 thread on the rdkit sourceforge and it sounds like someone else was having a similar problem on a Linux system. This is our first time setting up a server and we have not been successful at translating the recommended fix from linux to windows. There was no follow up to know if the recommendation was attempted let alone successful.
These 2012 slides lend us to believe someone was trying to overcome a similar issue in linux (slide 9)
How would a package need to be altered to allow it to load into a webserver?
Thank you, we greatly appreciate your time and assistance.
I'm trying to switch a django site from running in python 3.6 to python 3.7 on Ubuntu 16.04. To do so I created a new environment in the same path as the old and have re-installed all of the dependencies.
The Apache server, however, fails with the following error:
Fatal Python error: Py_Initialize: Unable to get the locale encoding ModuleNotFoundError: No module named 'encodings'
Which error, after a bit of research, seems to be due to the WSGI configuration, as per:
You cannot for example force mod_wsgi to use a Python virtual
environment created using Python 3.5 when mod_wsgi was originally
compiled for Python 2.7. This is because the Python library for the
Python installation it was originally compiled against is linked
directly into the mod_wsgi module. In other words, Python is embedded
within mod_wsgi. When mod_wsgi is used it does not run the command
line python program to run the interpreter and thus why you can’t
force it to use a different Python installation.
from: https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
thanks to: Django Apache wsgi changes python version
The OP in the above ended up just wiping the setup clean and starting from scratch. This seems a bit extreme to me, as it seems like I should just be able to re-install/re-configure mod-wsgi to run with python3.7
In this line of thinking, I uninstalled and reinstalled both, libapache2-mod-wsgi-py3 and mod_wsgi. The former, however, just reconfigures to 3.6 automatically, as seen below:
root#server1:~# dpkg -S mod_wsgi
libapache2-mod-wsgi-py3: /usr/lib/apache2/modules/mod_wsgi.so
libapache2-mod-wsgi-py3: /usr/lib/apache2/modules/mod_wsgi.so-3.6
and the mod_wsgi installation fails with:
RuntimeError: The 'apxs' command appears not to be installed or is not executable.
How can I re-build wsgi with python 3.7?
I have a VPS and it does not provide a one-click Python Installation as some other VPS services do. After many failed attempts I finally installed Python 3.6.3 via my WHM ssh.
Can someone guide me on how to set up Django next and proceed to development?
First of all: please don't blame me for making newbie mistakes or anything like that. I am still learning and need just a bit of help.
So I created a droplet on digitalocean with ubuntu 16.04 and logged in and ran:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-setuptools python-pip apache2 libapache2-mod-wsgi
and installed django:
sudo pip install Django==11.1.4
and created the project (without virtualenv) in a directory:
django-admin.py startproject mysite
However, if I do "runserver"
python manage.py runserver
and type xxx.xxx.xxx.xx:8000 in firefox there is nothing even though I see in the terminal that the runserver did work. If I type xxx.xxx.xxx.xx then I see the default page of apache. My goal is to run django over apache but I cannot even get started because the runserver which is just for testing didn't even work. How can I make this work, where did I make a mistake?
Edit: the output of the runserver is:
Performing system checks...
System check identified no issues (0 silenced).
September 02, 2017 - 22:21:12
Django version 1.11.4, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The manage.py runserver is NOT meant for serving your pages through Apache, it is ONLY meant as a lightweight local development server for running your code as you write it.
Instead, you should be following a guide to run DJango on Apache using mod_wsgi.
The only bit of advice I'd be willing to give that might help in this situation is that if you're trying to host runserver inside a virtual machine or Docker container, you need to explicitly set the host binding to
manage.py runserver 0.0.0.0:8000
Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled).
Again, runserver is for local development ONLY. Do NOT use it to try and host a site through Apache since that's what hosting drivers like mod_wsgi are for.
The runserver and apache are 2 different things.
The local runserver is used by a developer to code and run the web application locally. Usually the settings loaded locally are different, for example the production website use settings and locally you use settings_local.py that ovverrides the production settings (very simplified example).
If you run your runserver and you load http://127.0.0.1:8000/ you should be able to see something and on your terminal you should see the runserver response to your requests from the browser.
If your goal is deploy your web application than you need something like apache, but not locally. IMHO, I suggest you to avoid Apache and use Nginx + Gunicorn + supervisord to manage your webapp on your production server. Much much easier to configure.
I have a Django project.
I'am using xvfb on ubuntu 14.04 server with selenium and firefox to generate pdf from html.
Below is the code sample which is inside a python script.
cmd = 'xvfb-run -a python path/to/script.py'
subprocess.call(cmd, shell=True)
When I run it through django shell, it's working fine and pdfs are genearted on the server.
But when I run it via apache2, it's creating some never ending processes probably deadlocks and apache2 is giving time out repsonse.
Apache2 mayn't use 3rd party programs which is xvfb here.
Should I integrate xvfb with apache2 somehow?