php script running as sudo

0

I have already created a PHP script that creates a folder within my home Linux directory, but I want to know how to change its rights ( rwx ) because the created folder has ownership the daemon and the rest of the script ( chown ) does not work. Please detail as I do not have much Linux experience.

    
asked by anonymous 19.07.2014 / 03:09

3 answers

1

1 - I do not recommend running scripts through php with sudo, as you said yourself do not have much knowledge in linux, and this would be a big gap not only in your application over all your SO .

2º - You could create a folder with global permission for everyone to access, so I believe that employee for you mkdir ("directory_name", 0777 );

More information about permissions in linux in the link below

link

You can run any command on the operating system with exec or shell_exec

Here are some permissions data below:

--------- 000

r -------- 400

r-r-r-444

rw ------- 600

rw-r-r-644

rw-rw-rw-666

rwx ------ 700

rwxr-x --- 750

rwxr-xr-x 755

rwxrwxrwx 777

    
28.07.2014 / 21:32
0

You can already create the folder with permissions for everyone to access:

mkdir("pasta", 0777);

To run any linux command in PHP as admin, you must create a file with the root password and pass it to sudo. Assuming you have saved this file in "/ var / www / myupport", with the name "password.secret":

exec('sudo -u root -S chown "usuario" "pasta" < /var/www/meuprojeto/senha.secret');
    
21.07.2014 / 15:37
0
  • Create your PHP script regardless of the user who will run, using chmod to change the permissions of directories.
  • Run your script from the command line: sudo php meuscript.php
  • There are many " poren" "in using this approach, but if you are root and want a script to help you manage the system, OK!

    However, possibly bash will be the best language to achieve your goal.

        
    28.07.2014 / 22:24