cannot execute copy comment but can do echo

I have set the sh file to chmod 755
i only able to print the output but cannot execute the copy why?

Below is the code for sh file

echo "Hello"
cp hello.sh helloworld.sh

Below is my code for php.

<html>
<head>
</head>
<body>
<?php echo '<p>Hello</>'; ?>
<?php shell_exec('sh /home/user/hello.sh'); ?>
</body>
</html>

It will execute in whatever current directory the web server happens to be using, not your home directory.

And the web server probably doesn't have permission to modify your home directory anyway. Try putting a copy in /tmp/, the web server should be able to write there.

1 Like

i have configure the apache to execute in my home directory. if i want to execute in home directory, is there anyway to modify my permission for home? is it using chmod 755 also?

What exactly did you do to do so?

To allow apache to write to it:

chown :apache /home/myusername
chmod g+rwx /home/myusername
1 Like

ok. thanks. i think tmp should be fine to me. thanks ya.