Restore an environment
If you encounter issues in your environment and do not have a valid snapshot, you can try restoring your environment in one of the following ways:
- SSH
- Git
SSH
If you have not created a snapshot, but you can access the environment using SSH, follow these steps to restore your environment:
- Disable configuration management
- Uninstall Magento
- Reset the git branch
Performing these steps:
- Returns your Magento installation to its original state by restoring the database, removing the deployment configuration, and clearing
var/
subdirectories. - Resets your git branch to a stable state in the past.
Disable configuration management
You must disable configuration management so that it does not automatically apply the previous configuration settings during deployment.
To disable configuration management, make sure that your app/etc/
directory does not contain the config.php
file.
To remove the configuration file:
- SSH to your environment.
- Remove the configuration file:
-
For Magento 2.2:
1
rm app/etc/config.php
-
For Magento 2.1:
1
rm app/etc/config.local.php
-
Uninstall Magento
Uninstalling the Magento software drops and restores the database, removes the deployment configuration, and clears var/
subdirectories.
To uninstall the Magento software:
- SSH to your environment.
-
Uninstall the Magento application.
1
php bin/magento setup:uninstall
-
Confirm that Magento was successfully uninstalled.
The following message displays to confirm a successful uninstallation:
1
[SUCCESS]: Magento uninstallation complete.
Reset the git branch
Resetting your branch reverts the code to a stable state in the past.
To reset your branch:
-
Clone the project to your local development environment. You can find the command in your Project Web Interface:
-
Review the git history. Use
--reverse
to display history in reverse chronological order:1
git log --reverse
-
Choose a commit hash that represents the last known stable state of your code.
To reset your branch to its original initialized state, find the very first commit that created your branch.
-
Use the hard reset option to reset your branch.
1
git reset --h <commit_hash>
-
Push your changes to trigger a redeploy, which reinstalls Magento.
1
git push --force <origin> <branch>
Git
If you have not created a snapshot, cannot access your environment using SSH, and your deployment keeps failing, you must complete the steps in the previous section, and then force a redeployment.
Force a redeployment
Make a commit (this might be an empty commit, although we do not recommend it) and push it to the server to trigger redeploy:
1
git commit --allow-empty -m "<message>" && git push <origin> <branch>
Uninstall failed
If executing the setup:uninstall
command fails and cannot be completed, you might need to manually reset the database:
- SSH to your environment.
-
Connect to the database.
1
mysql -h database.internal
-
Drop the
main
database.1
drop database main;
-
Create an empty
main
database.1
create database main;
-
Delete the following configuration files.
config.php
config.php.bak
env.php
env.php.bak
After resetting the database, push your changes to trigger a redeploy and install Magento using the new database. Or run the redeploy command.