Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php exec function doesn't work as expected

Tags:

php

exec

I am using exec function in a php script, if I run the script in command line, such as "php xx.php", the exec function will be executed, but if i access the php page from a browser, then the exec function will not run. Anyone known how to solve the problem?

Thanks.

like image 973
cheng Avatar asked Feb 22 '26 13:02

cheng


1 Answers

Is the script trying to create/edit/delete files? Try making the files and the containing directory writeable by the web server. If you're trying to add a file, navigate to the folder you're adding it to and run the following: chmod go+w .. If you're trying to delete/edit a file, trying the following: chmod go+w myfile.txt.

When running a script from the command line it runs as the logged in user, whereas when running it through a browser it is run as the web server user (usually a user named www.) This user generally doesn't have write access to the files and directories that are being served.

like image 127
dleavitt Avatar answered Feb 24 '26 01:02

dleavitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!