想在自己的Ubuntu Server虚拟机上搭建一个LAMP玩玩,P用Python,使用Django和PostgreSQL,在网上搜了半天,大部分文章都是很粗略,因此自己整理一个Step By Step,作为备忘
Install Django
wget https://www.djangoproject.com/download/1.5.1/tarball/
tar xzvf index.html
sudo python setup.py install
Install WSGI
sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
打开浏览器访问http://<your machine ip>/ 如果你可以看到Apache2的欢迎网页,那就代表成功了
sudo aptitude install libapache2-mod-wsgi
sudo service apache2 restart
Install Postgresql
sudo apt-get install postgresql
安装完成后,需要设置默认用户 postgres的密码,并且创建一个数据库,后面会用到。这些命令适用于Ubuntu12.04上的Postgres9.1。
输入一下命令,进入Postgresql的界面更改密码
sudo -u postgres psql
在界面下输入下面的命令然后输入新密码
\password
Then we connect as 'postgres'. The -h localhost part is important: it tells the psql client that we wish to connect using a TCP connection (which is configured to use password authentication), and not by a PEER connection (which does not care about the password).
psql -U postgres -h localhost
I really wish they'd document all this in a more newcomer friendly fashion, instead of requiring a mandatory Google search and frustration.
login to the sample db to check your credential
psql -h localhost -U postgres -d mydb
Create first Django site
在这里,我跟着Django网站的教程,一步一步的完成,暂时不重复这个过程了,可以在下面的链接找到内容。回头会整理一下比较重要的命令放在这里
https://docs.djangoproject.com/en/1.5/intro/tutorial01/
Please take below as reference if you can't execute "python manage.py syncdb"
input \dt to check table list
Reference
下面是我设置的时候参考的一些比较有用的页面
https://help.ubuntu.com/community/PostgreSQL
https://www.digitalocean.com/community/articles/installing-django-on-ubuntu-12-04--4
https://www.digitalocean.com/community/articles/installing-mod_wsgi-on-ubuntu-12-04
https://docs.djangoproject.com/en/1.5/intro/tutorial01/