Uninstall modules

Edit on GitHubLog an Issue

Prerequisites

Before you use this command, you must install the Magento software.

Overview of uninstalling modules

This section discusses how to uninstall one or more modules. During uninstallation, you can optionally remove the modules’ code, database schema, and database data. You can create backups first so you can recover the data at a later time.

You should uninstall a module only if you’re certain you won’t use it. Instead of uninstalling a module, you can disable it as discussed in Enable or disable modules.

This command checks only dependencies declared in the composer.json file. If you uninstall a module that is not defined in the composer.json file, this command uninstalls the module without checking for dependencies. This command does not, however, remove the module’s code from the Magento file system. You must use file system tools to remove the module’s code (for example, rm -rf <path to module>). As an alternative, you can disable non-Composer modules.

First steps

  1. Log in to the Magento server as, or switch to, a user with permissions to write to the Magento file system. See switch to the file system owner.If you use the bash shell, you can use the following syntax to switch to the file system owner and enter the command at the same time:su <file system owner> -s /bin/bash -c <command> If the file system owner does not allow logins, you can do the following:sudo -u <file system owner> <command>
  2. To run Magento commands from any directory, add <magento_root>/bin to your system PATH.Because shells have differing syntax, consult a reference like unix.stackexchange.com.Sample bash shell for CentOS:export PATH=$PATH:/var/www/html/magento2/bin Optionally, you can run the commands in the following ways:
    • cd <magento_root>/bin and run them as ./magento <command name>
    • <magento_root>/bin/magento <command name>
    • <magento_root> is a subdirectory of your web server docroot.

In addition to the command arguments discussed here, see Common arguments.

Uninstall modules

Command usage:

bin/magento module:uninstall [--backup-code] [--backup-media] [--backup-db] [-r|--remove-data] [-c|--clear-static-content] \
  {ModuleName} ... {ModuleName}

where {ModuleName} specifies the module name in <VendorName>_<ModuleName> format. For example, the Magento Customer module name is Magento_Customer. To get a list of module names, enter magento module:status

The module uninstall command performs the following tasks:

  1. Verifies that the specified modules exist in the code base and are packages installed by Composer.This command works only with modules defined as Composer packages.
  2. Checks for dependencies with other modules; if there are any, the command terminates..To work around this, you can either uninstall all modules at the same time or you can uninstall the depending modules first.
  3. Requests confirmation to proceed.
  4. Puts the store in maintenance mode.
  5. Processes the following command options.OPTIONMEANINGBACKUP FILE NAME AND LOCATION--backup-codeBacks up the Magento file system (excluding var and pub/static directories).var/backups/_filesystem.tgz--backup-mediaBacks up the pub/media directory.var/backups/_filesystem_media.tgz--backup-dbBacks up the Magento 2 database.var/backups/_db.gz
  6. If --remove-data is specified, removes the database schema and data defined in the module’s Uninstall classes.For each specified module to uninstall, invokes the uninstall method in its Uninstall class. This class must inherit from Magento\Framework\Setup\UninstallInterface.
  7. Removes the specified modules from the setup_module database table.
  8. Removes the specified modules from the module list in the deployment configuration.
  9. Removes code from the codebase using composer remove.Uninstalling a module always runs composer remove. The --remove-data option removes database data and schema defined by the module’s Uninstall class.
  10. Cleans the cache.
  11. Updates generated classes.
  12. If --clear-static-content is specified, cleans generated static view files.
  13. Takes the store out of maintenance mode.

For example, if you attempt to uninstall a module that another module depends on, the following message displays:

magento module:uninstall Magento_SampleMinimal
    Cannot uninstall module 'Magento_SampleMinimal' because the following module(s) depend on it:
        Magento_SampleModifyContent

One alternative is to uninstall both modules after backing up the Magento module file system, pub/media files, and database tables but not removing the module’s database schema or data:

