MAGENTO CLOUD – HOW TO SETUP A LOCAL ENVIRONMENT?

Magento 2 is a leading eCommerce Platform, available for enterprise and community.

Magento Commerce (Cloud) was formerly known as Magento Enterprise Cloud Edition, introduced in early 2016 as Magento’s third platform option, alongside Magento Commerce and Magento OpenSource. 

Magento 2 Cloud offers services as a platform based on Amazon Web Services (AWS) global infrastructure. To access Magento Cloud and work on your store, you should have a Magento Commerce (Cloud) Account. This account provides access to all projects for developing and deploying them across all supported environments.

All environments for a project are read-only. If we work in any environment, it requires work to be done in the local environment first and pushed to the cloud environment. To start working and developing on Magento, you need:

  1. A configured local workspace,
  2. Cloned Magento Commerce Cloud Code from your Git branch

Here in this article, you will see the instructions to help you create a local workspace for development on your local system.

If you are a Magento Developer, you will need access to Magento Cloud Project. For that, the Project Owner (https://devdocs.magento.com/guides/v2.0/cloud/onboarding/onboarding-tasks.html) will invite you to access the project in your company’s or individual Magento Commerce Cloud Account to connect it to the local one. It will give you access to all source code and deployment environments. To work on a project, you will receive an email invitation to verify and access the project. Click the Verify my Account option in the email. When you log on to your account and have access to multiple projects, you will see the list of all projects. Select the specific project which will open with a master branch to work with.

Install Magento Prerequisites:

We assume that you have LINUX/MAC-based host computer. For Magento development, the following software packages and tools should be installed:

Virtual machine or container (host):

It is recommended (but optional) to install VM for developing and managing your host. The following packages can be used for VM:

  1. Vagrant (https://www.vagrantup.com/docs/) for a virtual machine
  2. Docker (https://docs.docker.com/) for a container

Development Tools

  1. GIT (https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) – provides code branching and management for accessing Magento Commerce and code repositories. For more information, see How Cloud uses Git (https://devdocs.magento.com/guides/v2.0/cloud/reference/git-integration.html).
  2. Composer: It is used for dependency management and enables the developer to manage the Magento components and their dependencies. For more information, see How Cloud uses Composer (https://devdocs.magento.com/guides/v2.0/cloud/reference/cloud-composer.html).

Web Server:

Nginx (https://devdocs.magento.com/guides/v2.0/install-gde/prereq/nginx.html) is strongly recommended though Magento Commerce Cloud supports Apache (https://devdocs.magento.com/guides/v2.0/install-gde/prereq/apache.html) too.

PHP (local):

Install PHP on your local machine (PHP 7.0 is recommended).

Set up PHP Memory Limit:

To set memory_limit, open php.ini in a text editor and set the value to at least 1G and 2G for debugging. Then restart the webserver – service apache2 restart for Apache and service nginx restart for Nginx.

Database (Local):

These are the options for the database:

  1. MariaDB (recommended) (https://mariadb.org/)
  2. MYSQL

Magento Cloud CLI (local)

The Magento Cloud command-line interface (CLI) tool helps manage projects and code branches on Magento Commerce Cloud. You can check the list of CLI commands here(https://devdocs.magento.com/guides/v2.0/cloud/reference/cli-ref-topic.html). 

The following are the steps to install Magento Cloud CLI in LINUX/MAC:

  1. Open a terminal with root privileges.
  2. Create a Magento File Owner by following these steps:
    1. sudo adduser magento_user
    2. It will ask for a password. Enter the desired password
    3. Now, it will ask for user information for magento_user – Full Name, Room Number, Work Phone, Home Phone, Others.
    4. Assign user to www-data group: usermod -g www-data magento_user
    5. Assign user to the root group: usermod -g root magento_user
    6. Restart Apache: service apache2 restart
  3. Switch to magento_user: su magento_user
  4. Change to a directory to which the Magento file system owner has written access, such as the home directory. cd /home/magento_user/
  5. Install the Magento Cloud CLI:
    1. Run: curl -sS https://accounts.magento.cloud/cli/installer | php. It will install Magento Cloud CLI.
    2. To use the Magento Cloud CLI, run: source /home/magento_user/.bashrc
    3. You can also add the following path into the Magento user’s path.
      1. export PATH=$PATH:/home/magento_user/.magento-cloud/bin
    4. To check if it has been installed, run a Magento-cloud list, and you will see the list of commands. Following is the screenshot:

ENABLE SSH KEYS:

The SSH Protocol (https://en.wikipedia.org/wiki/Secure_Shell) is designed to maintain a secure connection between two systems – in this case, the local working environment, and Magento Commerce Cloud Git project.

An SSH key pair should be created on a local work machine to work with and access Magento Commerce Cloud and GitHub Branches. The SHH Keys supports the connection to GitHub for managing branches and pushing the code.

Following are the steps to create SSH Keys:

  1. Open a terminal and log in as Magento File Owner.
  2. Run this command – ssh-keygen -t rsa -b 4096 -C “your_email@whatever_name.com”. Here, the email id should belong to GitHub Account.
  3. Enter a file in which to save the key (/home/magento_user/.ssh/magento_user_rsa): [Press enter]
  4. Enter passphrase (empty for no passphrase): [Type a passphrase]
  5. Enter same passphrase again: [Type passphrase again]
  6. Run: eval “$(ssh-agent -s)”
  7. Run: ssh-add /home/magento_user/.ssh/magento_user_rsa

Following are the steps to add a public SSH key into your Magento Commerce Cloud Account:

  1. Open a terminal application on your local.
  2.  Log in with Magento File Owner and go to its home directory.
  3.  To log on to Magento Cloud Account, run -magento-cloud auth:password-login
  4. It will ask for login. Enter the username and password of your Magento Commerce Cloud Account. Or run the following command to log in through the browser:
  5. magento-cloud auth:browser-login
  6. It will redirect you to the browser for logging in. If it does not find the protocol and shows an error message, it will suggest you open a localhost URL manually. For instance – http://127.0.0.1:5000. When you open this URL, it will show you the following:
  7. It will be logged in, and the following will be displayed:
  1. Now, to add the ky, run:
  2. Magento-cloud ssh-key:add /home/magento_user/.ssh/magento_user_rsa
  3. It will ask to enter the name of the key. Enter the key name. For instance –
  4. MagentoCloudProject
  1. Run: git config –global user.name “<Your name>”
  2. Run: git config –global user.email <Your GitHub Account email id>

Following are the steps to add your SSH keys into your GitHub account:

  1. Open a new terminal with root privilege. Copy the SSH key to your clipboard by running the following commands:
  2. sudo apt-get install xclip
  3. xclip -sel clip < /home/magento_user/.ssh/id_rsa.pub
  4. Now, go to GitHub.com and log in to your account.
  5. Go to Settings
  6. Create a New SSH Key
  7. Enter Title and paste Key into Key field.
  8. Click ADD SSH KEY button.
  9. It will ask you to re-enter the Git password to verify it’s you.

After adding the SSH keys, test the SSH connection to GitHub by running the following command:

  1. ssh -T [email protected]
  2. It will show you a successful message if everything is fine. If it shows any error or a Permission Denied issue, click here(https://help.github.com/articles/error-permission-denied-publickey/) to check the solution. Following is the screenshot.

CLONE THE PROJECT MASTER BRANCH:

These are the steps for cloning a branch (master) of a project:

Run: magento-cloud project:list
Run: magento-cloud project:get <project ID>
Run: magento-cloud environment:list
Run: git fetch magento
Run: git pull magento <environment ID>
Run: cd <dirname>
Run: magento-cloud build