Yii2 Log using FileTarget

Here’s a sample Yii2 FileTarget configuration (to be added to the application’s configuration) used for logging. This configuration overwrite the default log file location, doesn’t capture the global PHP variables and also, adds a prefix to the log entry. 'bootstrap' => [ 'log', ], 'components' => [ 'log' => [ 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'info'], // Custom log file. Default log file will appear in @runtime/logs 'logFile' => dirname(__DIR__) . '/log/app.log', // 'logVars' => [], // Custom prefix. 'prefix' => function ($message) { $request = Yii::$app->getRequest(); $ip = $request instanceof yii\base\Request ? $request->getUserIP() : '-'; $controller = Yii::$app->controller->id; $action = Yii::$app->controller->action->id; return "[$ip][$controller][$action]"; } ], ], ], ],

April 9, 2020

S3cmd on CentOS 7

S3cmd is a command line tool that we’ve used for uploading, retrieving and managing data in Amazon S3. To install S3cmd, you just need to run the install command. yum install s3cmd

March 20, 2020

Setup User and RBAC Management in Yii2

My goal for this exercise is to have User and RBAC management in my Yii 2 application. I’ve started out with the Yii 2 Basic Project Template and I would be adding the Yii2-user and Yii2-rbac extensions to my web application. Here are some of the steps I have taken to install and configure the extensions. Step 1: Installation Install the packages. composer require dektrium/yii2-user composer require dektrium/yii2-rbac Step 2: Configure the web application NOTE: Make sure that you don’t have user component configuration in your config files. Add the user and rbac module to the web applcation config. ...

August 26, 2019

Send Telegram Message in Group using VB Script

Here’s a vb script snippet that I have used to send Telegram message in a group from an Excel sheet. Sub sendTelegramMessage() Set objHttp = CreateObject("MSXML2.ServerXMLHTTP") ' Change these accordingly strChat = "<chat_id>" strText = "*Test*\r\nThis is a message" strUrl = "https://api.telegram.org/bot<token>/sendMessage" ' Leave these alone strMode = "markdown" strJson = "{""chat_id"": """ & strChat & """, ""text"": """ & strText & """, ""parse_mode"": """ & strMode & """}" objHttp.Open "POST", strUrl, False objHttp.setRequestHeader "Content-type", "application/json" objHttp.send strJson End Sub

August 17, 2018

WAMP and curl

Often times, after a fresh install of WAMP server, curl stops working. You might get a hint of the issue in logs/php_error.log If not, it could be that the SSL/TLS Certificate Authority (CA) certificates has not bee setup properly. Download cacert.pem Move the cacert.pem file to a folder, e.g. C:\code\ssl\cacert.pem Edit the php.ini file and change the curl.cainfo parameter, e.g. curl.cainfo = “C:\code\ssl\cacert.pem”

February 9, 2018

Add and Allow New Telegram Bot to Send Message in Group

Talk to @BotFather, and request to create a new bot. (hint: /help) Give the new bot a name, and a unique username. Take note of the bot token given by the @BotFather Add the new bot to a group. Run this - https://api.telegram.org/bot<bot_token>/getUpdates , to get the group’s chat id that contains the new bot. In the group, type /start @username to activate the new bot.

February 5, 2018

Nginx Configuration for Multiple Yii2 Site Under Same Domain

This nginx configuration will allow you to run multiple instances of Yii2 in sub folders under the same domain. Eg. http://advanced.local/ and http://advanced.local/subfolder/ server { listen 80; # listen for IPv4 server_name advanced.local; set $root_path /var/www/main/web; root $root_path; index index.html index.php; charset utf-8; client_max_body_size 100M; location / { root $root_path; try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /$uri =404; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ^~ /subfolder { alias /var/www/subfolder/web; if (!-e $request_filename) { rewrite ^ /subfolder/index.php last; } location ~ \.php$ { if (!-f $request_filename) { return 404; } include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; } } location ~* \.(htaccess|htpasswd|svn|git) { deny all; } }

December 27, 2017

Magento 2 Upgrade Ritual

Assuming that you are on Magento version 2.0.6 and would like to upgrade to 2.0.7 composer require magento/product-community-edition 2.0.7 --no-update composer update rm -rf var/di var/generation/* var/view_preprocessed/* var/cache/* var/page_cache php bin/magento cache:clean php bin/magento cache:flush php bin/magento setup:upgrade php bin/magento setup:di:compile php bin/magento indexer:reindex

February 28, 2017

Amazon Cloudwatch alarm to Jaconda - a Telegram Smartbot

We have setup Amazon Cloudwatch alarms to keep track of various metrics. In a situation where a particular alarm is triggered, a notification is sent to a Amazon Notification Topic. Within that Amazon Notification Topic, one of the subcription uses the lambda protocol. It is through this subscription which we would get Amazon Lambda to send a message to Jaconda - a Telegram Smartbot. Here’s a sample Node.js script that we have used. ...

February 15, 2017

RabbitMQ can not login with guest/guest

After a fresh install of RabbitMQ, I have encountered a Login Failed error when trying to access the RabbitMQ Management console at http://localhost:15672 Here’s one possible solution to overcome this issue. Create a file /etc/rabbitmq/rabbitmq.config, and add the below content into that file. [{rabbit, [{loopback_users, []}]}]. Restart the service to apply the changes.

December 20, 2016