目錄表
Install Zerobin on a Python Simple Hosting instance
Introduction
Zerobin (also written as 0bin) is free software (WTF license) developed in Python and uses no database. This is the description given by the developers of the project :
“0bin allows anybody to host a pastebin while welcoming any type of content to be pasted in it. The idea is that one can (probably…) not be legally entitled to moderate the pastebin content as they have no way to decrypt it.
It’s an Python implementation of the zerobin project, and is easy to install even if you know nothing about the language.”
We recommend reading this page for more information :
https://github.com/sametmax/0bin/blob/master/docs/en/intro.rst
Step 1 - Create the instance
First, we will create the instance using the Gandi CLI : http://cli.gandi.net
$ gandi paas create --name zerobin --type pythonmongodb password: Repeat for confirmation: Creating your PaaS instance.
Step 2 - Configure the application
Here we will clone the git repository locally, which will create a directory named “default” in which we must place our application :
$ gandi paas clone zerobin
Then we will navigate into the “default” directory and create the files needed to run the application :
$ cd default $ touch requirements.txt $ touch wsgi.py
Next, we will add the dependency “zerobin” in the requirements.txt
file :
$ echo "zerobin" > requirements.txt
Then we will download the zerobin application content located on the official Github repository :
$ git clone https://github.com/sametmax/0bin.git
We must then move the application (which is a Django application) to the root directory “default” :
$ cp -r 0bin/zerobin .
Now we will add a file .gitignore
, and add the directory '0bin' to the file to prevent the directory from being pushed to the repository as it's not needed :
$ touch .gitignore $ echo "0bin" > .gitignore
You should now have the following file structure :
$ tree -La 2 . ├── 0bin │ ├── compress.sh │ ├── docs │ ├── .editorconfig │ ├── .git │ ├── .gitignore │ ├── libs │ ├── README.rst │ ├── screenshot.png │ ├── setup.py │ ├── tools │ └── zerobin.py ├── .gandi.config.yaml ├── .git │ ├── branches │ ├── COMMIT_EDITMSG │ ├── config │ ├── description │ ├── FETCH_HEAD │ ├── HEAD │ ├── hooks │ ├── index │ ├── info │ ├── logs │ ├── objects │ └── refs ├── .gitignore ├── requirements.txt ├── wsgi.py └── zerobin ├── default_settings.py ├── __init__.py ├── paste.py ├── privilege.py ├── routes.py ├── static ├── utils.py └── views
Static files (images, javascript, CSS files) must be placed in a folder called 'static' at the root of our Python instance. In our case, the application already has a directory where the static files are located in 'zerobin/static'. We will create a simple symbolic link to this directory to simplify future updates :
$ ln -s zerobin/static static
Step 3 - Writing the wsgi.py file
Apache is used with mod_wsgi to serve pages. We will fill in the wsgi.py
file following the application documentation :
$ nano wsgi.py
import os, sys # make sure the zerobin module is in the PYTHON PATH and importable ZEROBIN_PARENT_DIR = os.path.dirname(os.path.dirname(__file__)) sys.path.insert(0, ZEROBIN_PARENT_DIR) # create the wsgi callable from zerobin.routes import get_app settings, application = get_app(compressed_static=True)
Step 4 - Customize the application
Make any edits you wish to the application. For example :
- replacing images with your own custom images,
- or altering displayed text in the zerobin/views/base.tpl file
Step 5 - Deploy the application to the instance
All we need to do now is push the application via git and deploy :
$ git add . $ git commit -am 'First install of Zerobin' $ git push origin master $ gandi deploy
Once done, your application should be available at the address you assigned to your Simple Hosting instance.