is there any way to recover the env.php file. As my file deleted unexpectedly when editing using command line. Now file is empty and showing with 0 size in the ftp. As i don't have the backup of the file or database credentials.

Any way to recover it ?

  • Do you have that website files on local machine? – Saphal Jha May 24 '19 at 15:52
  • which hosting you are using? – Saphal Jha May 24 '19 at 15:52
  • no i don't have that in my local drive. also i have no idea about hosting. – Mehar May 24 '19 at 15:53
  • i only have the FTP credentials and SSH access. – Mehar May 24 '19 at 15:53
  • do you have root ssh? – Saphal Jha May 24 '19 at 15:55

You need to find out about your hosting. If working on host might be worth reaching out to host to see if they have a restore procedure in place. The fact that you know what file and when you deleted it is helpful.


as experience shows, you just make sure your env.php file is writeable. restore or create new password for database user, from phpmyadmin or mysql shell, for example it will look like this:

mysql$> select user,host from mysql.user;
| user            | host      |
| magento         | localhost |
| mysql.session   | localhost |
| mysql.sys       | localhost |
| root            | localhost |
4 rows in set (0.00 sec)

change password for example user magento

mysql$> ALTER USER 'magento'@'localhost' IDENTIFIED BY 'New-Password-Here';

backup all your files and db.

remove all caches:

rm -rf var/cache/* generated/* var/view_preprocessed/*

open your website, you will be redirected to /setup/, enter all your required information for re-install.

make sure there is NO any checkboxes selected to wipe database data.

after final install button, your config will be re-stored/re-created. you will be able to access your shop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.