目錄結構
這是它在本地運行,現在我的應用程序的結構:
![enter image description here](https://i.stack.imgur.com/QDb1a.png)
環境
Linux Mint的17肉桂
個步驟要本地複製
01)的MongoDB 2.4.9 - DONE
MongoDB的2.4安裝的指令。9 Linux Mint的17:
http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu
02) RockMongo 1.1(這需要Apache,PHP和MongoDB驅動程序) - DONE
sudo apt-get install apache2 php5
sudo apt-get install php5-dev php5-cli
sudo apt-get install php-pear
pear version
pecl version
sudo pecl install mongo
在這一點上,系統提示我的東西,包括[否],我只是按下Enter鍵。
cd /etc/php5/apache2
sudo vi php.ini
這個添加到文件的末尾:
extension=mongo.so
然後重新啓動:
/etc/init.d/apache2 restart
然後安裝RockMongo:
cd /var/www/html
wget https://github.com/iwind/rockmongo/archive/1.1.7.zip
unzip 1.1.7.zip
mv rockmongo-1.1.7 rockmongo
rm 1.1.7.zip
03)創建乾淨virtualenv
環境並安裝軟件包 - 完成
virtualenv
是一個Python包,可讓您創建包含自己的Python安裝和包的獨立虛擬環境。
通過新立得包管理器安裝virtualenv
。
如何創建
https://code.google.com/p/modwsgi/wiki/VirtualEnvironments
通過的mod_wsgi
筆者,格雷厄姆鄧普爾頓。
爲什麼要創建
http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/
這篇文章是如此輝煌,幾乎讓我想流淚,聲望,榮譽。
命令
執行以下操作之前,請安裝python2.7-dev
,libxml2-dev
,libxslt1-dev
和apache2-dev
通過新立得軟件包管理器來解決錯誤的時候做的點子後安裝。
# change to your html folder
cd /var/www/html
# this will create a folder called ENV that contains its own instance
# of python without inheriting your system's installed python packages.
# it will also install independent instances of pip and setuptools.
# the --no-site-packages option is the default setting in recent versions
# however I added it just to be sure.
virtualenv --no-site-packages ENV
New python executable in ENV/bin/python
Installing setuptools, pip...done.
# you can 'activate' the virtual environment so that each time you use
# pip it automatically installs packages in the virtual environment.
# change to your virtual environment folder
cd /var/www/html/ENV
# activate the virtual environment
source bin/activate
# you can deactivate this by typing 'deactivate` and it is also
# automatically deactivated each time you close the terminal.
deactivate
# from time to time you can save the names of the packages you have
# installed to your virtual environment via pip to a text file with:
pip freeze > requirements.txt
# note, after installing virtualenv as shown above, you will have some
# packages installted by default.
pip freeze
argparse==1.2.1
wsgiref==0.1.2
# requirements.txt would allow installation of all required packages via:
pip install -r requirements.txt
# install packages, whilst virtualenv is activated
pip install bottle
pip install https://github.com/FedericoCeratto/bottle-cork/archive/master.zip
pip install requests
pip install pymongo==2.6.2
pip install beautifulsoup4
pip install lxml
pip install Beaker
pip install pycrypto
pip install pillow
pip install tldextract
04)複製現有應用程序文件到新的位置 - DONE
cp -r path/to/open_shift_apps/my-app/. /var/www/html
05)刪除文件和文件夾,不需要從VAR/www/html等*本地*生產 - DONE
rm -r data
rm -r libs
rm -r .openshift
rm -r .git
rm setup.py
rm setup.pyc
rm setup.pyo
06) mod_wsgi - DONE
通過新立得包管理器。除非mod_wsgi
是安裝在系統級
的Apache不會爲我工作,即當mod_wsgi
被內virtualenv
安裝時,沒有工作。
07)瞭解Apache服務器,mod_wsgi的和應用程序之間的關係 - DONE
阿帕奇
在本地運行一個動態的網站,你需要一臺服務器,在這種情況下,我們使用Apache的。
mod_wsgi的
mod_wsgi
是其延伸的Apache,使得規則可以被添加到它的配置Apache模塊,其指向Python代碼,以便它可以當用戶訪問一個特定的路徑運行。
08)配置Apache規則
/etc/apache2/sites-available/000-default.conf
WSGIPythonHome /var/www/html/ENV
WSGIPythonPath /var/www/html:/var/www/html/ENV/lib/python2.7/site-packages:/var/www/html/wsgi
<VirtualHost *:80>
# for all content in static folder - css, js, img, fonts
Alias /static/ /var/www/html/wsgi/static/
# for rockmongo
Alias /rockmongo /var/www/html/rockmongo
<Directory /var/www/html/rockmongo>
Order deny,allow
Allow from all
</Directory>
ServerAdmin [email protected]
DocumentRoot /var/www/html
WSGIScriptAlias//var/www/html/wsgi/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
當用戶訪問一個特定的路徑,Apache的尋找一個application
包含將運行您的Python程序的代碼的對象。
在這種情況下,該對象位於wsgi/application
,並在用戶轉到localhost
時觸發。
在/ var/www/html等/ WSGI /應用
from mybottleapp import application
09)檢查文件所有權和權限
如果事情不會在過程的任何階段的工作,是一定要看看你的本地文件的權限。沒有正確的權限可能意味着您的應用程序未被導入。從OpenShift
10) mongodump和mongorestore局部
How to mongodump from OpenShift and mongorestore locally on MongoDB 2.4.9?
進一步閱讀
How Python web frameworks, WSGI and CGI fit together
https://docs.python.org/2/howto/webservers.html
http://wsgi.readthedocs.org/en/latest/servers.html
https://code.google.com/p/modwsgi/
https://www.python.org/dev/peps/pep-0333
http://bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi
一個優秀的帖子!現在openshift已經轉移到基於docker的。你是否能夠在新的openshift上做同樣的事情? – minghua 2017-11-30 17:09:18