Get started with an environment

Common commands

The following commands can be run from any directory. However, it’s simpler to run them from a project directory. If so, you can omit the -p <project ID> parameter. These commands are meant to be used to manage integration environments.

All commands are shown with required options only. Get help for any magento-cloud command by appending --help.

git commit --allow-empty -m "redeploy" && git push <branch name>
Push an empty commit to force a redeployment. Some actions, like adding a user for example, don’t result in deployment.
magento-cloud login
Log in to the project
magento-cloud project:get <project ID> <directory> -e <environment ID>
Clone a project to a directory. To clone the master environment, omit -e <environment ID>.
magento-cloud environment:list -p <project ID>
List the environments in the current project (that is, the project that corresponds to the directory in which you run the command).
magento-cloud environment:branch <name> <parent branch>
Create a new branch (that is, environment); the environment has both a name and an ID

The environment name is different from the environment ID only if you use spaces or capital letters in the environment name. An environment ID consists of all lowercase letters, numbers, and allowed symbols. Capital letters in an environment name are converted to lowercase in the ID; spaces in an environment name are converted to dashes.

An environment name cannot include characters reserved for your Linux shell or for regular expressions. Forbidden characters include curly braces ({ }), parentheses, asterisk (*), angle brackets (< >), ampersand (&), percent (%), and other characters.

magento-cloud environment:checkout <environment ID>
Check out an existing environment
magento-cloud environment:merge -p <project ID> -e <environment ID>
Merge changes in this environment with its parent.
magento-cloud environment:synchronize -p <project ID> -e <environment ID> {code|data}
Synchronize (that is, git pull) code and/or data from the parent to this environment
magento-cloud variable:list
List variables in this environment
magento-cloud variable:set <name> <value>
Set a value for an environment variable in this environment

SSH to an environment and run commands

This section discusses how to SSH to an environment so you can run commands as if you were logged in to the environment itself.

Step 1: Get started

  1. Log in to your local development machine, or switch to, the Magento file system owner.
  2. Change to a directory to which the Magento file system owner has write access, such as the web server docroot.
  3. Log in to your project:

    magento-cloud login
    
  4. List your projects:

    magento-cloud project:list
    
  5. If necessary, clone a project.

    magento-cloud project:get <project ID>
    

    Typically, you should clone the project in the web server’s docroot or a Virtual Host docroot.

  6. Change to a project directory.

    For example, cd /var/www/html/magento2

  7. List environments in the project:

    magento-cloud environment:list
    

    magento-cloud environment:list displays environment hierarchies whereas git branch displays does not. If you have any nested environments, use magento-cloud environment:list.

  8. Fetch origin branches:

    git fetch origin
    
  9. Check out an environment:

    magento-cloud environment:checkout <environment ID>
    

    To create a new environment, use magento-cloud environment:branch <environment name> <parent environment ID>

  10. Pull updated code:

    git pull origin <environment ID>
    
  11. Create a snapshot of the environment.

    magento-cloud snapshot:create -e <environment ID>
    

Step 2: SSH to the environment

To SSH to the environment, see SSH into your environment.

Step 3: Enter commands

Now you can connect to services as if they were running locally.

  1. SSH to the integration environment.

    magento-cloud ssh
    
  2. Find the database login information:

    php -r 'print_r(json_decode(base64_decode($_ENV["MAGENTO_CLOUD_RELATIONSHIPS"]))->database);'
    

    Sample output follows:

    Array
       (
          [0] => stdClass Object
            (
               [username] => user
               [password] =>
               [ip] => 192.0.2.60
               [host] => database.internal
               [query] => stdClass Object
                  (
                    [is_master] => 1
                  )
    
               [path] => main
               [scheme] => mysql
               [port] => 3306
            )
        )
  3. Use the following command to connect to the database:

    mysql --host=<host> --user='<database user name>' --password='<user password>' --port='<port>' --database='<path>'