Run the following command
$ update-locale LC_ALL="en_US.UTF-8"
If it failed, you will need to add the following to /var/lib/locales/supported.d/local file
en_US.UTF-8 UTF-8
Then run
$ locale-gen
Update aptitude
$ apt-get update
$ apt-get upgrade
Install necessary packages
$ apt-get install build-essential
Install Python
$ apt-get install python2.7-dev python-setuptools
$ easy_install pip
Install git
$ apt-get install git-core
Generate a new SSH key
$ ssh-keygen -t rsa -C "[email protected]"
Then add the key from ~/.ssh/id_rsa.pub to GitHub
Test the key by
$ ssh -T [email protected]
Install virtualenv
$ pip install virtualenv
- I will not use virtualenvwrapper because I want to isolate everything about the website under one directory (in this case, Python libraries).
Install Postgresql Server and Python library
$ apt-get install postgresql python-psycopg2 libpq-dev
Create a new database and database's user
$ sudo -u postgres createdb [database_name]
$ sudo -u postgres createuser -SDRP [database_user_name]
Config pg_hba.conf file (you may need to change version number)
$ sudo vim /etc/postgresql/9.1/main/pg_hba.conf
Then add the following to pg_hba.conf file let database user authenticated using password
local [database_name] [database_user_name] md5
Reload Postgresql server
$ /etc/init.d/postgresql reload
Setup aptitude
$ apt-get install python-software-properties software-properties-common
$ add-apt-repository ppa:nginx/stable
Install nginx
$ apt-get install nginx-full
Install PCRE library (necessary for rewrite module)
$ apt-get install libpcre3-dev
Install uWSGI
$ apt-get install uwsgi uwsgi-plugin-python
Example website is example.com
Create folders
$ mkdir -p /web/example.com/
$ cd /web/example.com/
$ mkdir logs public_html source
$ cd /web/example.com/source/
$ git clone [email protected]:[username]/[repository].git
Set owner to www-data
$ chown -R www-data:www-data /web
$ cd /web
$ virtualenv example.com
$ cd /etc/nginx/sites-available
$ vim example.com
Add the following configuration to the file
server {
listen 80;
server_name $hostname;
access_log /web/example.com/logs/access.log;
error_log /web/example.com/logs/error.log;
location / {
uwsgi_pass unix:///run/uwsgi/app/example.com/example.com.socket;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
}
location /static {
root /web/example.com/public_html/static/;
}
}
Then create a symlink
$ ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
Then you may need to delete default site
$ rm /etc/nginx/sites-enabled/default
$ vim /etc/uwsgi/apps-available/example.com.xml
Add the following configuration to the file
<uwsgi>
<plugin>python</plugin>
<vhost/>
<socket>/run/uwsgi/app/example.com/example.com.socket</socket>
<pythonpath>/web/example.com/source/example/</pythonpath>
<wsgi-file>/web/example.com/source/example/example/wsgi.py</wsgi-file>
<virtualenv>/web/example.com</virtualenv>
<logto>/web/example.com/logs/example.com.log</logto>
<master/>
<processes>4</processes>
<harakiri>60</harakiri>
<reload-mercy>8</reload-mercy>
<cpu-affinity>1</cpu-affinity>
<stats>/tmp/stats.socket</stats>
<max-requests>2000</max-requests>
<limit-as>512</limit-as>
<reload-on-as>256</reload-on-as>
<reload-on-rss>192</reload-on-rss>
<no-orphans/>
<vacuum/>
</uwsgi>
Then create a symlink
$ ln -s /etc/uwsgi/apps-available/example.com.xml /etc/uwsgi/apps-enabled/example.com.xml
$ service uwsgi restart
$ service nginx restart
Install dependencies
$ apt-get install libjpeg62-dev zlib1g-dev libfreetype6-dev liblcms1-dev
Install Pillow
$ pip install Pillow