Uninstall modules
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
-
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 Magento file system owner.
If you use the bash shell, you can use the following syntax to switch to the Magento file system owner and enter the command at the same time:
1
su <Magento file system owner> -s /bin/bash -c <command>
If the Magento file system owner does not allow logins, you can do the following:
1
sudo -u <Magento file system owner> <command>
-
To run Magento commands from any directory, add
<magento_root>/bin
to your systemPATH
.Because shells have differing syntax, consult a reference like unix.stackexchange.com.
Sample bash shell for CentOS:
1
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. Need help locating the docroot?
In addition to the command arguments discussed here, see Common arguments.
Uninstall modules
Command usage:
1
2
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:
-
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.
-
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.
- Requests confirmation to proceed.
- Puts the store in maintenance mode.
-
Processes the following command options.
Option Meaning Backup file name and location --backup-code
Backs up the Magento file system (excluding var
andpub/static
directories).var/backups/ _filesystem.tgz --backup-media
Backs up the pub/media directory. var/backups/ _filesystem_media.tgz --backup-db
Backs up the Magento 2 database. var/backups/ _db.gz -
If
--remove-data
is specified, removes the database schema and data defined in the module’sUninstall
classes.For each specified module to uninstall, invokes the
uninstall
method in itsUninstall
class. This class must inherit from Magento\Framework\Setup\UninstallInterface. - Removes the specified modules from the
setup_module
database table. - Removes the specified modules from the module list in the deployment configuration.
-
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’sUninstall
class. - Cleans the cache.
- Updates generated classes.
- If
--clear-static-content
is specified, cleans generated static view files. - 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:
1
2
3
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:
1
bin/magento module:uninstall Magento_SampleMinimal Magento_SampleModifyContent --backup-code --backup-media --backup-db
Messages similar to the following display:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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:
1
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:
- Puts the store in maintenance mode.
- Verifies the backup file name.
-
If you specify a code rollback file:
a. Verifies the rollback destination locations are writable (note that the
pub/static
andvar
folders are ignored).b. Deletes all files and directories under your Magento 2 installation directory.
c. Extracts the archive file to the destination locations.
-
If you specify a database rollback file:
a. Drops the entire Magento database.
b. Restores the database using the database backup.
-
If you specify a media rollback file:
a. Verifies the rollback destination locations are writable.
b. Deletes all files and directories under
pub/media
c. Extracts the archive file to the destination locations.
- 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:
1
magento info:backups:list
-
Restore a file backup named
1433876616_filesystem.tgz
:1
magento setup:rollback --code-file="1433876616_filesystem.tgz"
Messages similar to the following display:
1 2 3 4 5 6
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
To run the magento
command again without changing directories, you might need to enter cd pwd
.