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:
- A configured local workspace,
- 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:
- Vagrant (https://www.vagrantup.com/docs/) for a virtual machine
- Docker (https://docs.docker.com/) for a container
- 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).
- 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).
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.
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.
These are the options for the database:
- MariaDB (recommended) (https://mariadb.org/)
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:
- Open a terminal with root privileges.
- Create a Magento File Owner by following these steps:
- sudo adduser magento_user
- It will ask for a password. Enter the desired password
- Now, it will ask for user information for magento_user – Full Name, Room Number, Work Phone, Home Phone, Others.
- Assign user to www-data group: usermod -g www-data magento_user
- Assign user to the root group: usermod -g root magento_user
- Restart Apache: service apache2 restart
- Switch to magento_user: su magento_user
- Change to a directory to which the Magento file system owner has written access, such as the home directory. cd /home/magento_user/
- Install the Magento Cloud CLI:
- Run: curl -sS https://accounts.magento.cloud/cli/installer | php. It will install Magento Cloud CLI.
- To use the Magento Cloud CLI, run: source /home/magento_user/.bashrc
- You can also add the following path into the Magento user’s path.
- export PATH=$PATH:/home/magento_user/.magento-cloud/bin
- 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:
- Open a terminal and log in as Magento File Owner.
- Run this command – ssh-keygen -t rsa -b 4096 -C “your_email@whatever_name.com”. Here, the email id should belong to GitHub Account.
- Enter a file in which to save the key (/home/magento_user/.ssh/magento_user_rsa): [Press enter]
- Enter passphrase (empty for no passphrase): [Type a passphrase]
- Enter same passphrase again: [Type passphrase again]
- Run: eval “$(ssh-agent -s)”
- 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:
- Open a terminal application on your local.
- Log in with Magento File Owner and go to its home directory.
- To log on to Magento Cloud Account, run -magento-cloud auth:password-login
- 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:
- magento-cloud auth:browser-login
- 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:
- It will be logged in, and the following will be displayed:
- Now, to add the ky, run:
- Magento-cloud ssh-key:add /home/magento_user/.ssh/magento_user_rsa
- It will ask to enter the name of the key. Enter the key name. For instance –
- Run: git config –global user.name “<Your name>”
- Run: git config –global user.email <Your GitHub Account email id>
Following are the steps to add your SSH keys into your GitHub account:
- Open a new terminal with root privilege. Copy the SSH key to your clipboard by running the following commands:
- sudo apt-get install xclip
- xclip -sel clip < /home/magento_user/.ssh/id_rsa.pub
- Now, go to GitHub.com and log in to your account.
- Go to Settings
- Create a New SSH Key
- Enter Title and paste Key into Key field.
- Click ADD SSH KEY button.
- 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:
- ssh -T [email protected]
- 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