Page 1 of 1

Unable to create text file using php coding

PostPosted: 06. January 2016 13:33
by jaspreet237
I am using .sh file to create text file and its working fine but when i am trying run this .sh file using php then its not working ??

Re: Unable to create text file using php coding

PostPosted: 06. January 2016 15:31
by Altrea
"it's not working" is not a qualified error report.
Maybe it is a permission issue because PHP is executed with a different user that the user you use executing this .sh script yourself?

Re: Unable to create text file using php coding

PostPosted: 06. January 2016 15:44
by Nobbie
jaspreet237 wrote:I am using .sh file to create text file and its working fine but when i am trying run this .sh file using php then its not working ??


Yes, maybe.

A path or a permission problem, but without proper error message and without any coding it is absolutely impossible to give any hint.

Re: Unable to create text file using php coding

PostPosted: 07. January 2016 07:20
by jaspreet237
working with root and and given chmod 755 to all folders which i am using in my coding ..

path for php page and also for .sh files are : /opt/lampp/htdocs (with permission of 755)

code for php file : <?php
$output = shell_exec('my_script.sh2>&1');
echo "<pre>$output</pre>";
?>
my_scrip.sh code : !/bin/bash
# My first script

ls -l -h >output.txt

here permisson for my_script.sh and php file is 755

Re: Unable to create text file using php coding

PostPosted: 07. January 2016 07:59
by Altrea
jaspreet237 wrote:my_script.sh2>&1

This does not seam to look correct. You seem to want to pipe stderr, but pipe it to where? And i am very sure there has to be a whitespace after the filename.

Re: Unable to create text file using php coding

PostPosted: 07. January 2016 12:56
by Nobbie
jaspreet237 wrote:working with root and and given chmod 755 to all folders which i am using in my coding ..


It does not matter, what YOUR userid is (even root does not help), because PHP is executed via Apache and Apache runs with a different Userid (see httpd.conf). This User (mostly "daemon" or "www" or similar) must have sufficient rights for creating files in htdocs.

jaspreet237 wrote:$output = shell_exec('my_script.sh2>&1');


This is badly wrong, there is missing a space between my_script.sh and 2>&1, also my_script.sh is not preceeded by any path, so the System is looking up the PATH variable, which normally does NOT contain the current directory (i.e. '.'), neither /opt/lampp/htdocs. Therefore my_script.sh wont be found by the shell.

Re: Unable to create text file using php coding

PostPosted: 14. January 2016 12:56
by jaspreet237
Sorry for late reply... first of all thanks for your help... problem has been resolved with providing rights -R 755 to /opt/lampp

:)