apache部署Django項目【CentOS】---2

來源:互聯網
上載者:User

標籤:安裝路徑   toc   重啟   class   ott   bsp   boa   pre   details   

【注】以下內容皆為轉載

CentOS6.5 內建的Python版本是2.6的,已升級為2.7.6.

假設Django網站myweb2的目錄在/usr/local/上  (我之前放在使用者檔案夾中,結果一直出錯)

1、安裝Apache

先卸載內建的httpd

rpm -e httpd --nodeps

在網上下載四個檔案

1、apr-1.4.6.tar.gz

2、apr-util-1.5.1.tar.gz

3、pcre-8.32.tar.gz

4、httpd-2.4.3.tar.gz


http://pan.baidu.com/share/link?shareid=169366&uk=1829018343

分別安裝這四個包

apr-1.4.6.tar.gz
tar xzf apr-1.4.6.tar.gz---------------------------------解壓
./configure –prefix=/usr/local/apr--------------------安裝路徑

make && make install----------------------------------編譯&安裝


apr-util-1.5.1.tar.gz
tar xzf apr-util-1.5.1.tar.gz
.configure –with-apr=/usr/local/apr

make && make install

prce
tar xzf pcre-8.32.tar.gz
./configure –prefix=/usr/local/prce
make && make install

apache
tar xzf httpd-2.4.3.tar.gz
./configure -prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-pcre=/usr/local/pcre/

make && make install

檢查一下apache是否正確安裝
/usr/local/apache/bin/apachectl start
然後登入127.0.0.1


2 安裝mod_wsgi

:http://pan.baidu.com/s/1sjM3uY5

解壓

tar zxvf mod_wsgi-4.2.5.tar.gz -C /usr/local/src/  (最好一個選項都不要改,我改過,結果解壓失敗了)

cd /usr/local/src/mod_wsgi-4.2.5

 ./configure --with-apxs=/usr/local/apache/bin/apxs     --with-python=/usr//bin/python  (指定Python的路徑,因為我沒有重裝Python,所以用的是預設Python路徑)

make && make install


3 配置apache

(假設Django網站myweb2的目錄在/usr/local/上)

在/usr/local/apache/conf/httpd.conf檔案中找到Directory段落,添加:
<Directory "/usr/local/myweb2/">   
    Order deny,allow
    Allow from all
 Require all granted
</Directory>
WSGIScriptAlias / "/usr/local/myweb2/myweb2/wsgi.py"
其中wsgi.py的檔案內容如下:

[python] view plain copy
  1. import os,sys  
  2. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb2.settings")  
  3. sys.path.append(r‘/usr/local/myweb2/‘)  
  4. from django.core.wsgi import get_wsgi_application  
  5. application = get_wsgi_application()  
注意sys.path.append(r‘/usr/local/myweb2‘)這句,千萬不要漏掉

最後再重啟apache

/usr/local/apache/bin/apachectl stop

/usr/local/apache/bin/apachectl start

登入127.0.0.1,看到

 

卸載apache

如果要卸載,則執行如下的命令:
cd /usr/local/httpd-2.2.16

makeuninstall 

apache部署Django項目【CentOS】---2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.