YT Por

I’m a code writer, observer, handyman, researcher, motivator, consultant and photographer.

SSH Tunnel to MySQL in Private Network

This setup is done on Windows 11, using HeidiSQL. We are using a private key to SSH to the server. Make sure that you have SSH to the server at least once, and has the server is listed in ~/.ssh/known_hosts Assuming that our server is on 218.8.8.88, and our MySQL is on 10.219.80.88 (private network). Open HeidiSQL. Create a New Session: Click on the New button to create a new session. Configure the Session: Under the Settings tab: Network Type: Select MySQL (SSH tunnel) Hostname / IP: 10.219.80.88 User: Enter your MySQL username. Password: Enter your MySQL password. Port: The default MySQL port is 3306. SSH tunnel tab: Check Use SSH tunnel SSH executable: ssh.exe SSH Host + Port: Enter 218.8.8.88 (the SSH server IP) and the SSH port (default is 22). Username: Enter your SSH username. Password: Enter your SSH password or use an SSH key if you have one. Private key file: Locate your private key file Local port: 3307 Save and Connect: Click Save to save the session. Click Open to establish the connection.

October 7, 2024

Running multiple instances of MariaDB

We have come across an occassion where we need to run multiple MariaDB databases on different port on the same Windows server. For our use case, each of the database represents a particular enviroment, eg. staging, sandbox or production. The same technique that I am going to illustrate will work for MySQL. Here’s how it was done. Upon installing MariaDB, we made a few copies of the data folder found in C:\Program Files\MariaDB 10.11\data, and named them:- ...

July 4, 2024

Multiple GitHub Accounts and Repositories

We work in an environment where we have multiple GitHub accounts that is tied to different repositories. It took us a while to figure out how to properly set this up, so that the correct identify is tied to the correct repository. Let me walk you through an example on how we did it. Assuming that you have 3 identity, ie. 3 private keys, tied to 3 different GitHub repository. ...

May 12, 2023

Yii2 Internationalization (i18n) for advanced template

We are working on a project that makes use of Yii2 advanced template. This project needs to support Internationalization (i18n). In each of our application, we have a translation configuration. This is needed to generate the translation. The files would be generated in backend/messages, common/messages or frontend/messages. Here’s a sample. <?php // backend/config/i18n.php // common/config/i18n.php // frontend/config/i18n.php return [ 'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..', 'languages' => [ 'zh-CN', ], 'translator' => 'Yii::t', 'sort' => true, 'removeUnused' => true, 'markUnused' => true, 'only' => ['*.php'], 'except' => [ '.svn', '.git', '.gitignore', '.gitkeep', '.hgignore', '.hgkeep', '/assets', '/command', '/config', '/mail', '/messages', '/modules', '/runtime', '/tests', '/vagrant', '/vendor', '/views/user/settings', '/web', '/widgets', ], 'format' => 'php', 'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages', 'overwrite' => true, ]; Here are some samples of how the text should be wrapped. ...

May 12, 2023

Yii 2 Codeception Fixtures Gotcha

We use MongoDB (important point) with our Yii 2 applicaton. While setting up our API test fixtures in our Cest file, $I->grabFixture was not able to find the data we wanted eventhough we have defined it within the dataFile. [yii\base\ErrorException] Trying to get property 'client_id' of non-object Here’s what the dataFile looks like. <?php // This doesn't work. return [ 'client_one' => [ 'client_id' => 'mytestclient', ], ]; After some experimentation, we’ve found that we need to set the _id within the dataFile in order to get $I->grabFixture to work properly. ...

July 17, 2021

Yii 2 Codeception API Test

My API uses the Yii2 advanced template. It uses symfony/dotenv to read the .env. The .env is loaded in all the configurations. $dotenv = new Symfony\Component\Dotenv\Dotenv; $dotenv->load(__DIR__ . '/../../.env'); While running the Codeception api test, I came across this error. [PHPUnit\Framework\Exception] Undefined index: HOST at ../common/config/main-local.php:7 After much digging around, I’ve realized that I need to load Symfony\Component\Dotenv\Dotenv in common/config/codeception-local.php Thus, I have updated that file in the environment folder, and reran php init. ...

June 30, 2021

Yii 2 Four oh Four Not Found

After setting up a new application using Yii 2 Advanced Project Template, the very first time you want to load your new controller, if you are met with a 404 Not Found, one very likely cause is that you do not have a .htaccess in your web folder.

June 29, 2021

Yii2 URL manager cache class

You might come across the below warning if you have not set a cache to your Yii2 application while using URL manager. Unable to use cache for URL manager: Failed to instantiate component or class "cache". In order to remove that warning, setup a cache in your application’s configuration. We are using the DummyCache class here as we have yet to decide on one that we want to use. 'components' => [ 'cache' => [ 'class' => 'yii\caching\DummyCache', // FIXME ], ],

April 9, 2020

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