1

I have a server, which has a user called user.

I am executing PHP commands in a directory with shell_exec, and executing "whoami" through shell_exec returns user.

I also install a wordpress installation with wp-cli commands with installing plugins, everything works fine.

However, when I try to execute the following command:

wp starter-templates import 59760 --yes --reset 2>&1

The error output is:

File generated at /home/server/wp/testwp/wp-content/uploads/astra-sites/astra-sites-backup-22-Aug-2023-08-10-54.json
sh: 1: : Permission denied

When I try to call this command in my local environment (in which everything works fine), the output is as follows:

File generated at /Users/user1/Sites/wp/wp-content/uploads/astra-sites/astra-sites-backup-22-Aug-2023-07-56-55.json
Reseting Posts..
Deleted - Post ID 1808 - attachment - Banner
Deleted - Post ID 12 - attachment - Logo-96×19
Deleted - Post ID 145 - attachment - Service-1-min
Deleted - Post ID 146 - attachment - Service-1-min (1)
Deleted - Post ID 149 - attachment - Service-2-min
...

When I look at phpinfo() and openbasedir settings at the server, I can see that PHP is allowed to access the directories, which is actually true since plugins and base wp installation install just fine.

When I look at the permissions for the generated .json file in the server, the permissions are:

-rw-r--r-- 1 user user 61 Aug 22 19:05 astra-sites-backup-22-Aug-2023-07-05-07.json

Which suggests that the user user have read and write properties and is the owner of the file.

When I look at the contents of the json file, it seems that it is empty. From my understanding, the wp starter-templates import 59760 --yes --reset 2>&1 command tries to write to that json file, however, it keeps giving permission error and the command fails.

From my local environment test, the .json file shouldn't be empty. However, in the server environment it is empty. Hence I believe the issue is write permissions.

Why does it keep giving permission error though?

DarthVader
  • 37
  • 1
  • 8
  • If what you are executing there was supposed to _create_ this file, and it apparently successfully _did_ - then the error message is probably regarding something else ...? (Would be weird to begin with, having a message say a file _was_ created, if that wasn't already successful at this point. If the error was related to this, then the message should probably rather have said it was going to _try_ to create a file now.) – CBroe Aug 23 '23 at 12:03
  • The command I try to execute (which is `wp starter-templates import 59760 --yes --reset 2>&1`) generates the json file and tries to fill it in, however, it gives permission error. I believe it is because it seems like it doesn't have write permissions, but i am executing the command as the owner, so that didn't make any sense. – DarthVader Aug 23 '23 at 12:31
  • 1
    Without write permission in the folder, it could not _create_ the file in the first place. And for the user that just created the file, not to have write access to the file itself then, would be really weird ... can't see that happening, if the application wasn't explicitly messing with file owner or access rights. (Plus that doesn't appear to be the case either, according your your check.) – CBroe Aug 23 '23 at 12:36
  • Hmm, that's correct :) I will dig more into this issue, thanks for the clarification! – DarthVader Aug 23 '23 at 12:37

0 Answers0