Ubuntu

Fix SSL not working on mobile browser RapidSSL

1 Nov , 2016  

To solve this, we need to make sure our installation of SSL is correct. Please check your current website via https://cryptoreport.rapidssl.com/checker/views/certCheck.jsp.

It will show you the missing SSL Certificate. Please download it into your server. The next step will be:

1. go to /etc/ssl
2. move your current domain.crt into another file
3. then concatenate your existing domain.crt (renamed) with intermediate key into new domain.crt

1
cat existing-domain.crt intermediate.pem > domain.crt

Please double check again with SSL certification checker

Ubuntu

Install Zurmo CRM in Ubuntu 16.04 Xenial Xerus

14 Oct , 2016  

Here are step to install Zurmo CRM into Ubuntu 16.04 Xenial Xerus.
Since Ubuntu 16.04 doesn’t have php5, we would like to install PHP5

1
2
3
4
sudo apt-get install software-properties-common
sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

1. Install php5.6

1
sudo apt-get install php5.6-dev php5.6-mysql php5.6-gd php5.6-imap php5.6-mcrypt php5.6-fpm  php5.6-mbstring php5.6-curl php5.6-xml

2. Now we need to switch from php7 to php5.6 by:

1
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart ; echo 1 | sudo update-alternatives --config php

3. Change listener in “/etc/php/5.6/fpm/pool.d/www.conf”, take a look on listen and change

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

4. Setup Zurmo NGINX sites-enabled 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
server {
    listen       80;
    server_name  zurmo.yodiaditya.com;
    root         /var/zurmo;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ ^/(protected|framework|themes/\w+/views) { deny all; }
    location ~ /\. { deny all; access_log off; log_not_found off; }
    location = /favicon.ico { log_not_found off; access_log off; }
    location ~ \.(js|css|png|jpg|gif|ico|pdf|zip|rar)$ {
        try_files $uri =404;
    }

    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_send_timeout 3800;
        fastcgi_read_timeout 3800;
        fastcgi_connect_timeout 2800;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

5. Change Mysql Configuration at “/etc/mysql/mysql.conf.d/mysqld.cnf” :

1
2
3
4
5
6
7
character-set-server=utf8
collation-server=utf8_unicode_ci
default-storage-engine=INNODB
max_sp_recursion_depth=100
max_allowed_packet = 20M
thread_stack = 512K
optimizer-search-depth = 0

6. Now restart the services

1
2
sudo service php5.6-fpm restart
sudo service nginx restart

Ubuntu

Setup Django + WordPress Ubuntu 16.04 Xenial Xerus

14 Oct , 2016  

Here is guide to setup Ubuntu 16.04 Xenial Xerus for Django and WordPress Development. First, we need to install dependencies software.

1. Install dependencies software Python, NGINX, PosgreSQL, MySQL and PHP5

1
sudo apt-get install libpq-dev python-dev python-software-properties postgresql postgresql-contrib nginx git zip unzip build-essential python nmap libxslt1-dev python-pip imagemagick uwsgi uwsgi-plugin-python nmap mysql-server phpmyadmin libffi-dev libmysqlclient-dev libmysqlclient-dev libmysqlclient-dev libjpeg-dev language-pack-id php5-fpm php5-mysql software-properties-common

2. Re-configure locale

1
sudo dpkg-reconfigure locales

3. Create bash_prompt.sh in your home directory

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# DESCRIPTION:
#
#   Set the bash prompt according to:
#    * the active virtualenv
#    * the branch/status of the current git repository
#    * the return value of the previous command
#    * the fact you just came from Windows and are used to having newlines in
#      your prompts.
#
# USAGE:
#
#   1. Save this file as ~/.bash_prompt
#   2. Add the following line to the end of your ~/.bashrc or ~/.bash_profile:
#        . ~/.bash_prompt
#
# LINEAGE:
#
#   Based on work by woods
#
#   https://gist.github.com/31967

# The various escape codes that we can use to color our prompt.
        RED="\[\033[0;31m\]"
     YELLOW="\[\033[1;33m\]"
      GREEN="\[\033[0;32m\]"
       BLUE="\[\033[1;34m\]"
  LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
      WHITE="\[\033[1;37m\]"
 LIGHT_GRAY="\[\033[0;37m\]"
 COLOR_NONE="\[\e[0m\]"

# Detect whether the current directory is a git repository.
function is_git_repository {
  git branch > /dev/null 2>&1
}

# Determine the branch/state information for this git repository.
function set_git_branch {
  # Capture the output of the "git status" command.
  git_status="$(git status 2> /dev/null)"

  # Set color based on clean/staged/dirty.
  if [[ ${git_status} =~ "working directory clean" ]]; then
    state="${GREEN}"
  elif [[ ${git_status} =~ "Changes to be committed" ]]; then
    state="${YELLOW}"
  else
    state="${LIGHT_RED}"
  fi

  # Set arrow icon based on status against remote.
  remote_pattern="# Your branch is (.*) of"
  if [[ ${git_status} =~ ${remote_pattern} ]]; then
    if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
      remote="↑"
    else
      remote="↓"
    fi
  else
    remote=""
  fi
  diverge_pattern="# Your branch and (.*) have diverged"
  if [[ ${git_status} =~ ${diverge_pattern} ]]; then
    remote="↕"
  fi

  # Get the name of the branch.
  branch_pattern="^# On branch ([^${IFS}]*)"
  if [[ ${git_status} =~ ${branch_pattern} ]]; then
    branch=${BASH_REMATCH[1]}
  fi

  # Set the final branch string.
  BRANCH="${state}(${branch})${remote}${COLOR_NONE} "
}

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}


