Run Pyramid on Shared Hosting

Pyramid deployment on Shared Hosting

1. Install Pythona 2.7.6 to $HOME/bin location:

cd $HOME && mkdir bin && cd bin wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz 

tar -xzf Python-2.7.6.tgz

cd Python-2.7.6

./configure --prefix=$HOME

make install

--

2. Install Setuptools, PIP and virtualenv:

cd $HOME/bin

wget https://bootstrap.pypa.io/ez_setup.py -O - | ./python

./easy_install pip

./easy_install virtualenv

--

3. Create new virtual environment:

cd $HOME

mkdir YOUR_APP_NAME 

./bin/virtualenv -p ./bin/python --no-site-packages ./YOUR_APP_NAME 

cd ./YOUR_APP_NAME && mkdir src

--

4. Copy your application files to location: $HOME/YOUR_APP_NAME/src/

--

5. Run setup.py develop:

cd $HOME/YOUR_APP_NAME/src/

../bin/python ./setup.py develop

--

6. Initialize database

cd $HOME/YOUR_APP_NAME/

./bin/python ./src/YOUR_APP_NAME/scripts/initializedb.py ./src/production.ini

--

7. Configure FastCGI

I followed tutorial http://python.vexedlogic.com/2012/05/01/running-pyramid-web-framework-with-fastcgi/

cd $HOME/htdocs

  1. Create htaccess:

    vi ./.htaccess

    AddHandler fcgid-script .fcgi

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ YOUR_APP_NAME.fcgi/$1 [QSA,L]

  2. Create FCGI script:

    vi ./YOUR_APP_NAME.fcgi

    #$HOME/YOUR_APP_NAME/bin/python

    import sys

    from paste.deploy

    import loadapp

    from flup.server.fcgi_fork import WSGIServer

    app = loadapp('config:$HOME/YOUR_APP_NAME/src/production.ini')

    server = WSGIServer(app)

    server.run()

    IMPORTANT: ADD EXECUTE RIGHTS ON  .fcgi file:

    chmod 0755 YOUR_APP_NAME.fcgi

  3. Install FCGI Python server

    $HOME/YOUR_APP_NAME/bin/easy_install flup