[Windows Bash] Using bash in Windows

As a full-stack developer in LAMP, I often play-around with Linux servers.
Unfortunately, there are always some reason that I can’t switch to Linux development machine.
E.g. Windows only printer drivers, Adobe Software, exe…

However, Windows cmd/PowerShell always disgust me for their special syntax.
And I missed Unix-like CLI tools such as (grep, find, wget, curl, vim, ssh…) so much.
Plus you can’t use id_rsa format in Windows directly (You will need putty, a GUI tool for CLI… and you need to convert all your keys)

So today we will get those lovely tools back, on Windows!
(Does NOT require Windows 10 Ubuntu Bash, should work on any supported version of Windows)
Continue reading “[Windows Bash] Using bash in Windows”

[Windows/Linux] PHP “exec” missing environment variable causing command not to run

In a recent project, I am finding way to display current git branch on the backend dashboard.
Without a application dependent library, executing CLI git seems to be the fastest way.
i.e. The exactly same syntax as we use in bash/cmd/powershell.

$currentBranch = exec('git rev-parse --abbrev-ref HEAD');

However, it worked in production/staging Linux machine, but not in local Windows machine.
It does work if I specify the absolute path C:\Program Files\Git\bin\git.exe, but it’s not optimal because it will be machine dependent.

After a while, I figure out the environment PATH variable is missing in Windows that cause git not being picked up.
The trick is, add this line before exec call to:

putenv('PATH=' . $_SERVER['PATH']);

Ubuntu Postfix Mail Server 設定筆記 (八) 使用 MySQL 管理 User, Domain 和 Alias

本系列第八篇: 使用 MySQL 管理 User, Domain 和 Alias

早在第二篇我們設定了 Dovecot 的 userdb 和 passdb 的靜態 Database。
但每次新增 Email 用戶都要 SSH 進 Server 修改 /etc/dovecot/passwd 都是太麻煩了。
這次把 Dovecot userdb 和 passdb 都放進 MySQL, 方便其他程式管理 Email 用戶。

Postfix 的 virtual_mailbox_domains 負責那些 domain 的 Email 可以轉交給 Dovecot LMTP
virtual_alias_maps 負責 Email 別名轉寄, 這裡也一併把它放進 MySQL 管理

Continue reading “Ubuntu Postfix Mail Server 設定筆記 (八) 使用 MySQL 管理 User, Domain 和 Alias”