2014-11-23 22 views
2

這開始是一個問題,但我想我已經找出了大部分的部分,所以我把它張貼在這裏供參考。它相對涉及,但我認爲這對其他人考慮這種情況可能有用。如何在Linux Mint 17本地複製Python 2.7,Bottle,MongoDB OpenShift應用程序?

我是其中一些領域的新手,所以如果在Apache或其他不良做法中出現安全問題時出錯,請更正。

另請注意,按照以下步驟生成的本地開發版本不再通過它與生產代碼之間的更改啓用git。所以我會將本地git回購保存在另一個位置。

期望的行爲

方案一:
複製我當前的Python 2.7,瓶,MongoDB的OpenShift應用程序在本地,加快開發時間(GIT期間推等)。

方案二(如果顯著更容易):
複製我當前的Python 2.7,瓶,MongoDB的Openshift應用程序在本地*未經OpenShift平臺*加快開發時間。

當前行爲

我有一個Python 2.7,瓶,MongoDB的上OpenShift應用。

我現在的工作流程是:

  • 編輯本地。
  • 混帳添加--all
  • git的承諾-m 「這裏是一個消息」
  • 混帳推主產地(這將更新上openshift直播網站)
  • 混帳推github上主(這將更新GitHub庫)

很顯然,由於每次推送需要花費的時間才能看到結果,因此這並不理想。

+0

一個優秀的帖子!現在openshift已經轉移到基於docker的。你是否能夠在新的openshift上做同樣的事情? – minghua 2017-11-30 17:09:18

回答

1

目錄結構

這是它在本地運行,現在我的應用程序的結構:

enter image description here

環境

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-devlibxml2-devlibxslt1-devapache2-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

相關問題