(Integrator) Get the Composer metapackage

Updated: 14 August 2016 (PDT)

Totally lost? Need a helping hand? Try our installation quick reference (tutorial) or installation roadmap (reference).

Contents

Intended audience

The audience for this topic is anyone who downloads the Magento metapackage using composer create-project. If that isn’t you, go back and choose another starting point.

Prerequisites

Before you continue, make sure you’ve done all of the following:

First steps

As an integrator, you want to manage each of your Magento core components and third-party components using the Component Manager and System Upgrade.

To do so, you start by creating a Composer project from our metapackage. The metapackage installs each component so it can be centrally managed after installation.

Commands

If you already have everything set up, you can get the Magento CE and EE metapackages as follows:

CE

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <installation directory name>

EE

composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <installation directory name>

Composer and Magento

We now use Composer for dependency management. Composer enables us to manage the Magento components and their dependencies.

Composer provides you with the following advantages:

  • Enables you to reuse third-party libraries without bundling them with source code
  • Component-based architecture with robust dependency management
  • Manages dependencies to reduce extension conflicts and compatibility issues
  • Versioned dependencies
  • Semantic versioning
  • Supports the PHP Framework Interoperability standard

Install Composer

First, check if Composer is already installed:

In a command prompt, enter any of the following commands:

  • composer --help
  • composer list --help

If command help displays, Composer is already installed.

If an error displays, use the following steps to install Composer.

To install Composer:

  1. Change to or create an empty directory on your Magento server.

  2. Enter the following commands:

    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer
    

    For additional installation options, see the Composer installation documentation.

Get the Magento CE metapackage

To get started:

  1. If you haven’t done so already, get your authentication keys.
  2. Log in to your Magento server as, or switch to, the Magento file system owner.
  3. Change to the web server docroot directory, or to a directory you’ve configured as a virtual host docroot.
  4. Enter the following command:

    composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <installation directory name>
    

    When prompted, enter your authentication keys. Your public key is your username; your private key is your password.

    This command creates the project and downloads dependencies for it. The project is in a directory named <installation directory name> if you provided the parameter or project-community-edition if you did not.

    If the following error displays, see troubleshooting:

    file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory
  5. Continue with Set file system ownership and permissions.

Get the Magento EE metapackage

To get started:

  1. Make sure you know your support portal user name and password.

    If you don’t remember it, contact Magento Support before you continue.

  2. Log in to your Magento server as, or switch to, the Magento file system owner.
  3. Change to the web server docroot directory, or to a directory you’ve configured as a virtual host docroot.
  4. Enter the following command:

    composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <installation directory name>
    

    When prompted, enter your authentication keys. Your public key is your username; your private key is your password.

    The following error indicates your tokens are incorrect:

      Could not find package magento/project-enterprise-edition with version 2.0.0
    

    This command creates the project and downloads dependencies for it. The project is in a directory named <installation directory name> if you provided the parameter or project-enterprise-edition if you did not.

    If the following error displays, see troubleshooting:

    file_get_contents(app/etc/NonComposerComponentRegistration.php): failed to open stream: No such file or directory
  5. Continue with the next section.

Set pre-installation file system ownership and permissions

This topic discusses how to set read-write permissions for the web server group before you install the Magento software. This is necessary so the Setup Wizard or command line can write files to the Magento file system.

The procedure you use is different, depending on whether you use shared hosting and have one user or if you use a private server and have two users.

If you're using a Magento version earlier than 2.0.6, see Appendix—Magento file system ownership and appendix (legacy) instead.

Set permissions for shared hosting (one user)

This section discusses how to set pre-installation permissions if you log in to the Magento server as the same user that also runs the web server. This type of setup is common in shared hosting environments.

Click to show/hide content

To set permissions before you install the Magento software:

  1. Log in to your Magento server.
  2. Use a file manager application provided by your shared hosting provider to verify write permissions are set on the following directories:

    • vendor (Composer or compressed archive installation)
    • app/etc
    • pub/static
    • var
    • Any other static resources
  3. If you have command-line access, 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 u+w {} \;
    find var vendor pub/static pub/media app/etc -type d -exec chmod u+w {} \;
    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:

    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+w {} \; && chmod u+x bin/magento
    
  4. If you haven’t done so already, get the Magento software in one of the following ways:

  5. After you have set file system ownership and permissions, continue with any of the following:

To further restrict permissions after installing the Magento software, you configure a Magento umask.

Set ownership and permissions for two users

This section discusses how to set ownership and permissions for your own server or a private hosting setup. In this type of setup, you typically cannot log in as, or switch to, the web server user. You typically log in as one user and run the web server as a different user.

Click to show/hide content

Complete the following tasks in the order shown:

About the shared group

To enable the web server to write files and directories in the Magento file system but to also maintain ownership by the Magento file system owner, both users must be in the same group. This is necessary so both users can share access to Magento files (including files created using the Magento Admin or other web-based utilities).

This section discusses how to create a new Magento file system owner and put that user in the web server’s group. You can use an existing user account if you wish; we recommend the user have a strong password for security reasons.

Step 1: Create the Magento file system owner and give the user a strong password

This section discusses how to create the Magento file system owner. (Magento file system owner is another term for the command-line user.)

To create a user on CentOS or Ubuntu, enter the following command as a user with root privileges:

adduser <username>

To give the user a password, enter the following command as a user with root privileges:

passwd <username>

Follow the prompts on your screen to create a password for the user.

If you don't have root privileges on your Magento server, you can use another local user account. Make sure the user has a strong password and continue with Put the Magento file system owner in the web server group.

For example, to create a user named magento_user and give the user a password, enter:

sudo adduser magento_user
sudo passwd magento_user

Because the point of creating this user is to provide added security, make sure you create a strong password.

Step 2: Find the web server user’s group

To find the web server user’s group:

  • CentOS: egrep -i '^user|^group' /etc/httpd/conf/httpd.conf

    Typically, the user and group name are both apache

  • Ubuntu: ps aux | grep apache to find the apache user, then groups <apache user> to find the group

    Typically, the user name and the group name are both www-data

Step 3: Put the Magento file system owner in the web server’s group

To put the Magento file system owner in the web server’s primary group (assuming the typical Apache group name for CentOS and Ubuntu), enter the following command as a user with root privileges:

  • CentOS: usermod -g apache <username>
  • Ubuntu: usermod -g www-data <username>

For example, to add the user magento_user to the apache primary group on CentOS:

usermod -g apache magento_user

To confirm your Magento user is a member of the web server group, enter the following command:

groups <user name>

A sample result follows:

magento_user : apache

To complete the task, restart the web server:

  • Ubuntu: service apache2 restart
  • CentOS: service httpd restart

Step 4: Get the Magento software

If you haven’t done so already, get the Magento software in one of the following ways:

Step 5: Set ownership and permissions for the shared group

To set ownership and permissions before you install the Magento software:

  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

Next step

After you have set file system ownership and permissions, continue with any of the following:

Switch to the Magento file system owner

After you’ve performed the other tasks in this topic, enter one of the following commands to switch to that user:

  • Ubuntu: su <username>
  • CentOS: su - <username>

For example,

su magento_user

Next step

Install the Magento software: