Install Magento

Previous step:

Clone and branch the project

With your workspace prepared, install Magento on your local to verify custom code, extensions, and more. This section includes the installation prep, options, and post-installation configuration you should complete.

Prepare to install Magento

To be able to customize the Magento software on your local machine, you should install it using the following information:

  • Host name or IP address of your machine
  • Admin user name, password, and URL you created earlier
  • Magento authentication keys for installing Magento locally

Get Magento Admin environment variables

You will need the Admin environment variable values for the installation command line.

  1. Log in to your local development system, or switch to, the Magento file system owner.
  2. Change to a directory to which the Magento file system owner has write access.
  3. Enter the following command in a terminal to log in to your project:

     magento-cloud login
    
  4. Before you begin, list the environment variables.

     magento-cloud variable:get -e <environment ID>
    

The following results provides an example of variables:

+----------------+---------------+-----------+------+
| ID             | Value         | Inherited | JSON |
+----------------+---------------+-----------+------+
| ADMIN_PASSWORD | admin_A456    | Yes       | No   |
| ADMIN_URL      | magento_A8v10 | Yes       | No   |
| ADMIN_USERNAME | admin_A456    | Yes       | No   |
+----------------+---------------+-----------+------+

Get Magento authentication keys

You need Magento authentication keys to install Magento locally for your local environment. These are separate to the authentication keys included in the cloud code repository in auth.json.

To create authentication keys through the Magento Marketplace:

  1. Log in to the Magento Marketplace. If you don’t have an account, click Register.
  2. Click your account name in the top-right of the page and select My Profile.
  3. Click Access Keys in the Marketplace tab.

    Click Access Keys

  4. Click Create A New Access Key. Enter a specific name for the keys, for example CloudProductOwner or the name of the developer receiving the keys.
  5. The keys generate a Public and Private key you can click to copy. Save this information or keep the page open when installing Magento Commerce.

Set the docroot

Set the docroot to the /magento directory until you complete all setup. If you change the docroot to /magento/pub prior to completion, you will encounter issues running the Web Setup Wizard.

For the Production environment, you should set the docroot to /magento/pub, which helps restrict access to vulnerable areas of the system. The webserver docroot should be set to /magento/pub only after Magento is installed (including any upgrades and patches), configured, and static files have been generated and populated in /magento/pub. Alternatively, you could also create a subdomain (for example, install.domain.com) and configure your webserver’s docroot to the Magento installed root folder.

Set file system permissions and ownership

After you have installed Magento, you need to set the file system permissions and ownership.

  1. Log in to your Magento server as, or switch to, the Magento file system owner.
  2. Enter the following commands in the order shown:

    cd <your Magento install dir>
    find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \;
    find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \;
      	chown -R :<web server group> .
      	chmod u+x bin/magento
    

To optionally enter all commands on one line, enter the following assuming Magento is installed in /var/www/html/magento2 and the web server group name is apache:

cd /var/www/html/magento2 && find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; && chown -R :apache . && chmod u+x bin/magento

In the event file system permissions are set improperly and can’t be changed by the Magento file system owner, you can enter the command as a user with root privileges:

cd /var/www/html/magento2 && sudo find var vendor pub/static pub/media app/etc -type f -exec chmod g+w {} \; && sudo find var vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} \; && sudo chown -R :apache . && sudo chmod u+x bin/magento

Install Magento

Prior to installing, you should Update installation dependencies using Composer commands.

You should be ready to install Magento using one of the following options:

The following example installs using the command line method:

  1. Switch to the user:

    sudo su - magento
  2. Change directories for the installation:

    cd /app/bin
  3. Enter a CLI command with options for entering the name, email, admin credentials, URL, and additional information. For a list of all options, see Installer help commands.

    php magento setup:install \
       --admin-firstname=John \
       --admin-lastname=Smith \
       --admin-email=jsmith@mail.com \
       --admin-user=admin \
       --admin-password=password1 \
       --base-url=http://magento.local/ \
       --db-host=localhost \
       --db-name=magento \
       --db-user=magento \
       --db-password=magento \
       --currency=USD \
       --timezone=America/Chicago \
       --language=en_US \
       --use-rewrites=1

Post-install configurations

After installing Magento, run the commands for compile and deploy for the code:

  1. If you are not in the correct Magento user, switch:

    sudo su - magento
  2. Change directory to app/bin.
  3. Run the compile command:

     php magento setup:di:compile
    
  4. When complete, Run the deploy command:

     php magento setup:static:deploy
    

Optionally, if you used Vagrant with the hostmanager plugin, update the hosts file:

  1. Access the localdev root for the Vagrant box.
  2. Enter the command vagrant hostmanager to update the hosts file.

Additional software and services

For development and testing in an environment as close to Integration as possible, you may also want to install additional tools, software, and services. These services are configured using services.yaml.

Verify your local workspace

To verify the local, access the store using the URL you passed in the install command. For this example, the local Magento store should load using http://magento.local/. The Admin panel should open using http://magento.local/admin. If you change the URI for the Admin panel, use this command to locate it:

php bin/magento info:adminuri

To verify the Integration master branch environment, log into the Project Web Interface and select your named project. In the list of branches, select the Master. Click Access site to pull up a list of URLs (HTTP and HTTPS) and click the preferred link to open the site. To view the admin, add /admin or other configured Admin URI.

Click Access for list of URLs

With these steps completed, you should have:

  • Magento Commerce account and initial project setup and master branch
  • A local workspace configured with installations of required software, Magento Cloud CLI, and Magento
  • SSH keys set up
  • The Magento file system owner configured
  • Your initial code branch
  • Magento authentication keys set up and configured in the project and local

Next steps:

For Pro projects, we strongly recommend fully deploying this base Magento template master branch without any code or configuration changes to Staging and Production. For instructions, see First time deployment.

For Starter projects, you are ready to start developing.