Dreamhost是小型项目的理想主机。而且它也是Django友好的托管。除python和Django版本外,其他所有功能都过时了。好吧,这是一整天的工作,要弄清楚如何在dreamhost上更新Python 2.7.3,Django 1.4,我真的想与任何发现它的人分享
我目前有私人服务器,一个外壳帐户和一点运气。所以这是我的工作:
SSH到您的主机以升级python
cd ~
mkdir tmp cd tmp wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar zxvf Python-2.7.3.tgz cd Python-2.7.3 ./configure –enable-shared –prefix=$HOME/Python27 –enable-unicode=ucs4 make make install
配置系统以使用我们的新Python。打开〜/ .bashrc并添加以下行
export PATH="$HOME/Python27/bin:$PATH"
export LD_LIBRARY_PATH=$HOME/Python27/lib
#save it and run source ~/.bashrc
您现在可以使用检查您的python版本 which python
which python
安装easy_install,pip
easy_install
pip
cd ~/tmp
wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py easy_install pip
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
安装 virtualenv
virtualenv
pip install virtualenv
virtualenv $HOME//env #Switch to virtualenv source $HOME//env/bin/activate
您还可以将env路径添加到 bashrc
bashrc
export PATH="$HOME/<site>/env/bin/:$PATH" source ~/.bashrc
安装Django和其他所有东西
pip install django
pip install .... pip install .... pip install ....
建立专案
cd $HOME/<site>/
python $HOME//env/bin/django-admin.py startproject project
创建passenger_wsgi.py于HOME/<site>/与下列内容
passenger_wsgi.py
HOME/<site>/
import sys, os
cwd = os.getcwd() sys.path.append(cwd) sys.path.append(cwd + ‘/project’) #You must add your project here or 500
#Switch to new python #You may try to replace $HOME with your actual path if sys.version < “2.7.3”: os.execl(“$HOME//env/bin/python”, “python2.7.3”, *sys.argv)
sys.path.insert(0,’$HOME//env/bin’) sys.path.insert(0,’$HOME//env/lib/python2.7/site-packages/django’) sys.path.insert(0,’$HOME//env/lib/python2.7/site-packages’)
os.environ[‘DJANGO_SETTINGS_MODULE’] = “project.settings” import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
或者这样
import sys, os BASE_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(BASE_DIR)) #You must add your project here or 500 #Switch to new python #You may try to replace $HOME with your actual path PYTHON_PATH = os.path.join(BASE_DIR, 'env', 'bin', 'python') if sys.executable != PYTHON_PATH: os.execl(PYTHON_PATH, "python2.7.12", *sys.argv)
如果您使用的是django 1.7,请将最后两行替换为
from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
Dreamhost上的新版本python将不再返回,sys.executable因此您这是我的passenger_wsgi版本
sys.executable
import sys, os VIRTUAL_ENV_PYTHON = 'venv-python' # Python > 2.7.6 dreamhost not return sys.executable BASE_DIR = os.path.dirname(os.path.abspath(__file__)) def is_venv_python(): if len(sys.argv) > 0: last_item = sys.argv[len(sys.argv)-1] if last_item == VIRTUAL_ENV_PYTHON: return True return False sys.path.append(os.path.join(BASE_DIR)) #You must add your project here or 500 #Switch to new python PYTHON_PATH = os.path.join(BASE_DIR, 'env', 'bin', 'python') if not is_venv_python(): os.execl(PYTHON_PATH, "python2.7.12", *sys.argv + [VIRTUAL_ENV_PYTHON]) sys.path.insert(0, os.path.join(BASE_DIR, 'env', 'bin')) sys.path.insert(0, os.path.join( BASE_DIR, 'env', 'lib', 'python2.7', 'site-packages' ))