Reputation: 951
I'm trying to roll out a pyramid app to a production site.
As of now, I've created the env file where the app is placed in out of the public_html, something like below:
[~/env] $
So I've typed
$ ../bin/pserve production.ini,
However, when I access www.mydomain.com, it is still showing the index.html. How should I resolve this?
I'm using a CentOS 64bit + Apache + mod_wsgi.
Settings are as followed:
Apache/2.2.24 (Unix)
mod_ssl/2.2.24
OpenSSL/1.0.0-fips
mod_wsgi/3.3
Python/2.6.6
mod_auth_passthrough/2.1
mod_bwlimited/1.4
FrontPage/5.0.2.2635 configured -- resuming normal operations
In my production.ini file, it is as followed
[app:main]
use = egg:ECommerce
reload_templates = false
debug_authorization = false
debug_notfound = false
debug_routematch = false
debug_templates = false
default_locale_name = en
mongodb.url = mongodb://my.ip.address
mongodb.db_name = mycart_demo
[filter:weberror]
use = egg:WebError#error_catcher
debug = false
;error_log =
;show_exceptions_in_wsgi_errors = true
;smtp_server = localhost
;error_email = [email protected]
;smtp_username = janitor
;smtp_password = "janitor's password"
;from_address = paste@localhost
;error_subject_prefix = "Pyramid Error"
;smtp_use_tls =
;error_message =
#[pipeline:main]
#pipeline =
# weberror
# ECommerce
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 8080
# Begin logging configuration
[loggers]
keys = root, ecommerce
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_ecommerce]
level = WARN
handlers =
qualname = ecommerce
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
# End logging configuration
I've managed to roll out on a production site, however, now, it's showing a 500 internal server error...
In the apache error_log, it's showing:
[Sun Apr 07 23:17:47 2013] [alert] [client <ip_address>]
/home/vretnet9/public_html/.htaccess: WSGIScriptAlias not allowed here
So I went ahead to take a look at .htaccess
.htaccess
Options +ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
WSGIScriptAlias ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
WSGIDaemonProcess root processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup root
WSGIApplicationGroup %{GLOBAL}
I don't know if it should actually be calling the .htaccess or if the scriptalias should be the same as the one in my .conf which is located in
/usr/local/apache/conf/userdata/std/1/$user/$domain/modwsgi.conf
the contents of modwsgi.conf is as followed:
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=vretnet9 group=vretnet9 threads=4 \
python-path=/home/vretnet9/modwsgi/env/lib/python3.3/site-packages
WSGIScriptAlias /ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
<Directory /home/vretnet9/modwsgi/env>
WSGIProcessGroup pyramid
Order allow,deny
Allow from all
</Directory>
EDIT In the apache error_log, the following is being recorded:
[Mon Apr 08 02:17:22 2013] [error] Traceback (most recent call last):
[Mon Apr 08 02:17:22 2013] [error] File
"/home/vretnet9/modwsgi/env/pyramid.wsgi", line 5, in <module>
[Mon Apr 08 02:17:22 2013] [error] from pyramid.paster import get_app,
setup_logging
[Mon Apr 08 02:17:22 2013] [error] File "/home/vretnet9/modwsgi/env/
lib/python3.3/site-packages/pyramid/paster.py", line 1, in <module>
[Mon Apr 08 02:17:22 2013] [error] import os
[Mon Apr 08 02:17:22 2013] [error] ImportError: No module named os
EDIT #2
This is my result when running in shell:
[~/modwsgi/env]# python
Python 3.3.0 (default, Mar 27 2013, 09:31:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print (os.getcwd())
/home/vretnet9/modwsgi/env
Upvotes: 0
Views: 1647
Reputation: 4755
That is not how you will put a pyramid project into production using mod_wsgi + Apache. I recommend reading The official documentation
When you run ../bin/pserve production.ini
it starts a paste HTTP server at port 8080 (defined in production.ini
)
Ideally you will want to install pyramid in a fresh virtualenvironment and then configure mod_wsgi to use that instance of python. You will have to add a .wsgi
script to your project and configure mod_wsgi to run that script on Apache startup.
EDIT
The ScriptAlias (and all related parts) should be in your modwsgi.conf (Make sure you import modwsgi.conf in your actual apache conf).
In that file you should define your PYTHONPATH and PYTHONHOME( esp. If you have a virtualenv) and the rest of the stuff you have already defined (WSGIApplicationGroup, WSGIScriptAlias etc.)
IMPORTANT - Make sure your apache user (apache) has read-execute permissions to the .wsgi script all the way. This means even your /home directory should be accessible to apache.
I would recommend creatijg a seaparate directory (say /opt/proj) for hosting the app and another (say /opt/env for the environment).
Here's how my pyramid.conf looks. I have Python 2.6 and keep my project (only the static things like css,images,js, and the .wsgi script) at /opt/save_project. My virtualenv is /opt/pyra
WSGIPythonHome /opt/pyra
WSGIPythonPath /opt/pyra/lib/python2.6
<VirtualHost 31.1.1.22:8005>
DocumentRoot /opt/save_project
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIProcessGroup %{GLOBAL}
WSGIDaemonProcess pyramid user=apache group=apache \
python-path=/opt/pyra/lib/python2.6
WSGIScriptAlias / /opt/save_project/pyramid.wsgi
# Get the static and favicon.ico pages working by properly aliasing them
Alias /favicon.ico /opt/save_project/static/images/favicon.ico
Alias /static /opt/save_project/static
<Directory /opt/save_project>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
You may see mod_wsgi docs for more information
Upvotes: 1