0

I want to add new DNS on my server. I'm able to edit the file /etc/resolv.conf using vi editor.

But, when I try using PHP.. the file is not opening.

What could be the issue?

Please suggest / provide me with a solution to fix this.

KiranD
  • 433
  • 2
  • 7
  • 20

2 Answers2

2

Most likely your PHP is running on a different user then when you login to the server yourself. You will have read/write access to the file and PHP doesnt.

Now increasing the rights of the PHP users could cause a security issue, so I would advise against it. But you could grant the user access to that specific file only if realy needed. Check Granting Access Permission to a file to a specific user on how to do it.

Community
  • 1
  • 1
Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72
0

You will probably need root access to modify /etc/hosts .

  • You can chmod 666 /etc/hosts, but this would be a security issue.
  • But so is running PHP under root,
  • and so is chowning the /etc/hosts.

So there you have 3 (insecure) solutions. With the last one being least evil.

You might also be facing a struggle with PHP accessing files if PHP is restricted to files inside a certain directory. ( http://www.php.net/manual/en/ini.core.php#ini.open-basedir )

nl-x
  • 11,762
  • 7
  • 33
  • 61