todo after fresh ubuntu server vps install

apt-get install nano -y

echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >> ~/.bashrc
echo "export LC_ALL=en_US.UTF-8" >> ~/.profile
echo "export LANG=en_US.UTF-8" >> ~/.profile
echo "export LANGUAGE=en_US.UTF-8" >> ~/.profile

sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales

apt-get install htop

How i fix local issues on my ubuntu server

put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

reboot 1 // can be re-login but reboot is so fast for my vps servers that i just reboot lol, less typing :)

sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales

How i did SSL with let's encrypt for free

I use ubuntu v14 on vps machine. I have couple nodejs scripts running with pm2. I use https server inside js files:

const app = require('express')();

const fs = require('fs');
var privateKey = fs.readFileSync('/etc/letsencrypt/live/'); // privatekey.pem
var certificate = fs.readFileSync('/etc/letsencrypt/live/'); // certificate.pem
var chain = fs.readFileSync('/etc/letsencrypt/live/'); // certificate.pem
const https = require('https').Server({
  key: privateKey,
  cert: certificate,
  ca: chain}, app);

In nginx i use this:

    server {
      listen 443 ssl;


     ssl_certificate /etc/letsencrypt/live/;
     ssl_certificate_key /etc/letsencrypt/live/;

      keepalive_timeout 10;

      location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;

      location / {
          proxy_redirect off;
          proxy_set_header   X-Real-IP         $remote_addr;
          proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
          proxy_set_header   X-Forwarded-Proto $scheme;
          proxy_set_header   Host              $http_host;
          proxy_set_header   X-NginX-Proxy     true;
          proxy_set_header   Connection        "";
          proxy_pass         http://pm2upstream;


Tried different guides and failed.

This worked:

  1. wget
  2. chmod a+x ./certbot-auto
  3. service nginx stop
  4. ./certbot-auto certonly  & follow instructions, use auto server
  5. reboot 0     // i hear you screaming about this, best wishes, sys admins

Prestashop update all prices with SQL (fully working)

I had to update all prices of shop made with PrestaShop. Found some tutorials where in that crazy database prices are saved, but none fully working example in one place. I was updating from prices written in Lithuanian Litas to Euros. 1 Euro = 3.4528 Litas So my solution:

PHP Recursive dir size with iterator object

public function getDirSize($dir, $format = true)
        $dir_iterator = new RecursiveDirectoryIterator($dir);
        $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
        $size = 0;
        foreach ($iterator as $file) {
            $size += $file->getSize();

        if ($format) {
            if ($size / 1048576 > 1) {
                return round($size / 1048576, 1) . ' MB';

                // if the total size is bigger than 1 KB
            } elseif ($size / 1024 > 1) {
                return round($size / 1024, 1) . ' KB';

                // else return the filesize in bytes
            } else {
                return round($size, 1) . ' bytes';
        } else {
            // return the total filesize in bytes
            return $size;


$size = getDirSize('/dir/to/get/size/');