views:

102

answers:

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!!!

A: 

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).

Bayes
Got you. Thank you!
Cristalla
A: 

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.

Geek Num 88
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!
Cristalla
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.
Geek Num 88
I understood. Thank you very much! :)
Cristalla
A: 

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

poiuyttr
I will try! Thank you!
Cristalla