I am tying to upgrade a Magento 2.1 site to Magento 2.2.0 but it seems to be dropping out during the process and the bin/magento file is removed but not replaced so nothing at all works after this.

I am using these commands:

cd /var/www/html
bin/magento maintenance:enable
composer require magento/product-community-edition 2.2.0 --no-update  
composer update

It seems to work nicely upgrading all the files but then it seems to stop (as if it has actually finished) but I get the following and the file bin/magento has completely gone.

I am definitely using the same user account to do the upgrade as was used to install Magento so I don’t think it’s a permissions problem.

 ....truncated lots of updates....
 - Removing theseer/fdomdocument (1.6.5)
 - Installing theseer/fdomdocument (1.6.6)
 Downloading: 100%         

 zendframework/zend-session suggests installing mongodb/mongodb (If you want to use the MongoDB session save handler)
 zendframework/zend-session suggests installing zendframework/zend-cache (Zend\Cache component)
 paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
 zendframework/zend-captcha suggests installing zendframework/zend-i18n-resources (Translations of captcha messages)
 zendframework/zend-captcha suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha component)
 ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)
 ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)
 ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)
 ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)
 ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
 ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)
 Package fabpot/php-cs-fixer is abandoned, you should avoid using it. Use friendsofphp/php-cs-fixer instead.
 Writing lock file
 Generating autoload files
 File doesn't exist: bin/magento
 Check "chmod" section in composer.json of magento/magento2-base package.
  • It must add permissions for bin/magento chmod -Rf 777 bin/magento
    – St3phan
    Commented Oct 7, 2017 at 9:29
  • I'm pretty certain that permissions are correct for the file: -rwxrwxrwx 1 magentouser apache 783 Apr 25 08:20 magento and it's enclosing folder drwxrwxrwx 2 magentouser apache 4096 Apr 25 08:20 bin. I'm definitely using su magentouser before running the composer commands, also the magento file is definitely there before I run the upgrade. Commented Oct 8, 2017 at 7:49
  • I have also tried upgrading to 2.1.9 and it still deletes the magento file. If it was a permissions issue, I would have thought it wouldn't be able to delete the file too. Commented Oct 8, 2017 at 7:50
  • Actually I think the enclosing html folder had the wrong permissions, what should the root web directory permissions be set to? Commented Oct 8, 2017 at 8:14
  • yes, permission may also be on the folder
    – St3phan
    Commented Oct 9, 2017 at 7:25

8 Answers 8


I had the same problem.

It seems to be some kind of configuration error or some composer related issue. There is a trace of the same issue on the Magento Forum and on Magento2 Github Issue tracker.

There is a solution suggested by a Magento2 contributor here (for Enterprise Edition): https://github.com/magento/magento2/issues/4792#issuecomment-352069899

It seems that running:

composer clear-cache
composer update

would restore all eventually removed files. But it didn't work for me :-|

What I did to solve the issue was to downgrade and upgrade again.

Be very careful with filesystem permissions, you should always follow the official documentation at http://devdocs.magento.com/guides/v2.0/install-gde/prereq/file-system-perms.html

  • 1
    Downgrading and upgrading did the trick for me too.
    – Webninja
    Commented Apr 24, 2018 at 13:19
  • 2
    It didn't work for me. In Community Edition I had to delete vendor/magento and then run the commands in your answer. This makes composer re-download all Magento files.
    – Gabriela
    Commented Dec 2, 2019 at 16:22

You need to remove the magento2-base base modules for this directory to be added back in on next composer install.

rm -rf vendor/magento/magento2-base vendor/magento/magento2-ee-base
composer clear-cache
composer install
  • 1
    Thank you so much it is working for me Commented May 5, 2021 at 12:47
  • its working for me and remove the error on composer time. Commented Jan 3, 2022 at 13:27

I've bumped into this issue as well, which I believe to be related to the package magento/magento2-base that might have been installed already, while actually only a reinstall of that package triggers a post-install procedure that copies files from that very same package to the root of Magento (like the file bin/magento). My remedy is to remove the vendor folder and do composer install.


I had the same problem when I wanted upgrading from Magento 2.3 to 2.3.1 and I solved it removing all vendor components except .htaccess file and executed composer update. This solved the problem.


Was facing this issue and below found at https://github.com/magento/magento2/issues/4792#issuecomment-503790315 fixed it.

Make sure you have below in your composer.json file:

"extra": {
    "magento-force": "override"

If "extra" section is already there, check "magento-force" part. This is to force override from magento2-base on project filesystem during composer update process to regenerate important files, e.g. bin/magento, app/bootstrap.php, etc.


I also faced a similar issue. bin/magento file was deleted during the upgrade and site stopped working when I am upgrading from 2.2.4 to 2.3.0. I managed to fix it by removing all files from the vendor folder and run composer update command again.


I had the same issue when upgrading from CE2.2.0 to CE2.2.3. I tried to set permissions exactly as Magento 2 dev docs recommended, but upon completion composer update kept deleting bin/magento and other files. It is definitely something to do with permissions but I don't know the exact reason.

Anyway I give the solution that worked for me and hopefully this will help anyone running into the same issue: I use GC with Ubuntu/Apache, after I changed my owner and group to magento_user:magento_user instead of magento_user:www-data which is how it's normally setup, composer update worked. Then all I need was changing the group back to www-data and fix file permissions for var/ pub/static and generation/. Remember to enabled the cache, otherwise your CPU will max out.

I hope seasoned folks could shed some lights on why this is happening. I've been working on M2 for over two years now and I'm still trying to get my head around on file permissions to be honest.


If composer clear-cache && composer update doesn't help you, you can just go to Github: https://github.com/magento/magento2/blob/2.2.0/bin/magento, choose your version from the tags list & copy the contents of the file to your local bin/magento (create it as a new file).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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