1、apache24的安装这里就不赘述了
参考上一篇博文http://blog.csdn.net/sccs999/article/details/49247747
2、django安装也不赘述了,用
pip install django==1.8.2
3、首先描述一下自己的环境
cat /etc/issue
Ubuntu 14.04.2 LTS
django 1.8.2
python 2.7.6
apache 2.4.17 (released 2015-10-13)
apache下载地址: http://httpd.apache.org/download.cgi
apr 1.5.2
apr-util 1.5.4
apr and apr-util下载地址: http://apr.apache.org/
pcre 8.37
pcre 下载地址:http://www.pcre.org/
mod_wsgi 4.4.19
mod_wsgi的下载地址: https://pypi.python.org/pypi/mod_wsgi
4、安装mod_wsgi
这个是下载源码自行编译的安装方式,相较于直接apt-get更灵活一点
tar -zxvf mod_wsgi-4.4.19
sudo ./configure --with-apxs=/home/wsc/apache24/bin/apxs --with-python=/usr/bin/python
sudo make
sudo make install
出错了的话,一般是因为 python-dev的库没装好吧
apt-get install python2.7-dev
需要确认一下 apache/modules 里面是否存在 mod_wsgi.so
ls /home/wsc/apache24/modules | grep mod_wsgi.so
并且要把 mod_wsgi.so的权限更改为755
sudo chmod 755 /home/wsc/apache24/modules/mod_wsgi.so
5、修改文件 /conf/httpd.conf
确认路径是否正确
ServerRoot "/home/wsc/apache24"
ServerAdmin example@example.com
ServerName www.example.com:80
增加需要监听的端口
Listen 80
Listen 8000
Listen 8001
打开注释,引入虚拟主机的配置文件
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
注释掉
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory />
AllowOverride none
#Require all denied
</Directory>
LoadModule wsgi_module modules/mod_wsgi.so
6、修改/conf/extra/httpd-vhosts.conf
<VirtualHost *:8000>
ServerAdmin 549917764@qq.com
DocumentRoot "/home/wsc/example"
ServerName example.com
WSGIScriptAlias / "/home/wsc/example/example/wsgi.py"
ErrorLog "/var/log/apache/dummy-host.example-error.log"
CustomLog "/var/log/apache/dummy-host.example-access.log" common
#配置主目录权限
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/home/wsc/example">
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
7、运行apache
sudo service apache2 start 或者 sudo apachectl start
访问页面 看是否成功,出错了就看 日志
停止
sudo service apache2 stop 或者 sudo apachectl stop
重启
sudo service apache2 restart 或者 sudo apachectl restart