Showing posts with label openshift. Show all posts
Showing posts with label openshift. Show all posts

Tuesday, June 26, 2012

setup a local envrionment for openshift wsgi app

We do want a local development environment for debugging, etc. As my previous posts, we are using Python2.6 Django WSGI as backend for our mobile app, so, it's pretty easy to setup a local environment, actually, it's just a WSGI deployment.

But, since openshift gear using many environment variables, so the key steps here are copy those env vars to your local box, and export them. The another thing that matters a lot is Database setup, with help of Django Framework, i just need to create a database with the same name as it is in openshift, and then run syncdb.

The issue bit me was Selinux settings, so you may need pay some attentions to it. If you have an admin beside you, drop these setup stuff to him, :).


http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6

https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/

Tuesday, June 19, 2012

redirect http to https for your openshift application

Want to use HTTPS for you openshift application? Yes, our application as mobile app's backend definitely needs this feature, I though there should be some other additional complex, obscure steps to enable HTTPS. But actually, it's very easy, just add .htaccess file in your wsgi directory(I'm using python, django application, you should do this according to your specific requirement).

here is the content for redirecting HTTP to HTTPS:

RewriteEngine on

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST} [R,L] 

Now, all your requests will be porting to HTTPS, if you have some cookies in your browser, you should clear those insecure cookies, otherwise you may can not login.

Monday, June 18, 2012

howto create a django application in openshift(wsgi related)

we are using openshift as our mobile app's backend since we don't have much resource and money to buy a server for hosting this backend site. It's a great Pass platform for developers saving much headaches. Every account has one domain associated, we can create 3 apps under it, e.g. you create a domain map, and then create a app social, the application's full URL will be social-map.rhcloud.com. You can check its features in http://openshift.redhat.com .

Django is our backend web framework, and there's a quick start example in github(github.com/openshift/django-example), you can just clone this repo, and push it to your repo, then openshift will deploy it for you.

But we decided to do it ourselves(why we need those unrelated dirs, codes, it's really annoying), it's very easy. Here are some steps:
1, clone your app repo into local working directory, when you create an app, openshift will create a git repo for you, and you can add other remote repos, and push/pull from there, it's up to you.
2, edit setup.py, add 'Django>=1.3' into install_requires
3, use django-admin.py creating a new project under your working directory, there will be one wsgi file generated, after step 4, you can delete this
4, edit wsgi/application file, you can setup environment vars there, the important thing is help it finding your site's setting.py
 5, ok, you have done the setup stuff, now you can continue your coding, and then push it to openshift


ps, our directory structure:
  .
|-- data
|-- libs
|-- socialmap   (this is our django project)
|   |-- accounts
|   |   `-- avatars
|   `-- templates
`-- wsgi      (wsgi file application mentioned in step4 is in this directory)
    `-- static
        `-- admin
            |-- css
            |-- img
            |   `-- gis
            `-- js
                `-- admin