Magento – How to configure Magento 2 Theme/Design via the Command-Line

cliconfigurationlinuxmagento2theme

I'm doing some server configuration related tasks and was looking for a way to configure the theme of a store/website via the command-line.

I'm setting up a store with a custom theme (e.g. "Vendor/code") and I would like to activate it without entering the adminhtml website but set the theme on the command-line / in the shell / bash script.

Best Answer

I was not able to find a direct Magento CLI command so far, I could work around with a Bash and Magerun:

$ THEME_ID="$(n98-magerun2.phar dev:theme:list --format=csv \
  | grep 'Vendor/code' | cut -d, -f1)" \
  ; test -n "${THEME_ID}" \
  && n98-magerun2.phar config:set design/theme/theme_id "${THEME_ID}"

This sequence sets the configuration path for the theme_id to the one of the named theme (by it's code, which is "Vendor/code" in the example).

In case the operation fails, this has a non-zero status.