Some notes about running a Laravel App on Coolify. Documentation here
Assuming that the Laravel App is on Github private repository, on your Coolify Project choose + New, choose Github Private Repository (with GitHub App), Choose the server where you want to install, Choose a GitHub App you have already added before to Coolify or create a new one with + Add GitHub App, select the repository you want to load, and click on Load Repository (this, depending setting of the GitHub App you have created, you will see the repository that the App has access). next step:
Choose the Branch or use the default main
Set Build Pack to Nixpacks
(should be already selected)
Set Port Exposes to 80
click on Continue
Now that the app is installed, you have to set APP_KEY
in your App Environment Variables. you can generate here more info here
APP_KEY=base64:****************
Also, add all the other Environment Variables you need, for example:
DB_CONNECTION=mysql
DB_HOST=<DB_HOST>
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
REDIS_HOST=<REDIS_HOST>
REDIS_PASSWORD=null
REDIS_PORT=6379
Run on SSL
on Coolify, when you change the app URL to an https URL (https://example.com) and point that URL to your Coolify server IP in your DNS record, it will automatically generate the Let’s Encrypt certificate in background.
you will notice that the app does not work well on the https URL, returning some “Mixed Content” issue loading assets, and also on login, logout routes for example, because is serving assets, and routes in HTTP.
I have found this solution that work:
Add this before the class name of this file app\Providers\AppServiceProvider.php
use Illuminate\Support\Facades\URL;
Then paste this code inside the boot
function of app\Providers\AppServiceProvider.php file of your Laravel App.
if (config('app.env') === 'production') {
URL::forceScheme('https');
}
Add these Environment Variables to your Coolify app:
APP_ENV=production // app in production, forceScheme https will run
APP_KEY=base64:**************** // the app key - generate or create a new one - 32 character key
APP_NAME=AppName
APP_URI=https://example.com
ASSET_URL=https://example.com
App should running smoothly with Https.
Additional Notes
If you are using Laravel Debugbar locally, you can add another Environment Variables to deactivate on live server
DEBUGBAR_ENABLED=false