Using Gitpod on an existing Magento 2 project

We'll take a look at how to add the Gitpod files to your existing Magento 2 project

Integrate Gitpod on an existing project Video

Testing Gitpod in your existing Magento repo

To get started copy our Magento Repo contents into the root of your Magento project repository. If you already have the core Magento project files in the repository then you can skip the composer create-project  part of the and just let it composer install the decencies of your existing composer.json. 

Importing an existing Magento 2 database

There is a section of the file that can be uncommented out, this will install your exiting staging database, replacing all URLS in the .sql file with the Gitpod instance URLs. 

Magento 2 db install section

What about pub/media files?

The following hack is a quick way of having the site show all images but not require a local copy. Edit the pub/get.php file and add the following code, this will look at the live domain if no local file is found. 

*Warning, please understand how this works before trying it. This will cause lots of requests to the live domain, hopefully your static assets on live are served via a CDN, but if you have issues with images not on live you may find lots of 404 requests to the live domain, don't go DDOS' your own site, use with caution!

Editing Files

Once an instance has started and it's ready to work, your workspace files are already directly checked out from Git, and any changes you make can be committed and pushed directly without any additional authentication or setup. 

You can edit the files via VSCode or PHPStorm directly on the instance! 

What's required to get started with Magento?

I wanted to keep the gitpod files added to the project root to a minimal, so all configuration files goes in the gitpod folder. The .gitpod.yml and .gitpod.Dockerfiles are the only files required at the root. 

Gitpod files

The contents of the gitpod folder are as follows, 

Most of these are straight forward service configuration that most Magento developers are familiar with. Update these files as needed to support the projects requirements.

The only file that won't be familiar is This is responsible for the Magento application installation, so it will git checkout the required Magento 2 version, install all dependances, remove modules that aren't needed for development env's 2FA CSP etc. 

Use this file to configure the Magento application as needed, for local development. 


This the main file used by Gitpod to orchestrate the build process, this tells Gitpod to build the server as explained in the Docker file. You can adjust the DockerFile to change PHP/MySql versions etc, any changes to the DockerFile will cause Gitpod to rebuild the image used. After a rebuild anyone else loading that project will use the pre-built image, speeding up deployment. 

After an image is built Gitpod will then run the tasks of the .gitpod file. You can learn more about the different tasks and when they run during the build and deployment lifecycle process here.

Our Magento command task is here, 

There might seem a lot of commands here but the main purpose of them is to configure the services, php/mysql etc for the current workspaces URL and directory structure, as each instance is given unique urls on creation and directory names per project. 

The last line is what's responsible to ensure Magento is installed on this instance only once, per startup. This speeds up the deployment start up time, and enables you to keep database / Magento admin changes while working on the workspace instance. 

Starting and stopping Instances

Gitpod workspaces can be stopped and started at any time, a workspace will be stopped if idle for more than an hour, or it can be extended to 3 hours idle as needed. 

Having an instance stop is not the end of the world, here are some rough estimates on start up time, from opening an instance to seeing the Magento site start in the browser. 

Start up times

- First time anyone has built a specific project : 15 mins

- Starting a project from a prebuilt image :  5 mins

- Opening a project that has been started and is idle : 10 seconds

View our Magento 2 Gitpod Repo on the link below





Ready to start your next project?

See how we can help you accelerate your business