четверг, 16 сентября 2021 г.

Linux Bash check disk space

df --output=pcent / | tail -n +2 | tr -cd '0-9\n'

output available percent without header and symbol '%' - only number

#!/bin/bash

for mnt in / /var/log /var/www /mnt/shared; do

  chk_avail=`df --output=pcent $mnt | tail -n +2 | tr -cd '0-9\n'`

  flg=`echo $(( 100 - $chk_avail ))`

  if [ $flg -lt 15 ]; then

    echo 'Dataserver lack of free space, only '$flg' percent available in '$mnt' partition' | mail -s 'Dataserver lack of free space' alerts@gmail.com

  fi

done



пятница, 23 апреля 2021 г.

Magento 2 Multistore one domain

domain.com/store1

domain.com/store2

  1. Admin Panel: Stores/Settings/Stores (table store for checking code for MAGE_RUN_CODE)
    website: base, store: store1_code, store view: store1
    website: base, store: store2_code, store view: store2
  2. Admin Panel: Configuration/Web/URL Options/Add Store Code to Urls - Yes
  3. NGINX: 

    .php

        fastcgi_param  MAGE_RUN_TYPE    $MAGE_RUN_TYPE;

        fastcgi_param  MAGE_RUN_CODE    $MAGE_RUN_CODE;

    http

    map $request_uri $MAGE_RUN_CODE {

        ~^/store1 store1;

        ~^/store2 store2;

    }

    server
        set $MAGE_RUN_TYPE store;

воскресенье, 14 марта 2021 г.

среда, 24 февраля 2021 г.

grep with wildcard

 If you have a file with data and you need only words which starts with ABCD- and three numbers at the end. You can use it

 egrep -ow ABCD-... the_file

-o, --only-matching

 -w, --word-regexp         force PATTERN to match only whole words

... - three any numbers


понедельник, 9 ноября 2020 г.

PHP-FPM via command line

1. Install apt install libfcgi0ldbl

2. Install apt install html2text

3. Sh script

SCRIPT_FILENAME=/path/to/site/php_info.php \
REQUEST_URI=/ \
QUERY_STRING= \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect /run/php/php7.3-fpm.sock

4. script.sh | html2text

We will get phpinfo() function output through php-fpm, not through php-cli

четверг, 25 июня 2020 г.

PHP Xdebug multi php versions in the server , fixing xdebug.so: undefined symbol: zend_post_startup_cb

If you have many php versions in the server we might face Xdebug installing.
Firstly, I installed via manual as
install PECL, then install xdebug through pecl
As result, I got an error

xdebug.so: undefined symbol: zend_post_startup_cb

The default php version in the server is PHP 7.3 . I need to install Xdebug for PHP 7.2
I used those links
https://gist.github.com/amenk/29636622c60a420330a8b827d166f9cf
https://qna.habr.com/q/729423
https://xdebug.org/docs/install
The server is Debian. I installed php7.2-dev. We will use phpize and php-config from the package.
It is MATTER to use version as  phpize7.2 and php-config7.2
1) download
2) tar -xzf xdebug-2.9.6.tgz && cd xdebug-2.9.6
3) phpize7.2
4) ./configure --with-php-config=/usr/bin/php-config7.2
5) make
6) copy from modules folder to lib folder.
to check that lib folder via phpize7.2
7) add to available modules with 20 priority
PS: firstly, I used 10 priority and got error with IonCube. 20 priority helped
Then restart PHP service and enjoy

среда, 20 мая 2020 г.

Nginx map $request_uri example

If I need to add http auth to special location I can use map

http block

map $request_uri $auth {
    /2.3.5/  "Authorization Required";
    default  "off";
}

server block

    auth_basic $auth;
    auth_basic_user_file /etc/nginx/.htpasswd;