bin/magento module:uninstall Magento_SampleMinimal Magento_SampleModifyContent --backup-code --backup-media --backup-db

Messages similar to the following display:

You are about to remove code and/or database tables. Are you sure?[y/N]y
Enabling maintenance mode
Code backup is starting...
Code backup filename: 1435261098_filesystem_code.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Code backup path: /var/www/html/magento2/var/backups/1435261098_filesystem_code.tgz
[SUCCESS]: Code backup completed successfully.
Media backup is starting...
Media backup filename: 1435261098_filesystem_media.tgz (The archive can be uncompressed with 7-Zip on Windows systems)
Media backup path: /var/www/html/magento2/var/backups/1435261098_filesystem_media.tgz
[SUCCESS]: Media backup completed successfully.
DB backup is starting...
DB backup filename: 1435261098_db.gz (The archive can be uncompressed with 7-Zip on Windows systems)
DB backup path: /var/www/html/magento2/var/backups/1435261098_db.gz
[SUCCESS]: DB backup completed successfully.
You are about to remove a module(s) that might have database data. Remove the database data manually after uninstalling, if desired.
Removing Magento_SampleMinimal, Magento_SampleModifyContent from module registry in database
Removing Magento_SampleMinimal, Magento_SampleModifyContent from module list in deployment configuration
Removing code from Magento codebase:
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing magento/sample-module-modifycontent (1.0.0)
Removing Magento/SampleModifycontent
  - Removing magento/sample-module-minimal (1.0.0)
Removing Magento/SampleMinimal
Writing lock file
Generating autoload files
Cache cleared successfully.
Generated classes cleared successfully.
Alert: Generated static view files were not cleared. You can clear them using the --clear-static-content option. Failure to clear static view files might cause display issues in the Admin and storefront.
Disabling maintenance mode

Errors display if you attempt to uninstall a module with a dependency on another module. In that case, you cannot uninstall one module; you must uninstall both.

Roll back the file system, database, or media files

To restore the Magento codebase to the state at which you backed it up, use the following command:

bin/magento setup:rollback [-c|--code-file="<filename>"] [-m|--media-file="<filename>"] [-d|--db-file="<filename>"]

where <filename> is the name of the backup file located in <magento_root>/var/backups. To display a list of backup files, enter magento info:backups:list

This command deletes the specified files or the database before restoring them. (For example, the --media-file option deletes media assets under pub/media before restoring from the specified rollback file.) Make sure you have made no changes to the file system or database that you want to keep before using this command.

To display a list of available backup files, enter magento info:backups:list

This command performs the following tasks:

  1. Puts the store in maintenance mode.
  2. Verifies the backup file name.
  3. If you specify a code rollback file:a. Verifies the rollback destination locations are writable (note that the pub/static and var folders are ignored).b. Deletes all files and directories under your Magento 2 installation directory.c. Extracts the archive file to the destination locations.
  4. If you specify a database rollback file:a. Drops the entire Magento database.b. Restores the database using the database backup.
  5. If you specify a media rollback file:a. Verifies the rollback destination locations are writable.b. Deletes all files and directories under pub/mediac. Extracts the archive file to the destination locations.
  6. Takes the store out of maintenance mode.

For example, to restore a code (that is, file system) backup, enter the following commands in the order shown:

  • Display a list of backups:magento info:backups:list
  • Restore a file backup named 1433876616_filesystem.tgz:magento setup:rollback --code-file="1433876616_filesystem.tgz" Messages similar to the following display:Enabling maintenance mode Code rollback is starting ... Code rollback filename: 1433876616_filesystem.tgz Code rollback file path: /var/www/html/magento2/var/backups/1433876616_filesystem.tgz [SUCCESS]: Code rollback has completed successfully. Disabling maintenance mode Copy

To run the magento command again without changing directories, you might need to enter cd pwd.Updated9 months ago

https://devdocs.magento.com/guides/v2.4/install-gde/install/cli/install-cli-uninstall-mods.html