2

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.

  • Which operating system do you want? Exist a control interface (WHM/cPanel) on the operating system? because you need to create a data base. – St3phan Sep 5 '17 at 6:49
  • I am using blank ubuntu which is pre configured for magento2 I just need script that can make auto install with .sh script. I don't need to store any installation details in db – Dhaval Solanki Sep 5 '17 at 12:04
  • When the Magento installation is running, the database structure is created and then the database is populated, this is part of the installation. Or do you want that .sh file to set you all you want (EX: dbname, dbuser, dbpass, ...)? – St3phan Sep 5 '17 at 18:44
  • Yes I want to create sh file which can manage it all. I can specify db name in variable of sh file then it can use that and install it automatically. – Dhaval Solanki Sep 6 '17 at 4:14
2

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

0

Have a look at magerun2 (https://github.com/netz98/n98-magerun2)

You can use it to install magento2 like

$ n98-magerun2.phar install --dbHost="localhost" --dbUser="mydbuser" --dbPass="mysecret" --dbName="magentodb" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-ce-2.0.0.0-dev-beta1" --installationFolder="magento2" --baseUrl="http://magento2.localdomain/"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.