DEV Community

Meng Ly
Meng Ly

Posted on

Laravel deployment with dokku

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
Enter fullscreen mode Exit fullscreen mode

4. Administrator to Dokku

Add SSH key

cat ~/.ssh/authorized_keys | dokku ssh-keys:add admin
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

6.Deployment

Deploy Laravel App to dokku

Create an app on dokku

dokku apps:create my-app
Enter fullscreen mode Exit fullscreen mode

Create database

dokku mysql:create my-database
Enter fullscreen mode Exit fullscreen mode

Link database to the app

dokku mysql:link my-database my-app
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Setup Domain

Buy a domain name on NameCheap
More details baout domains (https://dokku.com/docs/configuration/domains/)

dokku domains:set <app> <domain>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Add remote repository

git remote add dokku dokku@your_instance_ip:my-app
Enter fullscreen mode Exit fullscreen mode

Deploy in just one command

git push dokku main
Enter fullscreen mode Exit fullscreen mode

Thanks you so much guysss.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more