addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [baltimorephp] PHP calling unzip

From: Yicheng
Sent on: Tuesday, March 20, 2012 3:55 PM
First, you generally want to be careful when running command line executables from apache.  You risk exposing your site to remote compromise, especially if your command line accepts parameters.  While I don't see a problem with what you're doing here, I'm guessing that this is just a prototype and not the final revision of the code.

Second, the problem is that the exec() is running as the shell user & environment that apache will run under.  You will need to check, but on my machines, it's usually 'daemon'.  You will want to make sure that SELinux is not enabled (which can cause issues  AFAIR), but the most likely problems it that the command line string assumes relative unix paths instead of absolute paths.

For example, on my servers, the command would be

exec("/usr/bin/unzip /home/www/ziptest.zip", $aOutput);

Find out where your unzip command is by using "which unzip", and substitute that line where I have /usr/bin/unzip.  You'll also want to give an absolutely path to your Apache's document root path.  I'm not altogether sure what you want to do with ziptest.zip, so putting it into the base document root path may not be what you want to do.

Regards,
Yicheng

On Tue, Mar 20, 2012 at 3:40 PM, Joe Tseng <[address removed]> wrote:
All,

Boss asked me to figure this out and now we're both stumped.  I wrote a little test script to see if we can use PHP to unzip a file:

$ more ziptest.php
<?
echo("Start here");
exec("unzip ~/ziptest.zip", $aOutput);

echo("[".$aOutput[0]."]");
echo("end here");
?>

It works great at the command line - it extracts the file and gives me stdout:

$ php -f ziptest.php
Start here[Archive:  /home/user/ziptest.zip]end here

But it's not doing squat via Apache:

Start here[]end here

And no we're not using the zip module.  Our SAMP stack has to be built by hand from source code and I don't have the time right now to do that to add this functionality to PHP.  I've also verified that the directory the script lives in has rw perms for the Apache daemon user.

Can I assume I'm really close and it's some tiny detail I'm overlooking?

Thx in advance,

 - Joe



If you type "Google" into Google, you can break the Internet.  -- Jen Barber




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Joe Tseng ([address removed]) from Baltimore PHP.
To learn more about Joe Tseng, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy