Report this

What is the reason for this report?

ZipArchive extractTo not extraction file on apache php7

Posted on May 23, 2018

Warning: ZipArchive::extractTo(/var/www/html/agendarpost/.env): failed to open stream: Permission denied in /var/www/html/agendarpost/install.php on line 71



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

When running with mod_php on Apache your php processes will run as the user www-data as Apache itself does. This error would occur if you uploaded your files to the web server as the “root” user.

You can ensure that the correct ownership is set by running:

chown -Rf www-data:www-data /var/www/

Let us know if the problem persists after this change.

The “Permission denied” error you’re encountering when using ZipArchive::extractTo() indicates that the Apache user (typically www-data on Ubuntu or apache on CentOS) does not have the necessary write permissions to the target directory (/var/www/html/agendarpost/).

Steps to Fix:

  1. Check and Set Permissions: Ensure that the Apache user has write permissions to the target directory. You can adjust the permissions by running the following commands:
sudo chown -R www-data:www-data /var/www/html/agendarpost
sudo chmod -R 755 /var/www/html/agendarpost
  • These commands ensure that the Apache user (www-data) owns the directory and has write permissions.
  1. Check File Permissions: Ensure that the specific file (.env) you’re trying to extract can also be written by the Apache user. If needed, adjust the permissions:
sudo chmod 644 /var/www/html/agendarpost/.env
  1. Check Directory Ownership for ZipArchive: If you only want to give write permissions to ZipArchive operations without altering global permissions, consider changing ownership for the specific user or group responsible for Apache.
sudo chown -R www-data:www-data /var/www/html/agendarpost
  1. Disable SELinux (if applicable): If you’re on a system with SELinux enabled (such as CentOS), it might be blocking write access even if the permissions are correct. You can check SELinux status with:
sestatus

If SELinux is enforcing, you can either adjust the SELinux policy or temporarily disable it to test if that’s the issue:

sudo setenforce 0

If this resolves the issue, you’ll need to adjust SELinux policies properly to allow Apache to write to the directory.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.