当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - Running a bash script from php webpage

问题描述:

I have a php web page being ran by the apache server, it is stored in /var/www/myweb/ and called index.php

Now I am trying to call a script in /home/me/ called test.sh from the php webpage . All it does is create a file1 on /home/me/

test.sh:

#!/bin/bash

touch file1

~

~

~

~

inside index.php, I am trying to call the script

index.php:

 if ($_GET['run'])

{

exec('/home/me/test.sh');

}

unfortunately this is not working, and it seems the reason is permission problems. I went ahead and try to run this command from /var/www/myweb/

/home/me/test.sh

and I got this error:

touch: cannot touch ‘file1’: Permission denied

Is there a way to fix this problem ?

网友答案:

If you do not change a directory, you are not trying to touch /home/me/file1, but /var/www/myweb/file1. However, /var/www/myweb permits root to rwx; www-data group to r-x and also everyone else to r-x. When Apache runs it, it is running it as www-data, in www-data group; it gets the group permissions r-x, which prohibit creating a new file. When you run it, it is running as me, presumably not in www-data group, which takes the last set of permissions: still r-x, still unable to write.

Ideally, you would want to provide the full path to the file being created, to avoid confusion about where in the file system you are, and that location would want to have the permissions drwxrwxr-x (or drwxrwsr-x) for me and group www-data.

分享给朋友:
您可能感兴趣的文章:
随机阅读: