Beanstalkd “cold” delete all jobs

/etc/init.d/beanstalkd stop
cd /var/lib/beanstalkd
rm -r -f *
/etc/init.d/beanstalkd start

Git hard remove last commit

git reset --hard HEAD~1

Apache2 enable mod_proxy

a2enmod proxy_http

Php curl verbose

<?php
 
curl_setopt($f1, CURLOPT_VERBOSE, true);

Yii 2 Download a File

<?php
 
return Yii::$app->response->sendFile($fileName);

Yii2 custom logger

Step 1:
app/config/console.php

 
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'app\helpers\MyFileTarget',
                    'exportInterval' => 1,
                    'categories' => ['my-category'],
                    'except' => ['application'],
                    'levels' => ['trace'],
                    'logFile' => '@app/runtime/logs/my-category.log',
                ],
            ],
        ],

Step 2:
Create file app/helpers/MyFileTarget.php

 
<?php
 
namespace app\helpers;
 
use Yii;
use yii\log\Logger;
use yii\log\FileTarget;
 
class MyFileTarget extends FileTarget
{
 
    public function formatMessage($message)
    {
        list($text, $level, $category, $timestamp) = $message;
        $level = Logger::getLevelName($level);
 
        if ($level == 'trace') {
        return date('Y-m-d H:i:s', $timestamp) . " [$level][$category] $text";
        }
    }
}

Step 3:

cat /var/www/yii2-installed-dir/app/runtime/logs/my-category.log

Change apache2 running user/group

vi /etc/apache2/envvars

Edit

export APACHE_RUN_USER=imran
export APACHE_RUN_GROUP=www-data

Save and restart apache

Ubuntu reset root password

If you forgot root’s password follow these steps to reset it:
1. Reboot, press ESC to get to GRUB boot loader menu
2. Choose from the list kernel with

(recovery mode)

3. From the menu screen choose

"Drop to root shell prompt"

4. By default it gives you read-only filesystem Run this for read/write:

mount -o remount,rw /

5. Run this to change root’s password:

passwd root

Mysql bulk UPDATE

Run the following statement for bulk UPDATE

UPDATE table1 SET column2 = CASE 
WHEN column1 = 'A' THEN 'AB'
WHEN column1 = 'B' THEN 'BC'
WHEN column1 = 'C' THEN 'CD'
ELSE column2 
END;

Make sure you included ELSE statement, if you skip it then it will NULL rest of the column2 fields.
So, if you have any pre-filled column2 field and you want to keep their values then use ELSE column2 to keep them.

Git show last changes in file

git diff composer.json