Magento 2 – Auto Install Shell Script

command lineinstallationmagento2

I am wondering is it possible to install Magento 2 with a shell script?

Like we run shell script and Magento 2 will be installed automatically?

Just like softaculous on cpanel ?

Any help will be appreciated.

Thanks.

Best Answer

I created a shell script for installing automatically Magento2 with composer, the script is on GitHub

The shell file contains that:

This file has the .sh extension.
In .sh file, you must change the value of variables.

#!/usr/bin/env bash

# Magento install variables
dbhost="localhost"
dbname="dbname"
dbuser="dbuser"
dbpass="dbpass"
base_url="http://domain.com/"
admin_firstname="FirstName"
admin_lastname="LasteName"
admin_email="email@domain.com"
admin_username="admin"
admin_pass="admin123+"
language="en_US"
backend_frontname="admin"
mage_mode="developer"

while test $# -gt 0; do
    case "$1" in
        -h|--help)
            echo "options:"
            echo "-h, --help                                Show brief help"
            echo "-r, --run-instalation=DIR                 Run Instalation"
            echo "-rs, --run-instalation-sampledata=DIR     Run instalation with sampledata"
            exit 0
            ;;
        -rs|--run-instalation-sampledata)
            shift
                echo Start composer instalation project;
                composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento;
                echo Start SampleData deploy;
                php -d memory_limit=-1 magento/bin/magento sampledata:deploy;
                echo Start Magento install;
                php -d memory_limit=-1 magento/bin/magento setup:install --base-url=$base_url --db-host=$dbhost --db-name=$dbname --db-user=$dbuser --db-password=$dbpass --admin-firstname=$admin_firstname --admin-lastname=$admin_lastname --admin-email=$admin_email --admin-user=$admin_username --admin-password=$admin_pass --language=$language --backend-frontname=$backend_frontname --use-sample-data --magento-init-params="MAGE_MODE=$mage_mode";
                echo Start compilation;
                php -d memory_limit=-1 magento/bin/magento setup:static-content:deploy;
            shift
            ;;
        -r|--run-instalation)
            shift
                echo Start composer instalation project;
                composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento;
                echo Start Magento install;
                php -d memory_limit=-1 magento/bin/magento setup:install --base-url=$base_url --db-host=$dbhost --db-name=$dbname --db-user=$dbuser --db-password=$dbpass --admin-firstname=$admin_firstname --admin-lastname=$admin_lastname --admin-email=$admin_email --admin-user=$admin_username --admin-password=$admin_pass --language=$language --backend-frontname=$backend_frontname --magento-init-params="MAGE_MODE=$mage_mode";
                echo Start compilation;
                php -d memory_limit=-1 magento/bin/magento setup:static-content:deploy;
            shift
            ;;

        *)
            echo "The initialization process was not performed!"
            break
            ;;
    esac
done

The Readme file contains that:

The command for your helper of this script is:

sh m2_install.sh -h
sh m2_install.sh --help

Result:

options:
-h, --help                                Show brief help
-r, --run-instalation=DIR                 Run Instalation
-rs, --run-instalation-sampledata=DIR     Run instalation with sampledata
The command to installing Magento 2 without sample data is:

sh m2_install.sh -r
sh m2_install.sh --run-instalation

The command to installing Magento 2 with sample data is:

sh m2_install.sh -rs
sh m2_install.sh --run-instalation-sampledata

For create alias of script, view example:

alias m2i="/your/sh/file/path/file.sh"


After created alias of script, you can run next commands:
With sample data:

m2i -rs
m2i --run-instalation-sampledata

Without sample data:

m2i -r
m2i --run-instalation

Related Topic