I'm having problems with chown and chmod in ubuntu 18.04. When I use php + nginx: touch ('/var/www/a.log'); user:own of a.log is nginx:nginx and chmod is rw-r-r-- when i use

shell_exec('ffmpeg -i' b.mp3 >a.log 2>&1');

The above command was not able to run because it does not have access to the a.log file, it seems that ffmpeg was running under user ive (this is my ubuntu login account). It could not write to the log file. I hope you will give me advice to handle this case. I am using ubuntu 18.04 on my laptop. p:s I was thinking of a root login solution so that all commands run with root but not yet. When logged in with root at the ubuntu login screen. Although I have entered the correct password, it still gives me the wrong password. :(

  • What is the owner of those log files? – Tung Tran Nov 6 '18 at 4:41
  • Hi Tung Tran, owner of the file is nginx – im dev Nov 6 '18 at 7:49
  • do you mean user www-data? – Tung Tran Nov 6 '18 at 7:50
  • No, in the nginx configuration I use user nginx; – im dev Nov 6 '18 at 7:53
  • Could you please add the output of ls -la /var/www/? – Tung Tran Nov 6 '18 at 7:57

At first, add your user into nginx group:

sudo usermod -G nginx ive

And then add this line after your touch(); function:

chmod("/var/log/yourlog.log", 664);
  • Should be usermod, also usermod -G will remove the user from any other groups, that's normally not what one want. – mook765 Nov 6 '18 at 10:23
  • You’re right. Macos’s correction did so. – Tung Tran Nov 6 '18 at 11:20

Use groups for what you are trying to do.
You can't use root to login because as stated here

By default, the root account password is locked in Ubuntu.

The password you used in sudo is not the password in root.

  • Thank you. However, I used the sudo passwd root command to change the password of the root account as instructed on youtube. It still does not work when I try to log in as root – im dev Nov 6 '18 at 7:52
  • In that case, sudo -i at your user first to interactive root followed by passwd to change it will enable the root account. – ProtoAES256 Nov 6 '18 at 8:37

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.