2013年11月18日 星期一

Ubuntu precise amd64 安裝筆記


# apt-get update & 
sudo apt-get -y update
sudo apt-get dist-upgrade
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev vim

# install python
sudo apt-get install build-essential
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
cd /tmp
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar -xvf Python-2.7.6.tgz
cd Python-2.7.6
./configure
make
sudo make altinstall

# install easy_install for python 2.7
cd ..
sudo apt-get install python-setuptools

# install Flask for python
sudo easy_install Flask

# prepare to install uwsgi, nginx
sudo useradd -r -g www-data -s /bin/false uwsgi
sudo mkdir -p /var/www/myapp
sudo chown uwsgi:www-data /var/www/myapp -R
sudo useradd -G www-data myuser
sudo usermod -a -G www-data myuser

# install uwsgi
sudo pip install uwsgi
sudo mkdir -p /var/log/uwsgi
sudo touch /var/log/uwsgi/myapp.log
cd /var/www/myapp
sudo vi uwsgi.xml
sudo /usr/local/bin/uwsgi -x uwsgi.xml

# install nginx
sudo apt-get install nginx
sudo service nginx start
cd /etc/nginx/
cd sites-enabled/
sudo vi default


uwsgi.xml

<?xml version="1.0"?>
<uwsgi id="myapp">
  <module>application:app</module>
  <socket>/tmp/uwsgi.sock</socket>
  <socket>127.0.0.1:8000</socket>
  <processes>4</processes>
  <chdir>/var/www/myapp</chdir>
  <pidfile>/tmp/myapp.pid</pidfile>
  <daemonize>/var/log/uwsgi/myapp.log</daemonize>
  <stats>/tmp/myapp.stats</stats>
  <log-format>``%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) `` "%(referer)" "%(uagent)"</log-format>
  <uid>uwsgi</uid>
  <gid>www-data</gid>
  <chmod-socket>775</chmod-socket>
</uwsgi>

/etc/nginx/sites-enabled/default

server {
        listen 8080;
        root /var/www/myapp;
        server_name myapp;

        try_files $uri @uwsgi;
        location @uwsgi {
                include uwsgi_params;
                uwsgi_pass unix:/tmp/myapp.sock;
        }
}


沒有留言: