0

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 = janitor@example.com
    ;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
Gino
  • 951
  • 1
  • 12
  • 24
  • You do not say what server is already installed. You should try to figure out why nginx is not running. It's probably because your other server application is using port 80. Check the logs of nginx. Also, once nginx is running, this article in the cookbook might help you http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/deployment/nginx.html – Antoine Leclair Mar 27 '13 at 22:14
  • In your development.ini, what port is your app set to run on? Usually I don't think it defaults to 80. You might have to stop the default site (apache?) and set the pyramid app to respond to port 80? Although, on my production server I believe it is using nginix as well. – Peter Tirrell Mar 28 '13 at 01:43
  • I'm using apache + mod_wsgi – Gino Mar 28 '13 at 03:55

1 Answers1

1

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

RedBaron
  • 4,717
  • 5
  • 41
  • 65
  • ah, I've forgotten to add in modwsgi, it should be [~/modwsgi/env], my bad, I'm following the instructions in here: http://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/modwsgi/index.html. I'm stuck at item #9, I'm going to deploy the app in various sites from time to time, if I'll need to restart apache every time when I added in the sites, I think that is a bit ridiculous. I need something that when I run ./bin/pserve MyApp/production.ini whether it is in abc.com or 123.com, it will start up without having to restart apache. And what if I can't do a sudo apache restart? – Gino Mar 28 '13 at 04:56
  • The thing is that `pserve` starts a Paste (or is it Waitress?) server and NOT the Apache one. As far as I know you will have to restart apache every time you install,upgrade,modify the configuration of the app – RedBaron Mar 28 '13 at 05:00
  • You may also look at http://stackoverflow.com/questions/4206000/django-apache-mod-wsgi-having-to-restart-apache-after-changes for pointers – RedBaron Mar 28 '13 at 05:01
  • Actually you can run mod_wsgi in daemon mode and it will automatically restart the app (not Apache) if the .wsgi script changes. See http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide#Delegation_To_Daemon_Process – RedBaron Mar 28 '13 at 05:09
  • added in more information regarding the errors I've encountered upon deploying to a production site. – Gino Apr 08 '13 at 05:31
  • thanks, just a quick question, where do you save your pyramid.conf at and do I need a .htaccess? – Gino Apr 08 '13 at 06:35
  • I use CentOS, so http conf is at /etc/httpd/conf/httpd.conf and rest of the configs are in /etc/httpd/conf.d/. Within the httpd.conf I have a line `Include conf.d/*.conf` – RedBaron Apr 08 '13 at 08:04
  • I've added some of the errors encountered after following your steps. – Gino Apr 08 '13 at 08:25
  • @Gino Can you manually run the python environment (using `activate`)and see the results of `import os`? – RedBaron Apr 08 '13 at 08:41
  • ok, you might need to guide me step by step on how to see the results of import os. I know the command for activate is source bin/activate, what should be the command for the next step? – Gino Apr 08 '13 at 08:59
  • @Gino Just run `python` after running `activate` to get the python interpreter. There you can do `import os` – RedBaron Apr 08 '13 at 09:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/27761/discussion-between-redbaron-and-gino) – RedBaron Apr 08 '13 at 10:53