I am working on Magento 2.2.2. I have deployed the website on a subdomain in my VPS within a account.
The strange thing is that, the “generated” folder gets automatically generated after deletion.
To investigate, I deleted everything inside the subdomain root folder where I had put the Magento 2.2.2 website code. Still from nowhere this “generated” folder and some sub-folders inside it gets generated automatically. See snapshot below.
I also checked with command crontab -l and found that there are no cron jobs running. I also restarted apache server from my WHM panel.
What might be causing this to happen?
2
Answers
Ok. I found the issue. The issue was that in my VPS account, I had logged in as root user and then executed all the upgrade, compile and deploy commands. Moreover I started cron also as root user.
But I was deleting files in generated folder and other cache folders in var directory from cPanel. And I had logged into cPanel as user of my website account.
I removed all cron as root user with command:
Then I logged into my vps SSH using root user and executed following command:
where mydir is the name of directory which I wanted to delete. I deleted "code", "metadata" inside "generated" folder and then re-created from cPanel. Not from SSH as root user. I also deleted "cache", "page_cache" inside "var" folder using SSH as root user and created them back from cPanel.
Now I refreshed the "generated" folder a few times in cPanel to see if the folders inside generated/code/... are generated. And now they are not automaticlally generating. But do keep in mind to install and run your cron jobs after all these.
I believe, the problem of automatic generation of folders inside generated folder was caused more due to cron being run as root user and I was deleting folders as cPanel user.
generated folder contains generated codes, to make sure all the methods are corrected and speed-up the process
http://devdocs.magento.com/guides/v2.2/extension-dev-guide/code-generation.html