[Windows/Linux/Mac][PHP Deployer] Zero Downtime PHP Deployment

Deployer – https://deployer.org/
A zero downtime PHP deployment tool.

How it works?

Basically it SSH into the remote server, git clone to new folder, composer install, and create symlink to latest release folder
And optionally run database migration, restart PHP-FPM. If either step fails, it rollbacks the whole transaction.

Continue reading “[Windows/Linux/Mac][PHP Deployer] Zero Downtime PHP Deployment”

[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.

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:

Change public path in Laravel 5.*

Most shared host use public_html instead of public,
While sometimes considered bad practice, some client may force you to drop-in everything via FTP

There are several ways to change public folder name found on Google.

But most of them won’t work perfectly.

  1. In AppServiceProvider.php, bind ‘path.public’ to IoC container
    Won’t work in console, vendor:publish still publish in public path
  2. In index.php, bind ‘path.public’ to IoC container
    Works in console, but artisan serve still won’t work

After dig down deep in the source code, I found the cause:

The publicPath() method in Illuminate\Foundation\Application
is hardcoded.

But we should never hard the core, so let’s override this method on our own class.

Continue reading “Change public path in Laravel 5.*”