Configure thumbnails for video files in nextcloud

Nextcloud use ffmpeg to generate thumbnails from video files, so you need to install ffmpeg on your server first:

sudo apt install ffmpeg

Now configure nextcloud. Open configuration file /config/config.php and add this lines:

'enable_previews' => true,
'enabledPreviewProviders' => array (
        0 => 'OC\\Preview\\Image',
        1 => 'OC\\Preview\\Movie',
        2 => 'OC\\Preview\\TXT',
),

That’s all, it is very simple 😉

How to Install NGINX and PHP 7.4 on Debian 10

Step 1: Install Nginx

Firstly install the prerequisites:

sudo apt install curl gnupg2 ca-certificates lsb-release

Then we need to add the Nginx mainline package to our repository so that when we run apt install nginx, we will download the mainline version instead of the old stable version.

echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" 
    | sudo tee /etc/apt/sources.list.d/nginx.list

Next we need to download the signing key so that we can verify its authenticity

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -

If it prints out OK! then you are good to go!

Now update package repositories and install Nginx:

sudo apt update
sudo apt install nginx

That’s it! You have now installed the latest release of Nginx on Debian 10. You should now start it!

sudo systemctl start nginx.service

And Don’t forget to make it automatically start on system boot as well.

sudo systemctl enable nginx.service

Step 2: Install PHP 7.4

To install PHP 7.4 we need to add repository. Since PHP 7.4 didn’t come with Debian 10 it is required to add the following repository. Write this commands:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Update package repositories:

sudo apt update

And now install PHP 7.4:

sudo apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-gmp php7.4-curl php7.4-intl php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-cli php7.4-zip php7.4-soap php7.4-imap

It is recommended to raise the memory limit to improve the overall performance. Your PHP configuration is located in /etc/php/7.4/fpm/php.ini.

sudo vim /etc/php/7.4/fpm/php.ini

Replace it with memory_limit = 256 and save document with :wq command. How to edit files in text editor Vim you can read here: How to exit Vim? And other required commands.

Step 3: Configure Nginx

Add nginx to www-data group

sudo usermod -a -G www-data nginx

Change owner of directory to www-data

sudo chown -R www-data /usr/share/nginx/html

Go into your default.conf file

sudo vim /etc/nginx/conf.d/default.conf

Replace your existing configuration file with the one below

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;

   location / {
    if ($request_uri ~ ^/(.*)\.html$) {
        return 302 /$1;
        }
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
        location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}

Restart Nginx server:

service nginx restart

Now you can cteate test file fith information about PHP version:

nano /usr/share/nginx/html/phpinfo.php
phpinfo();

In Web-browser write IP address of server:
http://192.168.1.1/phpinfo.php

That’s all Nginx Server with PHP 7.4 installed.

Change default Grub 2 theme

Different themes for Grub 2 boot loader you can find on Gnome-Look website: https://www.gnome-look.org/browse?cat=109&ord=latest

To change Grub them use three simple steps:

1. Copy folder with theme into Grub themes directory:

/boot/grub/themes

2. Edit Grub configuration file /etc/default/grub and write there GRUB_THEME parameter:

GRUB_THEME=/boot/grub/themes/theme_folder/theme.txt

3. Update Grub configuration:

update-grub

Best three Grub themes:

1. Vimix

2. Tela

3. CyberRe

How to block Windows 10 Update

Windows 10 offers less UI control over the updating behavior of the operating system than previous versions of Windows , There is no option to turn off Windows Updates using the Control Panel or Settings app in Windows 10, it checks for updates automatically and install any updates they find, whether you like it or not.

To completely block all updates of Windows 10 use Windows Update Blocker tool.

How it works? Just download Windows Update Blocker – it’s freeware program and run it.

Here you can download Windows Update Blocker and get full instruction how to completely disable update of Windows 10.

Install Composer and Laravel

First install Composer package manager on on your project:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

Now install Composer global:

php composer.phar global require laravel/installer

Install Composer to your project (change site-name to your project name):