# Return the prompt symbol to use, colorized based on the return value of the
# previous command.
function set_prompt_symbol () {
  if test $1 -eq 0 ; then
      PROMPT_SYMBOL="\$"
  else
      PROMPT_SYMBOL="${LIGHT_RED}\$${COLOR_NONE}"
  fi
}

# Determine active Python virtualenv details.
function set_virtualenv () {
  if test -z "$VIRTUAL_ENV" ; then
      PYTHON_VIRTUALENV=""
  else
      PYTHON_VIRTUALENV="${BLUE}[`basename "$VIRTUAL_ENV"`]${COLOR_NONE} "
  fi
}

# Set the full bash prompt.
function set_bash_prompt () {
  # Set the PROMPT_SYMBOL variable. We do this first so we don't lose the
  # return value of the last command.
  set_prompt_symbol $?

  # Set the PYTHON_VIRTUALENV variable.
  set_virtualenv

  # Set the BRANCH variable.
  if is_git_repository ; then
    set_git_branch
  else
    BRANCH=''
  fi

  # Set the bash prompt variable.
  PS1="${PYTHON_VIRTUALENV}${GREEN}\u@ ${YELLOW}\w${COLOR_NONE}$(parse_git_branch)${PROMPT_SYMBOL} "
}

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"

# Tell bash to execute this function just before displaying its prompt.
PROMPT_COMMAND=set_bash_prompt

and edit .bashrc and add this into the last line

1
source ~/bash_prompt.sh

4. Setup your Django

Usually we install requirements for our Django

1
sudo pip install -r requirements.txt

5. Setup your django.ini at “/etc/uwsgi/apps-enabled/”

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
[uwsgi]
# enable master process manager
master = true

# spawn 2 uWSGI worker processes
workers = 2

# bind to UNIX socket at /run/uwsgi/<confnamespace>/<confname>/socket
socket = /tmp/django.sock

# set mode of created UNIX socket
chmod-socket = 666

# place timestamps into log
log-date = true

# user identifier of uWSGI processes
uid = root

# group identifier of uWSGI processes
gid = root

; define variables to use in this script
project = django

; number of worker processes
processes = 8

; plugins=python
; project-level logging to the logs/ folder

; django >= 1.4 project
chdir = /var/django
wsgi-file=/var/django/django/wsgi.py

; run master process as root
enable-threads = true

vacuum = true
env = DJANGO_SETTINGS_MODULE=kargo.settings
pidfile2 = /tmp/django.pid

6. Setup your NGINX at “/etc/nginx/sites-enabled”:

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
server {
        listen   80;
        server_name django.yodiaditya.com;
        root /var/django;

    client_body_timeout 64600000;
    client_header_timeout 64600000;
    send_timeout 6460000;
    client_max_body_size 30m;
    keepalive_timeout 6300000;
    proxy_connect_timeout 6600000;
    proxy_send_timeout 6600000;
    proxy_read_timeout 6600000;

    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;

    location /media  {
         alias /var/django/media;
    }

    location /static {
         alias /var/django/static;
    }

    location / {
        uwsgi_pass unix:/tmp/django.sock;
        uwsgi_read_timeout 600000;
        include uwsgi_params;
    }

    error_page 403 404 500 502 503 504 /custom_50x.html;
    location = /custom_50x.html {
        root /usr/share/nginx/html;
        internal;
    }
}

