I have installed mod_wsgi from source to use python2.7 like this:
git clone https://github.com/GrahamDumpleton/mod_wsgi.git
./configure --with-python=/usr/bin/python2.7
make
make install
When I try to start apache, I get the error:
Starting httpd: Syntax error on line 1020 of /etc/httpd/conf/httpd.conf:
Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
[FAILED]
My httpd.conf looks like this:
Alias /static/ /var/www/html/django/shared/static/
<Directory /var/www/html/django/shared/static/>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /var/www/html/django/wsgi.py
WSGIPythonPath /var/www/html/django
<Directory /var/www/html/django>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Why is apache not finding mod_wsgi?
If that's your entire config file, you never told Apache to load the module.
That's why the error message says "Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration".
See LoadModule for reference, DSO support for an introduction, and the sample configs that come with Apache for examples.
As #abarnert mentioned above, I didn't not add the line to the modules section of apache config. Adding that solved the problem. This apparently doesn't get added automatically when you add mod_wsgi from source as opposed to a yum install.
Related
I have an Apache2 server hosting multiple Django websites. All except one use Django 3.8, using a mod_wsgi compiled on Python 3.7. The outlier (let's call it SiteX) uses Django 4.0, which requires Python 3.8+. I want SiteX to use a virtual environment with these newer versions of Python and Django, while the other sites keep using their default versions.
For SiteX, I've created a virtual environment venv in its directory. But from what I understand, the current mod_wsgi installed is not compatible with its version of Python, so specifying WSGIPythonHome in the conf file won't do anything.
the current mod_wsgi (4.7/python 3.7) is loaded in /etc/apache2/mods-available/wsgi.load with the line
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
I've tried creating a new mod_wsgi, this time using the Python module mod_wsgi, which I've installed in venv. In the .conf file for a group of Django sites (that include SiteX) I tried specifying this unique version of the mod_wsgi above the <VirtualHost> block with the line:
LoadModule wsgi_module "/var/www/html/app/SiteX/venv/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so"
but running $ apachectl configtest says: module wsgi_module is already loaded, skipping.
I found a solution for multiple mod_wsgi's using WSGIDaemonProcess but the solution's .conf looks slightly different that mine. Below is a snippet of the relevant lines of the .conf, but I'm not sure where to insert WSGIDaemonProcess.
<IfModule mod_ssl.c>
# LoadModule wsgi_module, WSGIPythonHome, WSGIPythonPath here?
<VirtualHost _default_:443>
...
Alias /static /var/www/html/app/imagingTracking/static/
...
# other django website Directory blocks here
...
<Directory /var/www/html/app/SiteX/static/>
Require all granted
</Directory>
<Directory /var/www/html/app/SiteX/SiteX/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
</IfModule>
In addition I am not sure where to locate relevant .wsgi files for this.
Is my goal even tractable? It would be a nuisance if I'd have to downgrade SiteX just for this reason.
I am no expert on Django. I am able to run the app on my local machine well. I want to deploy this app on our internal server.
Versions I am using: Python: 2.7, Django 1.11, Apache: 2.4
Ports Open: 9991
When I access the port from any machine, it gives me no error. For e.g. xxx.xx.xxx.xxx:9991 shows Apache page.
But when I add the URL to the app
xxx.xx.xxx.xxx:9991/WebApp1Url
it gives error.
Below is my configuration of httpd.conf
Listen 9991
<VirtualHost *:9991>
Alias /static "C:/xxx/DjangoSite/WebApps/WebApp1/static"
<Directory "C:/xxx/DjangoSite/WebApps/WebApp1/static">
Require all granted
</Directory>
<Directory "C:/xxx/DjangoSite/WebApps/WebApps">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
Below is my wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "WebApps.settings")
application = get_wsgi_application()
from WebApp1.wsgi import WebApp1
application = WebApp1(application)
settings.py contains:
WSGI_APPLICATION = 'WebApps.wsgi.application'
I can assure that the paths to static and wsgi.py are correct. I can't figure out what is not right. Can someone please provide pointers as to which step is missing? Any help is appreciated. Pardon any typos above. Thank you in advance.
The first stop for any problems, new user or experienced, should be Django's very detailed, extensive, up-to-date, versioned documentation. There's even a section for deploying a Django project with Apache HTTPD.
Some stuff quoted below, but broadly:
Install Apache HTTPD with mod_wsgi (installing the module on Windows is probably the hard part, the mod_wsgi docs link to this guide)
Add WSGI directives to a conf file
The official mod_wsgi documentation is your source for all the details about how to use mod_wsgi. You’ll probably want to start with the installation and configuration documentation.
Basic configuration
Once you’ve got mod_wsgi installed and activated, edit your Apache server’s httpd.conf file and add the following. If you are using a version of Apache older than 2.4, replace Require all granted with Allow from all and also add the line Order deny,allow above it.
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonHome /path/to/venv
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
I am attempting to get a website to load within a web browser using Django + mod_wsgi and apache. I have exactly the same problem as in This Question Here, but the solution found there does not work in my case.
Here is my httpd-vhosts.conf setup:
WSGIDaemonProcess binshellpress.com python-home=/usr/local/docs/binshellpress-production/virtpy/ python-path=/usr/local/docs/binshellpress-production/virtpy/lib/python3.6/
WSGIProcessGroup binshellpress.com
WSGIApplicationGroup %{GLOBAL}
<VirtualHost *:80>
ServerAdmin webmaster#binshellpress.com
DocumentRoot "/usr/local/docs/binshellpress-production/root"
ServerName binshellpress.com
ServerAlias www.binshellpress.com
ErrorLog "/var/log/httpd/bsp-error_log"
CustomLog "/var/log/httpd/bsp-access_log" common
Alias /robots.txt /usr/local/docs/binshellpress-production/static/robots.txt
Alias /favicon.ico /usr/local/docs/binshellpress-production/static/favicon.ico
Alias /media/ /usr/local/docs/binshellpress-production/media
Alias /static/ /usr/local/docs/binshellpress-production/static
<Directory /usr/local/docs/binshellpress-production/static>
Require all granted
</Directory>
<Directory /usr/local/docs/binshellpress-production/media>
Require all granted
</Directory>
WSGIScriptAlias / /usr/local/docs/binshellpress-production/binshellpress/wsgi.py process-group=binshellpress.com
<Directory /usr/local/docs/binshellpress-production/binshellpress>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</Virtualhost>
I have a virtual environment set up at /usr/local/docs/binshellpress-production/virtpy. I have rebuilt mod_wsgi to explicitly use that virtual environment. I have performed the permissions modifications as described in the answer to This Question
No change.
I am desperate. I have been searching up and down. I can't figure out what to do. Please, help me. I beg you.
Thank you, for anything, thank, just please, help me, thank you.
First off, check the value of python-home is correct by running command line Python you want to use and do:
import sys
sys.prefix
It should be the same value.
Also be aware that:
python-path=/usr/local/docs/binshellpress-production/virtpy/lib/python3.6/
shouldn't be needed and I can't see why you would add that.
Next, run the check in:
http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-shared-library
What libraries and locations is mod_wsgi linked against?
If your mod_wsgi binary is definitely compiled against the correct Python version, the only other issue it could be is that it is a non standard Python installation and not a system Python. If this is the case and it isn't linked correctly, it may be finding the system Python shared library instead of that for your separate Python installation.
Again from the command line for Python from the virtual environment, try:
import sys
sys.real_prefix
What do you get for that?
I am trying to make my Flask application work on CentOS server. Basically the issue is that I have Python 2.6 installed in /usr/bin which is system default and Python 3.4 installed in /usr/local/bin. I would like to use Python 3.4 virtualenv or at least Python 3.4 interpreter for mod_wsgi to run my application.
I have created virtualenv in ~/virtualenvs/flask.
I have this WSGI script:
import os
import sys
from logging import Formatter, FileHandler
APP_HOME = r"/home/fenikso/Album"
activate_this = os.path.join("/home/fenikso/virtualenvs/flask/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
sys.path.insert(0, APP_HOME)
os.chdir(APP_HOME)
from app import app
handler = FileHandler("app.log")
handler.setFormatter(Formatter("[%(asctime)s | %(levelname)s] %(message)s"))
app.logger.addHandler(handler)
application = app
And following config in Apache:
<VirtualHost *:80>
ServerName album2.site.cz
Alias /static "/home/fenikso/Album/static"
Alias /photos "/home/fenikso/Album/photos"
Alias /thumbs "/home/fenikso/Album/thumbs"
WSGIScriptAlias / "/home/fenikso/Album/wsgi.py"
<Directory "/home/fenikso/Album">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/static">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/photos">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/thumbs">
AllowOverride None
Allow from all
</Directory>
</VirtualHost>
However, when trying to run the application, I get an error:
Apache/2.2.15 (Unix) DAV/2 mod_wsgi/3.2 Python/2.6.6 mod_fcgid/2.3.7 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips SVN/1.6.11 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
mod_wsgi (pid=14627): Target WSGI script '/home/fenikso/Album/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=14627): Exception occurred processing WSGI script '/home/fenikso/Album/wsgi.py'.
Traceback (most recent call last):
File "/home/fenikso/Album/wsgi.py", line 15, in <module>
from app import app
File "/home/fenikso/Album/app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
I have noticed that either Python 2.6 is being ran and my virtualenv is not activated. What would be the proper way to get this working and still have the Python 2.6 as a system default?
You have to add the following line in your apache.conf in order to give the right executable and the path to the virtualenv.
WSGIPythonHome /usr/local/bin
WSGIPythonPath /home/fenikso/virtualenv/lib/python3.4/site-packages
You will find all the options of these two command in the mod_wsgi documentation
Be aware that you must have the version of mod_wsgi compatible with the python executable. In your case, you probably have to install mod_wsgi3.4 and configure apache to use it instead of the standart mod_wsgi module.
The whole configuration file should be :
WSGIPythonHome "/usr/local/bin"
WSGIPythonPath "/home/fenikso/virtualenv/lib/python3.4/site-packages"
<VirtualHost *:80>
ServerName album2.site.cz
Alias /static "/home/fenikso/Album/static"
Alias /photos "/home/fenikso/Album/photos"
Alias /thumbs "/home/fenikso/Album/thumbs"
WSGIScriptAlias / "/home/fenikso/Album/wsgi.py"
<Directory "/home/fenikso/Album">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/static">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/photos">
AllowOverride None
Allow from all
</Directory>
<Directory "/home/fenikso/Album/thumbs">
AllowOverride None
Allow from all
</Directory>
</VirtualHost>
Look into the WSGIPythonHome and WSGIPythonPath directives. It's also possible that you have a python2.6 mod_wsgi installed, mod_wsgi must be compiled for the intended python version and does not support multiple python versions. So check that your mod_wsgi is py3.4 compatible and set the directives above.
Alternatively, you could run the flask app with a python server like gunicorn and proxypass from apache to gunicorn.
Another option, which I believe is much cleaner, logical, and flexible, is to simply reference the python interpreter from your venv at the beginning of your wsgi file. This way, it is easy to change (no fiddling with system config files) and opens the possibility for multiple apps running with different python environments, like so:
#!/path/to/your/venv/bin/python
If the python version installed on the system is different from the python version used in the virtual environment, then mod_wsgi will not work because mod_wsgi is always compiled for a specific python version.
In this situation, you need to install mod_wsgi in a virtual environment
pip install mod_wsgi-standalone
Then such a module should be loaded instead of the default one installed in the system.
For Ubuntu for example, modify the path to the module in /etc/apache2/mods-available/wsgi.load
LoadModule wsgi_module /home/user/etc/.venv/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so
Then in order to avoid the error "no such file or directory: mod_wsgi (pid=XXXX): Couldn't bind unix domain socket '/usr/local/opt/httpd/logs/wsgi.xxxxx.11.1.sock" should be added to the httpd.conf file:
WSGISocketPrefix /var/run/wsgi
After restarting apache everything should work
I get this error when I try to run my django site on apache. The site works on the development server:
ViewDoesNotExist at /
Could not import myproject.modulename.views. Error was: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so, 2): Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /Applications/MAMP/Library/lib/libjpeg.8.dylib
I am not sure how to resolve the issue. Other django sites work on this apache installation. The directory is on the path specified in my apache.conf file (see bottom of the post).
The three files referenced in the error message exist in the locations indicated.
_tkinter.so - /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_tkinter.so
ImageIO - /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
libjpeg.8.dylib - /Applications/MAMP/Library/lib/libjpeg.8.dylib
I am not sure what __cg_jpeg_resync_to_restart is.
Below is the original message I put up when I was trying to figure out what the error message meant. Thanks to sacabuche for pointing me in the right direction.
I am trying to get a Django Site to run on apache. It works on the django development server, but I get this error when I try to run it on apache with mod_wsgi. I know mod_wsgi works because I had a small trial site (that was a scaled down version of this stie) working on my mamp development server. A feat I managed with the help of others via this post: Django/mod_wsgi and PHP as Virtual Hosts on same Apache Server using MAMP
The new site uses a different database and is now at the localhost root, but otherwise is very similar, so this error is baffling me.
Here is the code for my apache conf (note: the php site works, and if I redirect the WSGIDaemonProcess to the old site, it loads without problem):
ServerName localhost
UseCanonicalName Off
DocumentRoot "/Applications/MAMP/htdocs"
Alias /phpsite /Applications/MAMP/htdocs/phpsite
<Directory "/Applications/MAMP/htdocs/phpsite">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess site1 display-name=%{GROUP}
WSGIProcessGroup site1
Alias /media/ /Applications/MAMP/htdocs/media/
<Directory /Applications/MAMP/htdocs/media>
Options ExecCGI
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /Users/sequoia/djangoprojects/myproject/apache/django.wsgi
<Directory /Users/sequoia/djangoprojects/myproject/apache>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Thanks.
Well it seems that a symlink is broken, so i looked and i found something in this forum
delete the symlinks "libpng.dylib" and "libjpeg.dylib" in "<installation directory>/lib"
Create new symlinks to the right libs.
ln -s /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libPNG.dylib /Applications/MAMP/Library/lib/libPNG.dylib
ln -s /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib /Applications/MAMP/Library/lib/libJPEG.dylib
I have no Mac rigth here, but first i would verify that the origin of the symlink exist, i hope this will solve your problem.
Don't you miss the + or - sign in your options statement?
Example of statement:
Options -Indexes +FollowSymLinks