Close

Using Gitlab to Deploy Laravel App to Shared Hosting via SSH

I developed some small sites for organizing events with my friends or supporting some blogs all hosted on a shared hoster service in Switzerland (if you are considering using cyon too, please use my referral link at the end of this blog post).

Sometimes I have to quickly fix or change things and then annoy me that it is so tedious to connect via ssh and do everything right when updating the latest version of the app. In the case of Laravel I have to clear the caches and install newest composer packages.

As I use Gitlab for some other projects together with Laravel Forge (https://forge.laravel.com/, Also a great service to use with your own VPS), I searched a way to automate this in a more restricted shared hosting environment.

Here is how I did it.

Setup Project

Just setup the Site as you as you would normally do. Then checkout your project via git from gitlab. In this example it’s done with the following:

Of course you have to setup the DNS but I’ll not cover that here.

Configure CI/CD

Just study the following Guide to to the whole thing together with Laravel Envoy (what I haven’t used yet).
https://docs.gitlab.com/ce/articles/laravel_with_gitlab_and_envoy/index.html

This guide works without Laravel’s Envoy.

Add cat ~/.ssh/id_rsa.pub to deploy keys of your repository in gitlab.

Environmen Variables set (don’t want them to be in my configs!):

  • $SERVER_PROD
  • $SERVER_USER
  • $PROD_PATH
  • $SERVER_PROD_ADDRESS

Use this .gitlab-ci.yml config:

build.sh (run in docker image mightycode/docker-laravel-dusk:latest or any other php testing docker container image)

install.sh (Run via ssh on server to simplify process)

 

Configure Runner for better Performance

Don’t forget to configure cache correctly on the runner (Safes a lot of time!)
sudo vim /etc/gitlab-runner/config.toml

My Actual runner config

sudo gitlab-ci-multi-runner restart

Support this Post by using my referral link: https://order.cyon.ch/affiliate/cyon_webhosting_35cfc725-58cc-4d34-9d3a-c80b324e828b

Leave a Reply

Your email address will not be published. Required fields are marked *