環境
- ubuntu:18.04
- Apache:2.4.29
- Python:3.6.6
- Django:2.1.3
Python
系統自帶Python2.7.15rc以及Python3.6.6
安裝Apache
sudo apt install apache2
sudo apt install libapache2-mod-wsgi-py3
安裝Django
體驗Django2,就必須要求是Python3,所以下面都是基於Python3
安裝pip
sudo apt install python3-pip
安裝Django2
sudo pip3 install django
這裡一定要使用
sudo
,否則,Apache無法import django
修改Apache
檔案路勁: /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin example@126.com
#Alias /media/ /home/blog/media/
#Alias /static/ /home/blog/static/
#<Directory /home/blog/media>
# Require all granted
#</Directory>
#<Directory /home/blog/static>
# Require all granted
#</Directory>
WSGIScriptAlias / /home/blog/blog/wsgi.py
<Directory /home/blog/geek>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
重啟Apache
sudo service apache2 restart