This bash script helps you quickly install Magento 2 from different sources (tar
, composer
, etc.) with optional sample data — perfect for development setups.
Download the script and make it executable:
curl -O https://raw.githubusercontent.com/MagePsycho/magento2-installer-bash-script/master/src/m2-installer.sh
chmod +x m2-installer.sh
To make it a system-wide command (preferred):
sudo mv m2-installer.sh /usr/local/bin/m2-installer
Or for user scope:
mv m2-installer.sh ~/bin/m2-installer
⚠️ Make sure your$HOME/bin
folder is in your$PATH
.
m2-installer --help
m2-installer --version=2.4.8 --base-url=magento248.test --install-sample-data --db-user=root --db-pass=pass --db-name=magento248
--install-sample-data
is required to include sample data.
Install via Composer:
m2-installer --source=composer --version=2.4.8 --base-url=magento248.test --install-sample-data --db-user=root --db-pass=pass --db-name=magento248
If --source
is not passed, tar
is used by default.
Magento >= 2.4.0 defaults to Elasticsearch, and >= 2.4.8 prefers OpenSearch.
Make sure you have the right service installed before running the installer.
--search-engine
(default:elasticsearch7
)--elasticsearch-host
(default:127.0.0.1
)--elasticsearch-port
(default:9200
)--elasticsearch-index
(default:magento2
)
--search-engine
(default:opensearch
)--opensearch-host
(default:127.0.0.1
)--opensearch-port
(default:9200
)--opensearch-index
(default:magento2
)
Examples:
m2-installer --version=2.4.7 --base-url=magento247.test --db-user=root --db-pass=pass --db-name=magento247 --search-engine=elasticsearch7 --elasticsearch-host=127.0.0.1
m2-installer --version=2.4.8 --base-url=magento248.test --db-user=root --db-pass=pass --db-name=magento248 --search-engine=opensearch --opensearch-host=127.0.0.1
To use redis
for sessions, frontend, and full-page cache:
--use-redis-cache
(required)--redis-host
(default:127.0.0.1
)--redis-port
(default:6379
)
Example:
m2-installer --version=2.4.8 --base-url=magento248.test --db-user=root --db-pass=pass --db-name=magento248 --use-redis-cache
Skip confirmation prompts and clean the directory before installation:
m2-installer --version=2.4.8 --base-url=magento248.test --db-user=root --db-pass=pass --db-name=magento248 --force
Instead of passing flags every time, you can use a config file:
- Global:
~/.m2-installer.conf
- Local/project:
./.m2-installer.conf
Copy the sample config:
curl -O https://raw.githubusercontent.com/MagePsycho/magento2-installer-bash-script/master/.m2-installer.conf.dist
cp .m2-installer.conf.dist ~/.m2-installer.conf
Edit to set defaults like DB credentials, search engine, Redis, etc.
Then run simply:
m2-installer --version=2.4.8 --base-url=magento248.test --use-secure --force
m2-installer --self-update
Works for version
> 0.1.2
1. Use with Warden
cd /path/to/warden/m2/project
warden shell
Inside the container:
m2-installer --version=2.4.8 --install-sample-data --use-secure --base-url=app.<project>.test --db-host=<project>_db_1 --db-user=magento --db-pass=magento --db-name=magento --elasticsearch-host=<project>_elasticsearch_1 --use-redis-cache --redis-host=<project>_redis_1 --force
Use this free bash script: nginx-virtual-host-bash-script
sudo vhost-nginx --domain=magento248.test --app=magento2
- Config files support (
~/.m2-installer.conf
or./.m2-installer.conf
) - Install via Composer
- Create virtual host (nginx)
- Multiple compression types (
.gz
,.zip
,.tar.bz2
) - Install Magento 2 EE
- Install via Git clone
- System readiness checks (PHP, MySQL, Nginx/Apache, etc.)
- Crontab setup
- Migration with local codebase + DB
Developed & maintained by MagePsycho
Licensed under OSL 3.0