Unable to create text file using php coding

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Unable to create text file using php coding

Postby jaspreet237 » 06. January 2016 13:33

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 ??
jaspreet237
 
Posts: 3
Joined: 06. January 2016 13:25
Operating System: Centos

Re: Unable to create text file using php coding

Postby Altrea » 06. January 2016 15:31

"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?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Unable to create text file using php coding

Postby Nobbie » 06. January 2016 15:44

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.
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: Unable to create text file using php coding

Postby jaspreet237 » 07. January 2016 07:20

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
jaspreet237
 
Posts: 3
Joined: 06. January 2016 13:25
Operating System: Centos

Re: Unable to create text file using php coding

Postby Altrea » 07. January 2016 07:59

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.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8299
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Unable to create text file using php coding

Postby Nobbie » 07. January 2016 12:56

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.
Nobbie
 
Posts: 8779
Joined: 09. March 2008 13:04

Re: Unable to create text file using php coding

Postby jaspreet237 » 14. January 2016 12:56

Sorry for late reply... first of all thanks for your help... problem has been resolved with providing rights -R 755 to /opt/lampp

:)
jaspreet237
 
Posts: 3
Joined: 06. January 2016 13:25
Operating System: Centos


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 11 guests

cron