Reputation: 355
Past few hours under the bridge and the zip creation code I'm working with will only create the zip if I run it from a ssh terminal using the php command as in: php zipcreate.php So I know the code works. I'm running this on a ubuntu debian amazon ec2 server. All the relevant files are owned by user ubuntu, the user I'm logged in as when I execute the script manually. It will not work for the life of my when I execute the script from the browser via the sites url. The page loads but no zip.
I've even changed the following lines in etc/apache2/envvars to user ubuntu with no success. export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data
What in the world am I missing. I'm pretty sure I'm not duplicating a question on stack overflow since I've read them all by now.
BTW, here's the zip code just in case: $files = array('test.txt'); $zipname = 'file.zip'; $zip = new ZipArchive; $zip->open($zipname, ZipArchive::CREATE); foreach ($files as $file) { $zip->addFile($file); } $zip->close();
Upvotes: 0
Views: 597
Reputation: 2998
If you can run it as your user but can't with you web app, it means apache's user (www-data) can't write in this directory.
You have to grant www-data write permission on your target directory:
chmod +w /your/target/directory
A more secure way to do it is to change your directory ownership and permissions:
chown -R www-data:www-data /your/target/directory
chmod 775 /your/target/directory #change it if you need
Upvotes: 0