设为首页 收藏本站
查看: 827|回复: 0

[经验分享] bluehost-python升级

[复制链接]
累计签到:1365 天
连续签到:1 天
发表于 2017-4-21 12:31:32 | 显示全部楼层 |阅读模式
  [I suppose the guy who need this will be able to read this article]
  I have a shared host on Bluehost.com, and want to have a lot of python libraries and applications to work on it.
  Since it’s a shared host, I can’t install python libs, while I love ez_setup so much, I can’t live on python world without it.
  Knowing from python-cn group, that I could build and use my own python on it. I should have got this solution earlier, this might be simple and naive for linux users.
  OK, now let’s do it:
  ——————————————–
  1. you must have shell access, please contact the bluehost support for a shell access
  2. my dev box is windows xp, so I use putty, to connect my host 2maomao.com
  3. then use wget to download latest python, unzip it

wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
tar xvzf Python-2.5.2.tgz

  4. this step is critical, you need to replace “twomaom1″ to your own user name below:

cd Python-2.5.2
./configure --prefix=/home/twomaom1/mypython --enable-unicode=ucs4
make
make install

  5. now, let’s use the new python instead of the old one, you need to
a). cd ~
b). use any editor(I use vim), to edit your “.bashrc” file, add the following line at the end of the file

export PATH=/home/twomaom1/mypython/bin/:$PATH
export PYTHONPATH="/home/twomaom1/mypython/lib/python2.5:$PYTHONPATH"

  6. now type “bash” and enter to refresh the shell, type “python -V” to view the python version.
  You should already been successful.
  from now on, easy_install or “python setup.py”, it’s your choice DSC0000.gif
  Oh…don’t forget, in your python script, use the correct python path in the head, like mine:

#!/home/twomaom1/bin/python

  Enjoy it ~!
  0. 安装自己的Python,参见:configure your own python 2.5.2 on bluehost
  1. 安装完以后重启shell(直接敲bash回车或者重连putty)
  2. 下载并安装ez_setup
  3. 我用mysql,所以安装mysql-python: easy_install mysql-python
  4. 安装flup和django:
easy_install flup
下载django包,解压(我放到了/home/twomaom1/django/src目录),按照指令安装
  5、设置子域名,我设置的是code.fayaa.com,网络不熟啊,至今不是很懂,似乎一些apache设置以及django默认配置的问题,搞个子域名比较好办
  6、在该子域名的目录下(我的是:/home/twomaom1/public_html/fayaa/code/),新建.htaccess,内容如下:

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteBase /
#static file setting
RewriteRule ^(static/.*)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ t.fcgi/$1 [QSA,L]


  7. 新建个t.fcgi,改为可执行(chmod +x t.fcgi),内容如下:

#!/home/twomaom1/twomaom1/bin/python
import sys, os
# Add a custom Python path.
sys.path.insert(0, "/home/twomaom1/twomaom1/python")
sys.path.insert(0, "/home/twomaom1/django")
os.chdir("/home/twomaom1/django/code")
os.environ['DJANGO_SETTINGS_MODULE'] = "code.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])


  注意你的python目录以及django目录,django工程目录
  8. 到/home/twomaom1/django目录下,生成一个工程,叫做code(注意,如果你用python manage.py runserver的方式,最好不要用code做工程的名字,会出错的,似乎是个bug),里面的settings.py配置好mysql
  9. 打开浏览器看一下吧,应该差不多了
  静态文件设置我试过django自带的、apache alias和Apache rewrite,在开发时使用这种方法还不错。
bluehost上,我是用的是Apache RewriteRule(见上面的Apache配置),直接把东西放到了t.fcgi所在目录的某个子目录下。
据说Alias也很不错,我试过很多次,每次都是500 Server Internal Error,放弃了
  注意:有时候改了文件,想要重启django server,由于fastcgi的预加载,需要做如下尝试:
1. 改变时间戳:touch t.fcgi文件,或者直接打开后强制保存
2. 如果上述方法无效,则尝试把t.fcgi改名,一会儿再改回来
3. 简单粗暴有效果的方法:
用putty连上,打印并过滤python有关的进程:
ps -ef | grep python
在输出中发现这一行:
twomaom1 16445 1982 0 09:41 ? 00:00:00 /home/twomaom1/twomaom1/bin/python t.fcgi
杀之:
kp 16445
  我喜欢第三种。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-367419-1-1.html 上篇帖子: Python基础 3----Python函数及类 下篇帖子: python难吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表