0

How can PHP be used to create a number of commands in the terminal? For example, if I want to change the permissions on a folder or a file, I might run

Sudo Chmod 777 FileName

from the command line. How could I do this with PHP?

Pops
  • 30,199
  • 37
  • 136
  • 151
dori naji
  • 980
  • 1
  • 16
  • 41

2 Answers2

1

Look at exec, system etc: http://www.php.net/manual/en/book.exec.php

Obviously, if you are going to use sudo for root access stuff (not recommended) then you would need to either supply a password somehow or set the user which PHP is running as to not require a password.

It may be better to use an SSH call for this and supply the command to execute via that command.

To sum up, I really don't recommend using PHP (or any language for that matter) to run a series of commands which then uses sudo

DaveyBoy
  • 2,928
  • 2
  • 17
  • 27
  • 4
    @Lix - at least in this case the answer does expand with some do's and don'ts caveats. – Kev May 15 '12 at 16:05
-2

To give permission to folder or file in php use following line of code

chmod($file,0777);

this will change the permission of file or folder.

Suresh kumar
  • 2,002
  • 1
  • 19
  • 28