Skip to content

Instantly share code, notes, and snippets.

@dhovart
Last active May 24, 2023 12:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dhovart/c9b67ef62e79042c4713 to your computer and use it in GitHub Desktop.
Save dhovart/c9b67ef62e79042c4713 to your computer and use it in GitHub Desktop.
Simple steps to set up a Laravel app on dokku in a Vagrant box
# --------------------------------------------------
# Setting up a Laravel app on dokku in a Vagrant box
# --------------------------------------------------
# First: cloning the dokku repo
$ git clone https://github.com/progrium/dokku
$ cd dokku
# Start, configure & provision a new vagrant box using the Vagrantfile from the repo
$ vagrant up
# Install dokku and its dependencies (dokker, git, buildstep, nginx…) on the newly created VM
$ vagrant ssh -- "wget -qO- https://raw.github.com/progrium/dokku/v0.2.3/bootstrap.sh | sudo DOKKU_TAG=v0.2.3 bash"
# Upload our public ssh key
$ cat ~/.ssh/id_rsa.pub | vagrant ssh -- sudo sshcommand acl-add dokku denis
# this should work if things went smoothly
$ ssh dokku@dokku.me version
# Logging in with the vagrant user to check that everything is ok
$ vagrant ssh
# In the ssh banner message:
# > (...)
# > *** System restart required ***
# > (...)
# > WARNING! Your environment specifies an invalid locale.
# So, first, regenerating locales…
vagrant@dokku:~$ sudo locale-gen fr_FR.UTF-8
vagrant@dokku:~$ sudo dpkg-reconfigure locales
# Then rebooting VM
vagrant@dokku:~$ exit
$ vagrant reload
$ vagrant ssh # No more warnings !
$ exit
# Now, on to create a new Laravel project
# We first add dokku.me to the hosts file, using the ip defined in dokku’s Vagrantfile
# (We need to manually add our future app subdomain as well. In staging or production, a wildcard A record would have done the trick)
$ sudo $EDITOR /etc/hosts
+ 10.0.0.2 dokku.me
+ 10.0.0.2 php-test-app.dokku.me
# We add an entry to our ssh config as well for more convenience
$ $EDITOR ~/.ssh/config
+ Host dokku.me
+ Port 2222
# We set up a new Laravel project
$ cd <PROJECTS_DIR>
$ composer create-project laravel/laravel php-test-app --prefer-dist
$ cd php-test-app
$ git init
$ git add . && git commit -m "Set up Laravel"
# Adding the dokku VM to the git remotes as 'devbox'
$ git remote add devbox dokku@dokku.me:php-test-app
$ git push devbox master
Counting objects: 506, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (494/494), done.
Writing objects: 100% (506/506), 372.63 KiB | 0 bytes/s, done.
Total 506 (delta 132), reused 0 (delta 0)
-----> Cleaning up ...
-----> Building php-test-app ...
remote: warning: You appear to have cloned an empty repository.
remote: HEAD is now at a393509... Setting up Laravel
Unable to select a buildpack
To dokku@dokku.me:php-test-app
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku@dokku.me:php-test-app'
# Not working at first try :/
# Actually, in order for dokku to detect that it should use the heroku php buildpack, we must remove composer.lock from the .gitignore file first and re-commit it
# Then we try again…
$ git push devbox master
(...)
-----> Deploying php-test-app ...
=====> Application deployed:
http://php-test-app.dokku.me
To dokku@dokku.me:php-test-app
* [new branch] master -> master
# \o/
# …except that we get a 403 from nginx when we try to acces the specified URL.
# We need to tune our composer.json to tell the document root and set the correct rights on app/storage. More info here : https://github.com/heroku/heroku-buildpack-php
# So, we add the following:
#
# "extra": {
# "heroku": {
# "document-root": "public",
# "index-document": "index.php",
# "compile": [
# "chmod -R 777 app/storage"
# ]
# }
# }
#
# Then commit, deploy again, et voilà !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment