Deploy Laravel With Dokku
1. Dokku
Dokku as a special helper that takes your favorite toys and puts them in a big play area so you and your friends can play with them whenever you want.
2. Dokku Installation
System Requirement
- Operating Systems
- Ubuntu 20.04/22.04
- Debain 10+ x64
- Min 1GB of system Memory # 3. Install Dokku To install the latest stable version of Dokku, you can run the following shell commands:
wget -NP . https://dokku.com/install/v0.34.4/bootstrap.sh
sudo DOKKU_TAG=v0.34.4 bash bootstrap.sh
4. Administrator to Dokku
Add SSH key
cat ~/.ssh/authorized_keys | dokku ssh-keys:add admin
5.Database on Dokku
Install MYSQL
To install the mysql plugin, you can run the following shell commands:
sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql
6.Deployment
Deploy Laravel App to dokku
Create an app on dokku
dokku apps:create my-app
Create database
dokku mysql:create my-database
Link database to the app
dokku mysql:link my-database my-app
Setup PHP Buildpack
Crate file .buildpacks in your project and paste these code
https://github.com/heroku/heroku-buildpack-php
https://github.com/heroku/heroku-buildpack-nodejs
Create the Procfile in the project directory
release: php artisan migrate --force && composer dumpautoload web: vendor/bin/heroku-php-apache2 -i php_custom.ini public/
Create the php_ custom.ini in the project directory
Enable php plugin
upload_max_filesize = 3000M
post_max_size = 3000M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300
max_input_vars = 10000
max_file_uploads = 20
max_upload_filesize = 3000M
Config .ENV to the dokku app
Example: mysql://mysql:2f4629asdf309a7d@dokku-mysql-my-database:3306/my_database
Example: DB_CONNECTION://DB_USERNAME:DB_PASSWORD@DB_HOST:3306/DB_DATABASE
dokku config:set my-app APP_ENV=production
dokku config:set my-app APP_KEY=yoursecretkeyinserthere
dokku config:set my-app DB_CONNECTION=mysql
dokku config:set my-app DB_HOST=dokku-mysql-my-database
dokku config:set my-app DB_DATABASE=my_database
dokku config:set my-app DB_USERNAME=mysql
dokku config:set my-app DB_PASSWORD=2f4629asdf309a7d
Setup Domain
Buy a domain name on NameCheap
More details baout domains (https://dokku.com/docs/configuration/domains/)
dokku domains:set <app> <domain>
Setup HTTPS
More details about letsencrypt (https://github.com/dokku/dokku-letsencrypt)
Documents
$ dokku letsencrypt:help
letsencrypt:active <app> Verify if letsencrypt is active for an app
letsencrypt:auto-renew Auto-renew all apps secured by letsencrypt if renewal is necessary
letsencrypt:auto-renew <app> Auto-renew app if renewal is necessary
letsencrypt:cleanup <app> Cleanup stale certificates and configurations
letsencrypt:cron-job <--add|--remove> Add or remove an auto-renewal cronjob
letsencrypt:disable <app> Disable letsencrypt for an app
letsencrypt:enable <app> Enable or renew letsencrypt for an app
letsencrypt:list List letsencrypt-secured apps with certificate expiry
letsencrypt:revoke <app> Revoke letsencrypt certificate for app
What we do
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
sudo dokku plugin:update letsencrypt
dokku letsencrypt:set app-name email
dokku letsencrypt:enable
Add remote repository
git remote add dokku dokku@your_instance_ip:my-app
Deploy in just one command
git push dokku main