Ubuntu

Setup New Server Ubuntu 14.10 with Django, Python and PHP

29 May , 2016  

Here is quickstep to configure a new server in Softlayer for Django and PHP development environtment.

1
2
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install libpq-dev python-dev python-software-properties postgresql postgresql-contrib nginx git zip unzip build-essential python nmap libxslt1-dev python-pip imagemagick uwsgi uwsgi-plugin-python nmap mysql-server phpmyadmin libffi-dev libmysqlclient-dev libmysqlclient-dev libmysqlclient18

For Django sites-enables/ :

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
server {
    listen 80;
    server_name www.yourdomain.com;
    return 301 $scheme://yourdomain.com$request_uri;
}

server {
    listen 80;

    server_name yourdomain.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/yourdomain;

    client_max_body_size 30m;

    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;

    location /media  {
         alias /var/yourdomain/media;
    }

    location /static {
         alias /var/yourdomain/static;
    }

    location / {
        uwsgi_pass unix:/tmp/yourdomain.sock;
        uwsgi_read_timeout 600000;
        include uwsgi_params;
    }

}

For WordPress 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
43
44
45
46
47
48
49
50
51
52
53
54
55
server {
    listen   80;
    server_name www.yourdomain.com;
    root    /var/yourdomain.com;

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

    access_log  /var/log/nginx/access.log;
    index  index.php index.html index.htm;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content
            try_files $uri $uri/ /index.php?$args;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
            fastcgi_send_timeout 3800;
            fastcgi_read_timeout 3800;
            fastcgi_connect_timeout 2800;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }

    # deny access to .htaccess files, if Apache document root
    # concurs with nginx one
    #
    location ~ /.ht {
            deny  all;
    }
}

Ubuntu

Setup SSL Certification RapidSSL on EC2

25 Nov , 2015  

Here are quickstep to generate SSL Certification

1
2
openssl genrsa -out www.domain.com.key 2048
openssl req -new -key www.domain.com.key -out www.domain.com.csr
1
2
3
4
5
6
7
8
9
10
11
12
Country Name (2 letter code) [AU]:ID
State or Province Name (full name) [Some-State]:Jakarta
Locality Name (eg, city) []:Jakarta
Organization Name (eg, company) [Internet Widgits Pty Ltd]:PT POLATIC INFORMATIKA INDONESIA
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:www.polatic.com
Email Address []:cs@polatic.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:PT POLATIC INFORMATIKA INDONESIA

Make sure check all value by :

1
openssl req -in www.domain.com.csr -noout -text

Option on “Common Name (e.g. server FQDN or YOUR name)” will used as your domain name certification. Make sure to choose “www” or non-www wisely.

Then we buy the certification.

Next step, we receive the certification from RapidSSL and download the intermediate from their website.
Merge together into :

1
cat www.domain.com.ssl www.domain.com.intermediate > www.domain.com.crt

Then in NGINX

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
server {
    server_name polatic.com;
    return 301 https://www.polatic.com$request_uri;
}

server { #Redirect https, non-www to https, www
    listen 443 ssl;
    server_name polatic.com;

    ssl_certificate      /etc/ssl/polatic.com.crt;
    ssl_certificate_key  /etc/ssl/polatic.com.key;
    return 301 https://www.polatic.com$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name www.polatic.com;
    ssl on;
    root    /var/polatic;

    ssl_certificate      /etc/ssl/polatic.com.crt;
    ssl_certificate_key  /etc/ssl/polatic.com.key;

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

    access_log  /var/log/nginx/access.log;
    index  index.php index.html index.htm;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content
            try_files $uri $uri/ /index.php?$args;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
            fastcgi_send_timeout 3800;
            fastcgi_read_timeout 3800;
            fastcgi_connect_timeout 2800;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }

    # deny access to .htaccess files, if Apache document root
    # concurs with nginx one
    #
    location ~ /.ht {
            deny  all;
    }

}

Ubuntu

Uwsgi on ubuntu 14.04 not working solution

12 Jul , 2015  

In Ubuntu 14.04, uwsgi that installed via apt-get will not working. To make it working, please use this steps:

1
2
sudo apt-get remove --purge uwsgi uwsgi-plugin-python
sudo apt-get install uwsgi uwsgi-plugin-python

Then follow this steps:

