Advanced Methods for Installing Magento 2
You can also install Magento in several other ways:
Method 1: Using Composer
1. Pre-Installation
Before proceeding, check that you have configured the server, created the Magento file system owner, and set up a Magento cron job for command line execution.
After that, install the composer and finish the prerequisites.
Note: You will need the authentication keys in your Magento account.
2. Log in as the file system owner
Become the file system owner by logging into Magento or changing to a writable user.
If you are using the bash shell, use the following directive to change to the Magento file system owner and enter the command at the same time:
su <Magento file system owner> -s /bin/bash -c <command>
Adding magento_root>/bin
to your PATH variable will allow you to execute Magento commands from anywhere. Below is an example of the CentOS bash shell:
export PATH=$PATH:/var/www/html/magento2/bin
3. Get the Setup
Here’s what you need to get the Magento meta-package:
- Log in or switch to Magento file system owner on your server.
- Enter the web server’s docroot or the virtual host’s docroot.
- Command to create a Composer project with Magento Commerce or Magento Open Source meta-package:
For Commerce:
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition <install-directory-name>
For Open Source:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition <install-directory-name>
Once prompted, you will need to provide the authentication keys.
The setup wizard will complete the installation process once you have completed all these steps.
Method 2: Using GitHub
Installing Magento without sample data:
- Clone the Magento repository from GitHub. You can check out the previous Magento releases.
- Using the following command, create a new empty directory:
git clone git@github.com:magento/magento2.git
- Wait until the deployment finishes and then execute this command.
composer install
- Install Magento
Below is a provided example of the command to install Magento 2.
Note: Modify the base-url, db-name, db-password, admin-email, and admin-password. They need to be appropriate for your local setup.
php -f bin/magento setup:install -base-url=http://m2.loc/2.07/github/ --backend-frontname=admin --db-host=localhost --db-name=m2git --db-user=root --db-password=inchoo --admin-firstname=Magento --admin-lastname=User --admin-email=ivan.veres@inchoo.net --admin-user=admin --admin-password=admin123 --language=en_US --currency=USD --timezone=America/Chicago -use-rewrites=1
- Open a browser window and go to your local URL.
Method 3 Using sample data:
- Go to your webroot (not magento).
- Run this command to clone the Magento directory:
git clone git@github.com:magento/magento2-sample-data.git
- Go to the cloned directory.
- Run this command:
php -f dev/tools/build-sample-data.php -- --ce-source="your Magento CE install dir"
This creates Symlinks to the Magento installation.
- Set ownership and permissions on your Linux machine:
chown -R :your web server group name
find . -type d -exec chmod g+ws {} \;
- Now go to Magento var/ folder to clear the cache (static files) by running the following command:
rm -rf cache/* page_cache/* generation/*
- Finally, run these commands to install sample data:
php bin/magento setup:upgrade
php bin/magento setup:di:compile
Installing Magento 2 sample data via the
command line
Installing Magento 2 via the shell is not new. In the current Magento version, it was already
possible using the install.php fi le. The confi guration looked like this:
/usr/local/bin/php -f install.php -- \
--license_agreement_accepted "yes" \
--locale "en_US" \
--timezone "America/Los_Angeles" \
--default_currency "USD" \
--db_host "mysql.example.com" \
--db_name "your_db_name" \
--db_user "your_db_username" \
--db_pass "your_db_password" \
--db_prefix "" \
--admin_frontname "admin" \
--url "http://www.examplesite.com/store" \
--use_rewrites "yes" \
--use_secure "no" \
--secure_base_url "" \
--use_secure_admin "no" \
--admin_firstname "your_first_name" \
--admin_lastname "your_last_name" \
--admin_email "your_email@example.com" \
--admin_username "your_admin_username" \
--admin_password "your_admin_password"
It was very easy to script and use multiple times on any given environment.
In Magento 2, the logic stayed the same but now, it's much easier to use. We will be using a
composer.json fi le for our setup prerequisites.