Create zip file using php and exec()

hi there,

i'm trying to create a zip file on my server using php and the exec() command and here is the output i get :

Warning: ftp_get(test100401120201.zip) [function.ftp-get]: failed to open stream: Permission denied

my code is attached below, i'm on an ubuntu system

any ideas ?

Cheers

Terence
$zipRemoteFileName = "/var/www/teleskiDev/tmp/teleski" . $date . ".zip";
$zipLocalFileName = "teleski" . $date . ".zip";			  
$zipCommand = "sudo -u root zip $zipRemoteFileName ";
foreach($files as $file) {
	$zipCommand .= $this->pwd . "/" . escapeshellcmd($file) . " ";
}
echo $zipCommand;
system($zipCommand);

Open in new window

LVL 1
terencepiresAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kruger_monkeyCommented:
Permission denied.  Looks like the script is trying to work, but doesn't have the necessary permission.

Does apache have access to the folder in question?  Check the access permissions on the folder, assuming your page is running under apache the user that apache runs under needs to have write permissions to the folder in question.
0
terencepiresAuthor Commented:
ok, how can i do that ?
0
Kruger_monkeyCommented:
On the server where the php script is you need to make sure the access to this folder is high enough fro apache to write to.

/var/www/teleskiDev/tmp/

Check the ownership and current permissions.

This article shows you how to set the permissions via your script.  Not sure about the 777 being necessary, but it may be.  If this is a public facing server, you may want to reset that

http://forums.digitalpoint.com/showthread.php?t=382036
0
INTRODUCING: WatchGuard's New MFA Solution

WatchGuard is proud to announce the launch of AuthPoint, a powerful, yet simple, Cloud-based MFA service designed to eliminate the vulnerabilities that put your data, systems, and users at risk.

terencepiresAuthor Commented:
ok i tried that but it still doesn't work

maybe i have to put apache in the sudoers group ? that too i don't know how to do
0
terencepiresAuthor Commented:
ok, i tried to add the apache user to the sudoers group using visudo, like below

stopped / restarted server without effect...
0
terencepiresAuthor Commented:

# User alias specification
User_Alias      APACHE = www-data

# Cmnd alias specification
Cmnd_Alias      ZIP = /usr/bin/zip

# User privilege specification
root    ALL=(ALL) ALL

# Uncomment to allow members of group sudo to not need a password
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=NOPASSWD: ALL
APACHE  ALL = (ALL) NOPASSWD: ZIP

Open in new window

0
Kruger_monkeyCommented:
The sudoer files isn't really necessary as far as I know as they aren't going to be using sudo.

As a test, can you chmod 777  /var/www/teleskiDev/tmp/

This will set your tmp folder for world writeable access.  It will also be worth if you can do the following on the server that hosts the page.

tail -f /var/log/httpd/error.log

Watch that log file while you try the file and post whatever pops up if anything.
0
terencepiresAuthor Commented:
ok, here's what i get :

[Thu Apr 01 13:09:23 2010] [error] [client 89.156.181.70] File does not exist: /var/www/favicon.ico
      zip warning: name not matched: /home/terence/Rakefile
      zip warning: name not matched: /home/terence/backup.sql
      zip warning: name not matched: /home/terence/configuration.php
      zip warning: name not matched: /home/terence/photos.php
      zip warning: name not matched: /home/terence/teleski.zip
      zip warning: name not matched: /home/terence/test
      zip warning: name not matched: /home/terence/test.tite
      zip warning: name not matched: /home/terence/test.titi
      zip warning: name not matched: /home/terence/test.titz
      zip warning: name not matched: /home/terence/toto.zip

zip error: Nothing to do! (/var/www/teleskiDev/tmp/teleski100401130925.zip)

i then tried to do :
   cat /home/terence/test.titi

and it worked...
0
Kruger_monkeyCommented:
Can you check what the file sizes are on those files listed above.  

See the name not match highlight here.

http://wiki.linuxquestions.org/wiki/Zip
0
Kruger_monkeyCommented:
Check the following as well to see if that applies to you if the file sizes are small.

http://www.kplaylist.net/forum/viewtopic.php?f=4&t=2384
0
terencepiresAuthor Commented:
- well the sizes are really small (a few kb's) and the command works when typing it from ssh

- i was using PHP's escapeshellcmd() so i tried without it, to get the same result...
0
Kruger_monkeyCommented:
It might still be a permissions problem, may the inability of the zip to fully access the files in question generates that error.  Have you tried the earlier suggestion of changing the permisssion on your tmp folder?  

All the files listed as name not matched, is that all of them?  What are the permisssions on that folder? If the same command works over ssh (I assume as yourself or root and not apache) then we are back to the permissions for apache.

Try changing the permissions on your home folder and see what happens.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
terencepiresAuthor Commented:
solved !
thanks !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
OS Security

From novice to tech pro — start learning today.