这篇文章要介绍在Ubuntu上面如何从零开始配置Django和Apache. 要说明的一点是我这里使用的是python3. 下一篇文章将介绍如何连接Django和MySQL.
Install pip
1 |
|
Install virtualenv
1 |
|
To exit the virtual env:
1 |
|
Install Apache
1 |
|
Some useful comments to restart apache service:
1 |
|
Install mod_wsgi
1 |
|
Install Django
Under the virtual env:
1 |
|
Create your first Django project and config it
1 |
|
Go to mysite/settings.py
. Add your host ip to ALLOWED_HOSTS
and add STATIC_ROOT
:
1 |
|
Apache Config
If you want to config the mod_wsgi as embedded mode
Go to Apache config. For Ubuntu the file path is /etc/apache2/apache2.conf
. For other systems, please check Apache website. Add following config into the file:
1 |
|
If you want to config the mod_wsgi as deamon mode
Add a new Apache VirtualHost config file (you can also modify the exsiting default file). For Ubuntu the file path is under /etc/apache2/sites-available
. For other systems, please check Apache website:
1 |
|
Then you can add following config into the file:
1 |
|
Then disable the default VirtualHost config and enable your new added.
1 |
|
Check your website
Then go to your browser to visit http://35.232.xxx.xxx:80
. You will find your config works. :D
Check you admin page
If you went you http://35.232.xxx.xxx:80/admin
and find out that your admin page does not serve css file. Please run cmd below. This cmd will copy all your admin static files to the STATIC_ROOT
directory which you configured above.
1 |
|