Please make sure that “/” is writable by the web-server. [Magento 2.4 Sitemap]

Hi Craig, I was trying to set up new site map at back-end of Magento 2.4.4.

Back-end of Magento 2.4.4 shows “Please make sure that “/” is writable by the web-server.”

Here attached the details of my Equipment Set Up:

Dedicated Server at Google Cloud Platform (GCP) with
Ubuntu 20.04.4 LTS (GNU/Linux 5.13.0-1024-gcp x86_64)
Apache/2.4.41 (Ubuntu)
PHP 7.4.3 (cli) (built: Mar 2 2022 15:36:52) ( NTS )

Setup follow direction on How to install Magento 2.4 and build a web server .

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

User “god”

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.

Thank you very much!

User “magento2”

And it’s still the same situation.

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 :+1: However, you should ask yourself:

"But who is trying to write to the /var/www/html/ Directory?" :thinking:

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.

Check out this excerpt I wrote in 2019.

Regards,

1 Like

Hi Craig, thank you so much for finest efficiency of teaching.

Unfortunately I am still a beginner with less experience :smiling_face_with_tear: . 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?

Here is the content of cron task by root user used to write for renew ssl certificate automatically last time (which is deleted):

0 5 * * 0 certbot renew -n -q --pre-hook “service apache2 stop” --post-hook "service apache2 start”

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.


Step 1.
Run command

sudo chmod -R 775 /var/www/html

as the “superuser” from within any directory first, -R is missing at the below link, I think it’s quite important in this case:

The documents’ name turn Green if they changed into 775!
螢幕快照 2022-05-03 上午1.23.54


Step 2.
Final Step, do remember to change the owner of /var/www/html back to “magento2” by command

sudo chown magento2:www-data /var/www/html

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.5-p1 and build a web server (updated)
12314


Result:

We did it!

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

If I understand your setup correctly, run the following commands. But make sure:

  1. You’re running them as “god”, not “magento2” user
  2. You’re in /var/www/html/

Set Ownership

sudo chown -R magento2:www-data /var/www/html/

Set Permissions

sudo 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

Ref: How to diagnose and fix Ownerships and Permission issues

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

No more “Operation not permitted” comes out.

Thank you Mr. Craig! @digitalstartup

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.