Development Debian Wheezy on Amazon EC2


Here is complete guide to setup debian wheezy server in Amazon EC2. Remember to login using “admin” user, since “root” is not allowed by default.

1. Install software
Add backports on “/etc/apt/sources.list :

1
deb http://ftp.debian.org/debian/ wheezy-backports main
1
2
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install nmap vim bind9 mysql-server mysql-client apache2  php5 php-pear php5-mysql python-software-properties python g++ make python-dev nginx php5-common phpmyadmin apache2 zip unzip unrar-free imagemagick rsync python-pip dnsutils libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full unzip unace unp bzip2 gzip patch htop rsync php5 php5-fpm php-pear php5-common php5-mcrypt php5-mysql php5-cli php5-gd python-mysqldb libapache2-mod-wsgi haproxy libmysqlclient-dev redis-server git

2. Enabled haproxy
by edit “/etc/default/haproxy” and “ENABLED = 1”

Example haproxy configuration :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /usr/share/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

frontend public
    bind *:80
    option forwardfor       except 127.0.0.0/8
    default_backend nginx

    acl is_pongmobnode_backend hdr_end(host) -i socket.pongmob.com
    use_backend pongmobnode_frontend if is_pongmobnode_backend
   
#nginx
backend nginx
    option forwardfor       except 127.0.0.0/8
    balance roundrobin
    server nginx 127.0.0.1:87 weight 8 maxconn 1024 check  

backend pongmobnode_frontend
    timeout server 8000s
    timeout connect 10s
    server server1 127.0.0.1:4005 weight 1 maxconn 1024 check

3. PHP FPM
Change PHP5-FPM listen into socket in “/etc/php5/fpm/pool.d/www.conf”:

1
listen = /var/run/php5-fpm.sock

4. Install NodeJS

1
2
3
4
5
6
sudo apt-get update && sudo apt-get install git-core curl build-essential openssl libssl-dev checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v*
 ./configure –openssl-libpath=/usr/lib/ssl
checkinstall #(remove the "v" in front of the version number in the dialog)

5. Install Django Development

1
2
sudo pip install virtualenv
sudo pip install virtualenvwrapper

Now, we need to add this into “~/.bash_profile” :

1
2
3
4
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME # Tell pip to create its virtualenvs in $WORKON_HOME.
export PIP_RESPECT_VIRTUALENV=true # Tell pip to automatically use the currently active virtualenv

Then, we are ready to create new virtualenv :

1
mkvirtualenv –no-site-packages –distribute django

Here is example NGINX configuration for Django

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
    listen 82;
    server_name pongmob.com;
    rewrite ^ http://www.pongmob.com$request_uri? permanent;
}

server {
    listen 82;
    server_name www.pongmob.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/yodi/pongmob;

    client_body_timeout  460;
    client_header_timeout 460;
    send_timeout 460;
    client_max_body_size 10m;
    keepalive_timeout 300;

    index  index.php index.html index.htm;

    # Check if a file exists at /var/www/domain/ for the incoming request.
    # If it doesn’t proxy to Apache/Django.
    try_files $uri @django;
       
    # Setup named location for Django requests and handle proxy details
    location @django {
            proxy_pass         http://localhost:8010;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

}

And this is for Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<VirtualHost *:8010>
    ServerName pongmob.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/yodi/pongmob

    WSGIScriptAlias / /var/yodi/pongmob/mobilegame/wsgi.py

    <Directory /var/yodi/pongmob/>
        <Files wsgi.py>
        Order deny,allow
        Allow from all
        </Files>
    </Directory>

    # Django settings
    WSGIDaemonProcess pongmob user=www-data group=www-data processes=1 threads=10 python-path=/root/.virtualenvs/django/lib/python2.7/site-packages/
    WSGIProcessGroup pongmob

    # Non-Django directories
    Alias /static/ /var/yodi/pongmob/static/
    Alias /media/ /var/yodi/pongmob/media/

    <Directory /var/yodi/pongmob/static/>
        Allow from all
    </Directory>

    <Directory /var/yodi/pongmob/media/>
        Order deny,allow
        Allow from all
    </Directory>

    Alias /robots.txt /var/yodi/pongmob/robots.txt
    Alias /favicon.ico /var/yodi/pongmob/static/favicon.ico

    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

Install LXML Dependencies

1
2
sudo apt-get install python-dev libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full rar  unrar unzip unace unp bzip2 gzip patch
pip install lxml

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.