Installing Private Magento Modules Using Our MageRepo Repository

November 21, 2018
Rafael Grigorian

About MageRepo

MageRepo is a set of services that was developed by the JetRails® team. It is all things Magento. One service that MageRepo offers is a custom satis repository for composer. With this private repository, it is possible to host Magento 2 extensions for our customers.

Automatically add repository

Adding the MageRepo repository is simple using the composer cli tool. Through an SSH connection, all you have to do is cd into your Magento installation directory and run the following command:

$ cd <MAGENTO_INSTALLATION>
$ composer config repositories.magerepo composer https://composer.magerepo.com/

The above command will edit the composer.json file that is found in your current directory. If you would like to know what changes it makes, please read the next section on how to add the repository manually.

Manually add repository

On a stock Magento 2 installation, your repositories section of your composer.json file might look something like this:

{
	"repositories": [
		{
			"type": "composer",
			"url": "https://repo.magento.com/"
		}
	]
}

At this point you have two choices and they will influence composer the same regardless of what you choose to do. The two choices are as follows:

Add the repository by appending an object to the repositories array

{
	"repositories": [
		{
			"type": "composer",
			"url": "https://repo.magento.com/"
		},
		{
			"type": "composer",
			"url": "https://composer.magerepo.com/"
		}
	]
}

Convert the repositories array into an object and then add the repository

{
	"repositories": {
		"magento": {
			"type": "composer",
			"url": "https://repo.magento.com/"
		},
		"magerepo": {
			"type": "composer",
			"url": "https://composer.magerepo.com/"
		}
	}
}

Note: If you ran the compose cli command in the automatically add repository section, then the repositories array will be converted to an object but the key of the default magento repository will be 0 instead of magento as depicted above.

List available extensions

Our composer repository can be reached by visiting this URL: https://composer.magerepo.com. By visiting this URL, you can see all the packages/versions that are available for installation through this repository.

Obtaining an account

Our Magento 2 extensions were built for our customers. For this reason, installing an extension requires user authentication using a username/password pair. If you would like to request credentials, please email [email protected] and we will evaluate your eligibility.

Install an extension

Once the MageRepo repository is added to the composer.json file, you can now install the packages that are available through it. For example, let’s say you want to install the jetrails/magento2-varnish extension through composer. You might first be prompted to provide credentials for repo.magento.com. Information on how to obtain these credentials is described by Magento in their article.

$ composer require jetrails/magento2-varnish

  Authentication required (repo.magento.com):
  Username: ••••••••••••••••
  Password: ••••••••••••••••

After you authenticate with Magento, you may be prompted to authenticate with MageRepo if you are attempting to install a private extension. If you are attempting to download an open source extension that is hosted on github.com, then you should not be prompted for additional credentials. Otherwise, private extensions are hosted on git.magerepo.com and credentials are needed in order for composer to clone the extension repository. If you are prompted, then it will look similar to the following:

  Authentication required (git.magerepo.com):
  Username: ••••••••••••••••
  Password: ••••••••••••••••

After composer resolves and downloads the extension, you can install the extension into your Magento instance by using Magento’s CLI binary:

$ php bin/magento setup:upgrade
$ php bin/magento cache:flush

Note: An additional step of logging out of your Magento’s backend may be required in order to refresh any altered ACL resources that the newly installed extension could have caused.

Update an extension

Assuming we are trying to update the jetrails/magento2-varnish extension, then you could run the following to update the module to the latest version:

$ composer require jetrails/magento2-varnish
$ php bin/magento setup:upgrade
$ php bin/magento cache:flush

Conclusion

The MageRepo composer repository allows composer to resolve private packages that JetRails® offers their customers. This process is made easy with the composer CLI tool. Any additional support on this topic can be directed via email to [email protected].