Install Magento 2 with one command (Valet+ only)

Composer, Laravel, Magento, Valet Plus+, Quick Tip, Tooling

For my daily work as a freelancer i tend to use a lot of disposable environments: I use them to check a bug in that specific version for example, and them throw them away. Setting up Magento can be a lengthy process, but with this one liner i can bring it down to ~10 minutes, depending on you internet & cpu speed. It installs the required Magento version including sample data.

MageTested.com (ad)

Do you want your Magento store to be more reliable? Tired of things that suddenly break the checkout process without anyone noticing? You can hire my services to kickstart End-2-End testing for your Magento store. This way you know for sure that your store is behaving as expected before releasing that new feature or that update.

View MageTested.com for more information.

This one-liner uses some specific Laravel Valet+ commands to create the database, you can change it to your liking.

export DBNAME=${PWD##*/} && \
export BASEURL="$DBNAME.test" && \
export MAGENTO_VERSION='2.3.2' && \
export MAGENTO_TYPE='project-community-edition' && \
valet db drop -y && valet db create && \

composer create-project --repository-url=https://repo.magento.com/ magento/$MAGENTO_TYPE=$MAGENTO_VERSION . && \

mkdir var/composer_home && \
ln -s ~/.composer/auth.json var/composer_home/auth.json && \
php bin/magento sampledata:deploy && \

php bin/magento setup:install --backend-frontname=admin --session-save=db --db-host=localhost --db-name=$DBNAME --db-user=root --db-password=root --base-url=http://$BASEURL --timezone=Europe/Amsterdam --currency=EUR --admin-user=michiel --admin-password=asdfasdf1 [email protected] --admin-firstname=Michiel --admin-lastname=Gerritsen --use-rewrites=1 && \

php bin/magento deploy:mode:set developer && \
valet open

That's the script, let's go over the steps.

This is defining the variables:

  • DBNAME: The name of the database. It is the same as the current directory.

  • BASEURL: It uses Valet's default: The directoryname + test.

  • MAGENTO_VERSION: That speaks for itself.

  • MAGENTO_TYPE: project-community-edition or project-enterprise-edition.

export DBNAME=${PWD##*/} && \
export BASEURL="$DBNAME.test" && \
export MAGENTO_VERSION='2.2.6' && \
export MAGENTO_TYPE='project-community-edition' && \

If there is already a database, drop it and create a new one:

valet db drop -y && valet db create

Run the composer command to download and install all required files:

composer create-project --repository-url=https://repo.magento.com/ magento/$MAGENTO_TYPE=$MAGENTO_VERSION .

Create the composer_home folder and link your Composer credentials to it. If you skip this you end up entering them again:

mkdir var/composer_home && \
ln -s ~/.composer/auth.json var/composer_home/auth.json

Add the sample data, this can take some time:

php bin/magento sampledata:deploy

Actual install Magento into the database. You can change it to you liking. Use you timezone or preferred admin url for example. These settings are find for me.

php bin/magento setup:install --backend-frontname=admin --session-save=db --db-host=localhost --db-name=$DBNAME --db-user=root --db-password=root --base-url=http://$BASEURL --timezone=Europe/Amsterdam --currency=EUR --admin-user=michiel --admin-password=asdfasdf1 [email protected] --admin-firstname=Michiel --admin-lastname=Gerritsen --use-rewrites=1

Change to developer mode and open the new webshop in your browser:

php bin/magento deploy:mode:set developer && \
valet open

Running it

So how do you use it? Simple, go to the directory where you hold all your sites. Create a new directory, for example magento230os if you're going to install Magento 2.3 open source. cd into it and then run the script. Now you just wait a few minutes and you are ready to go.