1
2
3
4
sudo pip install uwsgi
cd /usr/bin
sudo mv uwsgi uwsgi-old
sudo ln -s /usr/local/bin/uwsgi uwsgi

If still failed, follow this :

http://yodi.polatic.me/setup-latest-uwsgi-django-in-production-ubuntu-14-04/

Ubuntu

How to rollback or remove last commit in remove Git

26 Dec , 2014  

This is common thing can happen when we push bad commit and want to rollback into previous commit. Please try this in your own branch before apply into production / master.

Try with “git log” :

1
2
3
4
5
6
7
8
9
10
11
commit 10a8e361b35dd8131cb1ba3e606aad35d0d0f267
Author: Somebody
Date:   Fri Dec 26 13:02:33 2014 +0700

     Bad commit here

commit f89150c864cd4725a25995efd233f5beab7fc25d
Author: Somebody 2
Date:   Fri Dec 26 12:21:37 2014 +0700

    Stable version

So, we want to rollback commit from top into bottom. The easy way to do is :

1
git push -f origin <your-stable-commit>:<your-branch>

Example:

1
git push -f origin f89150c864cd4725a25995efd233f5beab7fc25d:development

Then update your local by:

1
git reset --hard origin/development

If this happened in your local but not submitted in remote yet, then you can reset it by:

1
git reset --hard HEAD~<number-of-rollback>

Ubuntu

Install locale ID in Ubuntu 14.04

15 Dec , 2014  

Here is quick step to install locale in Ubuntu:

1
2
3
sudo locale-gen id_ID
sudo locale-gen id_ID.UTF-8
sudo update-locale

Ubuntu

Solve RabbitMQ ERROR: epmd error for host “ubuntu”: address (cannot connect to host/port)

1 Dec , 2014  

When installing RabbitMQ in server, I got this errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Preparing to unpack .../rabbitmq-server_3.2.4-1_all.deb ...                
Unpacking rabbitmq-server (3.2.4-1) ...                                    
yProcessing triggers for man-db (2.6.7.1-1) ...                            
Processing triggers for ureadahead (0.100.0-16) ...                        
Setting up rabbitmq-server (3.2.4-1) ...                                    
 * Starting message broker rabbitmq-server                                  
 * FAILED - check /var/log/rabbitmq/startup_\{log, _err\}                  
   ...fail!                                                                
invoke-rc.d: initscript rabbitmq-server, action "start" failed.            
dpkg: error processing package rabbitmq-server (--configure):              
 subprocess installed post-installation script returned error exit status 1
Processing triggers for ureadahead (0.100.0-16) ...                        
Errors were encountered while processing:                                  
 rabbitmq-server                                                            
E: Sub-process /usr/bin/dpkg returned an error code (1)                    
ubuntu@ubuntu:~$ cat /var/log/rabbitmq/startup_                            
startup_err  startup_log                                                    
ubuntu@ubuntu:~$ cat /var/log/rabbitmq/startup_log                          
ERROR: epmd error for host "ubuntu": address (cannot connect to host/port)  
ubuntu@ubuntu:~$ cat /var/log/rabbitmq/startup_log                          
ERROR: epmd error for host "ubuntu": address (cannot connect to host/port)

The solution, set localhost on “/etc/hosts”

1
2
3
4
5
6
7
8
9
127.0.0.1       localhost
192.168.0.1 ubuntu.ubuntu   ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Into

1
2
3
4
5
6
7
8
9
10
127.0.0.1       localhost
127.0.0.1       ubuntu
192.168.0.1 ubuntu.ubuntu   ubuntu

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Ubuntu

Cleanup local branch and sync with Remote Git

22 Nov , 2014  

Here is git command to cleanup local branch and sync with remote :

1
git branch --merged | grep -v "\*" | egrep -v "master|dev" | xargs -n 1 git branch -d

Ubuntu

Blackberry as USB Modem connect into internet wvdial on Ubuntu with Barry

28 Jan , 2012  

I have Blackberry Bold 9800 and Ubuntu 11.10 Oneiric. Also, I have two of indonesian internet cards called “Telkomselflash” and “Indosat Broadband”. Now, I will introduce you how to make Blackberry Bold as USB Modem and connect into internet using Barry and PPPD.

First, you should install “Barry” packages in Ubuntu via apt-get or synaptic.

1
sudo apt-get install barry-util barrybackup-gui libbarry0

Then, you should plug your Blackberry via USB cable. Check if your Blackberry is detected by :
More…

,