You can install a Magento theme in two ways: manually if a theme is just a set of files and using Composer if a theme is a Composer package. While installing with Composer is the easiest way to do it, not all themes come bundled as Composer packages, and hence in some instances you may need to install the theme manually.
Let’s take a closer look at the process of installing a theme on your Magento store using both methods.
Note: Taking a backup of your store before performing major updates such as theme installations is strongly recommended. This will avoid data loss in the event of an unsuccessful installation.
1. Manual installation
If your Magento theme comes packaged in the form of an archive for example, you can follow these steps to install it manually on your server.
Step 1: Upload the archive to your server
Most themes come pre-packaged in a .zip, .gz, or .tar archive. Compressing and packaging the theme files in such formats reduces the time required to upload and copy the files to the server.
Log in to your server as the Magento filesystem owner and upload the theme archive to your Magento user’s home directory using an SFTP client like WinSCP or FileZilla.
Uploading to the home directory rather than directly into the Magento filesystem enables you to extract the archive and review its contents before copying it to the Magento filesystem. This step prevents copying unnecessary files or folders that may have been included in the archive.
Step 2: Extract the archive
Next, extract the archive to a separate folder in your home directory to avoid overwriting any existing files.
Run the following command in the terminal to extract the archive in a sub-directory in your Magento user's home folder:
$ mkdir -p theme && tar -xf archive.tar -C theme
This command will work for .tar archives like .tar or .tar.gz. For .zip archives use another command:
$ unzip archive.zip -d theme
Step 3: Copy files to the Magento installation directory
Once you’ve reviewed the extracted files and folders, you can copy them over to the Magento directory. Most theme authors will store all theme-related files inside app/ and pub/ folders so you can copy the contents of those folders into your Magento filesystem.
You can do this be replacing the <magento-root> placeholder with the path to your Magento root and running the following commands inside your terminal:
$ cp -R app/* <magento-root>/app $ cp -R pub/* <magento-root>/pub
Step 4: Change Magento mode to developer
If you’re running Magento in the production mode, make sure to switch to the developer mode before you proceed with the installation.
Before you change the mode, clear previously generated classes and proxies to avoid any unexpected errors during the installation. To do this, run the following command:
$ rm -rf <magento_root>/generated/metadata/* <magento_root>/generated/code/*
Then navigate to the root directory of your Magento installation and execute the following command:
$ php bin/magento deploy:mode:set developer
Optionally, you can also put the site in maintenance mode to restrict access during the installation process. You can do this by using the following command:
$ php bin/magento maintenance:enable
Step 5: Install the theme via the CLI
To install the theme, run the following command:
$ php bin/magento setup:upgrade $ php bin/magento setup:static-content:deploy -f
If you set your Magento store to run in maintenance mode in Step 4, you can now safely disable it before proceeding to the next step. To do this, run the following command:
$ php bin/magento maintenance:disable
Step 6: Verify the installation and apply the theme
Finally, after the installation has been completed, you can log in to the admin panel and enable the theme for your preferred store view.
To do this, navigate to Content > Design > Configuration inside the admin panel and click on ‘Edit’ under the Action column for your preferred store view.
Once the edit page loads, select your newly installed theme from the `Applied Theme` dropdown and click ‘Save Configuration’.
That’s it, you’ve successfully installed a Magento theme using an archive.
2. Installation via composer
If your theme is available in the form of a Composer package, you can install it in a couple of simple steps.
Note: Make sure you have the theme’s Composer name handy and are running your Magento store in developer mode before proceeding.
Step 1: Install the theme
First, add the theme using its Composer name to your composer.json file and update dependencies by running the following command:
$ composer require <vendor>/<name>:<version>
Step 2: Verify installation and apply the theme
Once the above command executes successfully, your theme installation will be complete.
To verify the installation and apply the theme, you can follow Step 7 of the manual installation procedure.
Congratulations, you’ve successfully installed your theme using Composer.