I can't delete the folder generated/code in Magento 2.2.6

I can't delete the folder generated/code in Magento 2.2.6

August 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
I can't delete the folder generated/code in Magento 2.2.6

Troubleshooting Magento 2.2.6: Deleting the Generated/Code Folder

Dear reader,

Are you facing issues deleting the generated/code folder in your Magento project running on Docker? This is a common problem that many developers encounter, especially when using older versions of Percona and Docker.

Understanding the Issue

When you execute commands like php bin/magento cache:clean, Magento attempts to delete certain files including those found in the generated/code directory. However, if the file doesn’t exist (as indicated by “No such file or directory”), it can cause issues with subsequent operations.

In your case, you’re using PHP 7.1.22, Percona 5.6.39, and Docker Version 18.06.1-ce-win73 (19507). This combination might have compatibility issues that are causing the problem.

Solution 1: Check Permissions

Ensure that the user running your Docker container has the necessary permissions to delete files in the generated/code directory. You can check and modify permissions using commands like:

ls -l /var/www/html/src/generated/code
chmod u+x /var/www/html/src/generated/code  # To grant execute permission

Solution 2: Update Docker and Percona

To resolve compatibility issues, consider updating your Docker version and Percona to their latest stable releases. As of now, the recommended versions are:

  • Docker: Version 18.09.x or later
  • Percona Server for MySQL: Version 5.7.x or 8.0.x

Updating these components can help fix underlying issues causing the deletion problem.

Solution 3: Run Commands as Root

If all else fails, you can try running your commands with elevated privileges using the sudo command:

sudo php bin/magento cache:clean

However, this should be used sparingly due to security implications. It’s generally better to adjust permissions rather than run commands as root.

Additional Resources

For more in-depth guidance on Magento performance optimization and troubleshooting, I recommend checking out our comprehensive guide at LaravelCompany. This article covers best practices for caching, indexing, and database management that can help avoid issues like the one you’re experiencing.

Remember, keeping your Magento version up-to-date is crucial. The latest 2.4.x releases include numerous performance enhancements and security fixes.

Conclusion

Deleting the generated/code folder in Magento requires careful attention to file permissions and compatibility with your Docker and Percona versions. By updating your software components or adjusting user permissions, you should be able to resolve this issue without having to restart your computer. Always ensure you have a backup before making significant changes.

If you continue to face problems, don’t hesitate to explore the advanced troubleshooting techniques mentioned in our guide at LaravelCompany. We’re here to help you get the most out of Magento!

Happy coding!

Magento 2 Cache Database Security

Our network