One of the many purposes of Magento Cloud is to save valuable DevOps time and to reduce deployment issues. Although is very convenient to utilize the UI provided by Magento Cloud Web, it is even more time-efficient to do the same tasks via Command-Line (CLI).
First, the Magento Cloud CLI must be downloaded and installed into the computer client:
- Make sure you are logged in as the OS user that will access the cloud resources (not necessarily the root user).
- Install the magento-cloud CLI.
|$ curl -sS https://accounts.magento.cloud/cli/installer | php|
Then, add magento-cloud to the bash profile.
$ export PATH=$PATH:$HOME/.magento-cloud/bin
After that, reload the bash profile
Now you can execute Magento clouds commands by typing magento-cloud or mgc. Please note that when using the console for the first time, you need to login by providing your username and password.
After this, when typing mgc list you will be able to check the available CLI commands; where most of them provide a basic CLI menu for guiding you into the executed procedure.
$ mgc list
After downloading it is recommended that you generate a public SSH key upload it to the project. (Generating an SSH key is out of the scope of this article)
$ mgc ssh-key:add ~/.ssh/id_rsa.pub
Note: When generating any SSH key please keep the default name as “id_rsa.pub”, because by default Magento cloud will look for this specif file name.
WEB UI actions on CLI
For the purpose of imitating the most common Web UI actions you might be interested in check the following commands (In alphabetical order):
db:dump: Create a dump file from the environment selected and downloads it into your computer. No need to mention how convenient is this command that reduces many steps and data transfer between the host and client.
db:sql: Opens the Mysql CLI interface for the specific environment.
environment:active: Activates the selected environment.
environment:branch: Branches an environment. Allowing you to select the parent branch.
environment:list: Lists the current environments for the project(s).
environment:merge: Merges two environments
environment:redeploy: Redeploys an environment without pushing any code. Very convenient when you just need to restart the environment.
environment:ssh: SSH to an environment.
environment:sync: Syncs an environment from its parent.
mount:download: Allows to download files from the environment.
mount:upload: Allows to upload files from the environment.
tunnel:open & tunnel:info: A combination of these commands allows you the get ip addresses, usernames, and passwords of the internal services of any specific environment, such as Elastics Search and Mysql DB, without the need to access the environment directly.
It is worth mentioning that if you would like to explore what param combinations are possible when using the above commands you can always use the “–help” param.
$ mgc –help command
In definitive, using the magento-cloud CLI is not a must when using Magento Cloud, however, when getting used to it will speed up, even more, the clouding experience.