Git Product home page Git Product logo

wx's Introduction

NOTICE:

This repository is a fork of https://github.com/prelegalwonder/openshift_web2py. I only make this fork with intent of keep the web2py version up-to-date. This fork is tested on python-2.7 cartridge.

Web2Py on OpenShift

This git repository helps you get up and running quickly w/ a web2py installation on OpenShift. The web2py project name used in this repo is 'web2py'

When you access this application for the first time, the sqlite database is initialized from the defined DAL in your model. This is the stock database that is created for the welcome application in web2py.

Running on OpenShift

Create an account at http://openshift.redhat.com/

Create a python-2.7 application

rhc create-app web2py python-2.7 --from-code https://github.com/glaucojunior22/openshift_web2py.git

That's it, you can now checkout your application at:

http://web2py-$yournamespace.rhcloud.com

The default web2py application that loads will be the "welcome" application. You can change this by modifying the routes as you usually would with web2py.

For the admin app to work you must use this password: web2py Remember to change your password later to avoid trouble.

Database Setup

Enabling db cartridges: If you want to use something beyond the sqlite provider that is default for applications, you'll need to install one of Openshift's db cartridges. You can see what's available with the following command.

$> rhc app cartridge

List of supported embedded cartridges:

Obtaining list of cartridges (please excuse the delay)...
mongodb-2.0, cron-1.4, mysql-5.1, postgresql-8.4, haproxy-1.4, 10gen-mms-agent-0.1, phpmyadmin-3.4, metrics-0.1, rockmongo-1.1, jenkins-client-1.4

Once you've identified which db cartridge you'd like to use you can install it with the following command.

$> rhc app cartridge add -c <cartridge_name> -a <your_app>

This will output some info regarding how to connect to your db. You can record this somewhere if you like, however all of this information is available within the gear and you'll see how to access it in the next section.

Connecting to db: Openshift makes using it's available database cartridges very simple by providing a list of various environment variables you can use depending on the connection format you want to use.

Openshift provides two classes of db cartridge; RDBMS and NOSQL. RDBMS uses the environment variable OPENSHIFT_DB_* where NOSQL uses OPENSHIFT_NOSQL_DB_*

MySQL and PostgreSQL are RDBM's style of database, where MongoDB is a NOSQL style database.

So if you wanted to get the host of your mysql environment, you'd use OPENSHIFT_DB_HOST vs OPENSHIFT_NOSQL_DB_HOST for mongodb. You can get a list of available variables by loging into your gear and executing:

openshift_gear$> env | grep DB

Using web2py, the most useful variable will most likely be the URL when defining the DAL in the model. Here's a mongodb example for your model (db.py):

from os import environ as myenv
DB_URL = myenv['OPENSHIFT_NOSQL_DB_URL']+myenv['OPENSHIFT_APP_NAME']

db = DAL(DB_URL)

(Note: If using postgresql, put the following after the DB_URL line and before the db = DAL line. Thanks srochy)
DB_URL = DB_URL.replace("postgresql://", "postgres://")

If you want to view your data directly you can do this via the console tools logged directly into the Openshift gear, or install the cooresponding web management cartridge (ie. rockmongo, phpmyadmin).

For more information on Openshift and how to accomplish various tasks, see: https://access.redhat.com/knowledge/docs/OpenShift/

Now with NewRelic Config

If you want to monitor the performance, user-experience and usage statistics, you can sign up for an account at newrelic.com. After signing up, simply put your license key in wsgi/web2py/newrelic.ini

license_key = <your_license_key_from_your_newrelic_account>

And whatever you want the app labeled as in your newrelic account can be set via the name property. app_name = web2py

If you don't intend to use NewRelic or want to turn it off temporarily, simply comment out everything after #NewRelic Monitoring in the wsgi/application file.

#NewRelic Monitoring
import newrelic.agent
newrelic.agent.initialize(NEWRELIC_INI)

application = newrelic.agent.wsgi_application()(application)

wx's People

Contributors

prelegalwonder avatar glaucojunior22 avatar sunlifeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.