Deploy Magento2 using Gitlab pipelines and Deployer PHP
Versione Italiana

Leggi questo articolo in italiano: click here

This guide is for a single frontend node and is not fully optimized. The configuration is for Production and Staging but we use only staging environment.

This is an implementation of Magento Pipeline Guidelines:

Magento Version: >= 2.2.x

Follow this project to have an example:


  • gitlab account
  • magento project with a local setup (so you have a config.php on your repository)
  • ssh access of deployment server
  • you know how deployer php works

Create a deploy ssh-key to access to your server

ssh-keygen -t rsa -b 4096 -N '' -f my_ssh_key

Create an ssh-keyscan of your server

ssh-keyscan -t rsa magento.staging > server_keyscan.txt

Add public deploy ssh key to the server

ssh-copy-id -i [email protected]

Create the project folder on the server

ssh [email protected]
mkdir /home/admin/magento
mkdir /home/admin/magento/bucket

Add Gitlab Variables for Pipeline

Go to Settings > CI/CD > Variables and add these variables:

For Stage environment

STAGE_HOST -> ip or domain of your web machine (ex. magento.staging)
STAGE_HOST_DEPLOY_PATH -> absolute path where you put your source code (ex. /home/admin/magento)
STAGE_SSH_KEYSCAN -> output of the file server_keyscan.txt
STAGE_SSH_PRIVATE_KEY -> output of the file my_ssh_key
STAGE_USER -> ssh user for server access (in our example admin)

Add gitlab pipeline files in your project

Use this project to add Gitlab Pipeline:

Go to Settings > CI/CD > General pipelines settings and add pipelines/gitlab/.gitlab-ci.yml under Custom CI config path


In this case pipeline start only with develop branch. In any case, we need to have .gitlab-ci.yml on default branch (master) or the pipeline doesn't start Also, first deploy/release will fail because we don't have any setup completed in the server

Create/compile Magento env.php on server

Once fist deploy (with error) is finished you have this folder tree:


edit /home/admin/magento/shared/htdocs/app/etc/env.php to make your magento setup.

Try to re-deploy. This time you can have the pipeline completed.



  • create a system for multinode web server
  • managing in a secure way ssh private key

Improve the project

Send me a feedback

Write me a line or open an issue on github.

Blog Comments powered by Disqus.