3

My html webpage calls a php script to upload files to the server from a local computer as follows.

<form enctype="multipart/form-data" action="upload.php" method="POST">
<p><b><h3>  <font color="#003366"> (1) Upload your reading text file.  </font> 
</h3> </b> </p>
<INPUT type="file" name="uploaded" size="50" >
<br/>
<input type="submit" name="files" value="upload">
</form> 

In order to process with an uploaded file, my php script calls a shell script

$output=system('/bin/sh connector_0.sh');  

and my shell script is composed of a series of python/perl scripts.

#!/bin/sh

python main_senselearner_final_0.py 

senseLearner.pl -i Uploaded_Files/slinput_0.txt -o Uploaded_Files/presloutput_0
.txt -model modelNNCollocations -model modelJJCollocations -model modelVBColloc
ations -pos

python smutngslout_0.py 

python genhtml_0.py 

Now, the problem is the following: all the python scripts in shell script worked fine through php. But the perl script didn't work.

When I run the shell script by myself in my server, all four scripts in the shell worked perfectly. However, when I run the shell script from php, only the perl script doesn't work.

Would you please give me any tips to solve this problem?

Many thanks!!!

4
  • I corrected your formatting - use the code formatting toolbar button, or indent code by four spaces. Commented May 25, 2010 at 20:30
  • Capture the output and standard error of the shell script. Check $? after each line in the shell script. Commented May 25, 2010 at 20:40
  • "Doesn't work" doesn't help. What specifically happens (error messages, log entries, mangled output, spilled milk, kitty fur on the couch)? @mobrule: set -x might be useful, too. Commented May 25, 2010 at 21:19
  • Paul, mobrule, Dennis, Thank you for your nice help and tips! :) @ Dennis, nothing happened. The script just didn't output any. Commented May 27, 2010 at 2:07

3 Answers 3

1

This is very likely a permissions problem. Try setting the files that the perl script reads to a+rw and see if it works then. If so, then you need to find out the user running php (likely the apache user) and make sure that they can read/write the relevant files. Also make sure the Perl script is executable by the php user (apache).

Sign up to request clarification or add additional context in comments.

Comments

0

There is a possibility that the user that Apache/PHP is running as (usually apache) does not have permissions for Uploaded_Files/slinput_0.txt or Uploaded_Files/presloutput_0.txt.

Just guessing but apache would need read for the slinput_0.txt file, read/write for presloutput_0.txt and read/write/exec for the directory Uploaded_Files

The reason it works when you try it is you are running as your user and most likely have permissions to write to the webroot.

2 Comments

Just guessing but apache would need read for the slinput_0.txt file, read/write for presloutput_0.txt and read/write/exec for the directory Uploaded_Files ==> Yes, that is what I guessed too. So I tried to set those files read/write using chmod 755/(or even 777), it returns "chmod: changing permissions of `slinput_0.txt': Operation not permitted" Would you give me some tips how to solve it? Thank you very much!
that means you don't have permissions on those files - if you have root access to the webserver you need to sudo chmod. Those directories might already be owned by apache but not have the correct permissions to read/write/exec. If you do not have root access to the webserver you would need to get help from your hosting company to fix some permissions.
0

I'd try
senseLearner.pl -i Up ... -pos > /var/log/senseLearner.log 2>&1
(and look to that log file after)

and maybe you can try to specify interpreter like
/path/to/perl senseLearner.pl -i Up ... -pos > /var/log/senseLearner.log 2>&1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.