php composer.phar create-project --prefer-dist laravel/laravel site-name "8.*"

You don’t need Windows anymore

Microsoft Windows is a proprietary operating system which has captured 80% personal computers in the world and using their monopoly position dictates their rules of the game.

In addition, Microsoft collects your personal information and sells it to third parties, which endangers your security.

To change the situation, many people are looking for alternative operating systems, and one such alternatives is GNU Linux.

Many years Linux was leader operating system on web servers and mainframes, but on personal computers it occupied a miserable 3%. But now the situation has changed and GNU Linux is the best free and open source alternative for proprietary Microsoft Windows.

Javascript: Closures, callback, context

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.

window.onload = function(){
    var item = document.querySelector(".items .item");
    item onClick = activeItem;

    function activeItem() {
        console.log(item);
    }
}

In this example inner function activeItem() have access to global variable item. This called closure – when inner function have access to all variables, defined in global function.

JavaScript: Type conversion

To show variable type use typeof:

let value = true;
console.log(typeof value); // boolean

Let’s convert our variable to string:

value = String(value); // now value is a string "true"
console.log(typeof value); // string

Numeric Conversion

Numeric conversion happens in mathematical functions and expressions automatically.

For example, when division / is applied to non-numbers:

console.log( "6" / "2" ); // 3, strings are converted to numbers

We can use the Number(value) function to explicitly convert a value to a number:

let str = "123";
console.log(typeof str); // string

let num = Number(str); // becomes a number 123
console.log(typeof num); // number

Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered.

If the string is not a valid number, the result of such a conversion is NaN. For instance:

let age = Number("an arbitrary string instead of a number");
console.log(age); // NaN, conversion failed

Examples of numeric conversion:

console.log( Number(" 123 ") ); // 123
console.log( Number("123z") );  // NaN (error reading a number at "z")
console.log( Number(true) );    // 1
console.log( Number(false) );   // 0

Please note that null and undefined behave differently here: null becomes zero while undefined becomes NaN.

Boolean Conversion

The conversion rule:

Values that are intuitively “empty”, like 0, an empty string, null, undefined, and NaN, become false.
Other values become true.

For instance:

console.log( Boolean(1) ); // true
console.log( Boolean(0) ); // false

console.log( Boolean("hello") ); // true
console.log( Boolean("") ); // false

Summary

The three most widely used type conversions are to string, to number, and to boolean.

String Conversion – Occurs when we output something. Can be performed with String(value). The conversion to string is usually obvious for primitive values.

Numeric Conversion– Occurs in math operations. Can be performed with Number(value).

Boolean Conversion – Occurs in logical operations. Can be performed with Boolean(value).

Install monit in Debian 10 (buster)

Monit is a free open source utility for managing and monitoring, processes, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

To install Monit on Debian 10 GNU Linux (Buster) you need to add backports repository:

printf "%s\n" "deb http://ftp.de.debian.org/debian buster-backports main" | \
sudo tee /etc/apt/sources.list.d/buster-backports.list

Then update package list:

sudo apt update

And install buster-backports and monit package:

sudo apt install -t buster-backports monit

To start monit service and show running status use commands:

sudo systemctl start monit
sudo systemctl status monit

If you want to enable auto start monit when system starts use command:

sudo systemctl enable monit

Now let’s configure monit to monitoring Apache2 and Nginx services. Open monit configuration file:

sudo vim /etc/monit/monitrc

To change monitoring interval change option:

set daemon 120

To send email if monitored services is down edit this options:

set mailserver your.mail.server
set alert your.mail.address

You can enable Web-interface where you can view information about monitoring services. By default monit starts on 2812 port. Enable this two lines and change administrator password:

set httpd port 2812 and
allow admin:monit # require user 'admin' with password 'monit'

Don’t forget to open port 2812 in firewall and restart monit service:

sudo systemctl restart monit

Now open http://your-site.com:2812 and see monit web interface:

If you want to monitor some custom services on your server go to /etc/monit/conf-available and copy that configuration files to /etc/monit/conf.d: