I already updated Magento system from 2.4.0 to 2.4.4, met the same problem at Can't setup sitemap but I can’t solve it by running the commands sudo chown magento:www-data /var/www/html and sudo chmod 775 /var/www/html as the superuser “god” from within any directory.
User “god” is the superuser as “craig”
User “magento2” is the user as “magento”
The results of ls -la are same after running the above commands by those 2 users and
And I found that the “elasticsearch-7.6.0-amd64.deb” shows in red color when I was logging in as superuser “god”.
Is this folder abnormally large or has an error occurred? Please let me know the solution of setting up the sitemap and turn the folder “elasticsearch-7.6.0-amd64.deb” to normal for stable operation in the further.
Elasticsearch files
Firstly, let’s address the elasticsearch files. Those are only temporary files that you would have downloaded in order to install Elasticsearch. This is why I recommended downloading the files to your “My Documents” directory (e.g. /home/god/). As they’re only used to installing elasticsearch, you don’t need them anymore. So, just delete them.
Sitemap
As you’ve clearly identified, magento2 user has appropriate permissions to write to the /var/www/html/ Directory However, you should ask yourself:
"But who is trying to write to the/var/www/html/Directory?"
If memory serves, crontab is responsible for actually creating the sitemap files. Therefore, in your case you should check that you have setup crontab under the correct user. Because if you accidently setup crontab up as god user (for example), then it’s god user trying to write the file, not magento2 user.
Hi Craig, thank you so much for finest efficiency of teaching.
Unfortunately I am still a beginner with less experience . The problem is still here.
I found that I might set a cron tasks by root user.
I deleted that cron tasks and emptied all users’ cron tasks with crontab -r, run sudo chown -R magento:www-data /var/www/html/ && sudo chmod 775 /var/www/html by “god” .
Finally, run bin/magento cron:install without any cron tasks by “magento2” . There is still the same situation we are facing with.
May I know more about what steps I did wrong or what should I do at the next step please?
okay Mr. Craig, I found the solution by tests and I am still wondering if this is the correct way to solve it. Please reply me to let general know about it. @digitalstartup
My Solution:
Step 0. (Optional)
Change back the owner of /var/www/html to the www-data
sudo chown -R www-data:www-data /var/www/html
This Step 0 is optional because I can’t make Step 1 successfully when the owner of /var/www/html is user “magento2” which is not superuser.
Notice (magento2 = username of Magento databases’ owner which I chose at the beginning we set up our Magento), it equals to character of user “magento” in Ubuntu Server at How to install Magento 2.4 and build a web server
Good work on solving your issue. Nice to see it was as simple as a Permissions/Ownership problem rather than anything too wild. Your methodology to solve the issue was sound.
My only comment, would be to set the appropriate chmod permissions back, as you’ve set everything to 755. Just run the below as the filesystem owner (e.g. magento2) form within /var/www/html/
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chmod u+x bin/magento
It’s all fine now after running the following command as “god” .
sudo chown -R magento2:www-data /var/www/html/
Then run the following command as “magento2”, no need sudo cause this character at How to install Magento 2.4 and build a web server can’t run sudo command
(“Operation not permitted” comes out if run this as “god”)
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chmod u+x bin/magento