一、
安裝Apache2.4:sudo apt-get install apache2
安裝mod_wsgi模塊:sudo apt-get install libapache2-mod-wsgi
安裝Django:
sudo apt-get install python-setuptools sudo apt-get install python-pip
sudo pip install django
進入到/etc/apache2/目錄,主要配置文件爲apache2.conf。
新建一個屬於自己的httpd.conf,在裏面進行相關配置,主要是DocumentRoot路徑。主要有以下幾項:
<VirtualHost *:80> *所有IP的80端口
ServerAdmin [email protected] *郵箱
DocumentRoot /home/ngb/Likunheng/Website_Project/Templates/App *網站根目錄
ErrorLog /home/ngb/Likunheng/Website_Project/Templates/error.log *網站錯誤記錄日誌
LogLevel warn
CustomLog /home/ngb/Likunheng/Website_Project/Templates/access.log combined *網站訪問日誌
ServerSignature On
WSGIScriptAlias / /home/ngb/Likunheng/Website_Project/Model_View/WebSite/wsgi.py *Django項目中的wsgi.py (這是個大坑,2.4沒有module目錄,所以也不用往module加入mod_wsgi.so,而網上的大多數教程都是說把mod_wsgi.so放入module,這類說法針對2.2Apache。)
Alias /static/ /home/ngb/Likunheng/Software_folder/Django-1.6.5/django/contrib/admin/static/ *後臺數據存放路徑
<Directory /home/ngb/Likunheng/Software_folder/Django-1.6.5/django/contrib/admin/static/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
Alias /Templates/ /home/ngb/Likunheng/Website_Project/Templates/App/ *模板存放路徑
<Directory /home/ngb/Likunheng/Website_Project/Templates/App/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
Alias /Website_Project/ /home/ngb/Likunheng/Website_Project/Model_View/WebSite/ *Django項目路徑
<Directory /home/ngb/Likunheng/Website_Project/Model_View/WebSite/>
#Options Indexes FollowSymLinks MultiViews
#AllowOverride None
#Order allow,deny
#Allow from all
Require all granted
</Directory>
</VirtualHost>
在配置apache2.conf中,主要有以下幾項:
ServerName localhost
DirectoryIndex index.html index.htm index.php
AddDefaultCharset GB2312 *字符編碼集
WSGIPythonPath /home/ngb/Likunheng/Website_Project/Model_View/ *Django項目路徑(很重要的一個東西,不加這一行mod_wsgi模塊會找不到你的settings.py)
# Include module configuration:
#IncludeOptional mods-enabled/*.load
#IncludeOptional mods-enabled/*.conf
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
# Include list of ports to listen on
#Include ports.conf
Include /etc/apache2/httpd.conf *自己新建的httpd.conf
Include /etc/apache2/ports.conf
#Include /etc/apache2/sites-enabled/* *註釋掉sites-enabled,使其中的default文件不生效
Include /etc/apache2/conf-enabled/*
至此。恭喜你。完成了LAMP最重要的也是比較難的部分配置。
從此,你可以安心的走上開發和商業之路。
完。