PHP Warning: Unknown: failed to open stream

PHP Warning: Unknown: failed to open stream

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP Warning: Unknown: failed to open stream

When you encounter the error PHP Warning: Unknown: failed to open stream accompanied by a "Permission denied" message, it is almost never a mystery about how PHP handles streams internally. It is a straightforward filesystem issue where the Apache process lacks the necessary privileges to access the requested resource.

In the scenario described, editing the httpd.conf file to enable mod_rewrite triggered this behavior immediately. While enabling rewrite rules involves modifying configuration directives like RewriteEngine On, it does not inherently strip permissions from directories or files. However, the act of editing a core configuration file often coincides with other system changes or permission resets that are easily overlooked.

The logs provide the definitive clue:
PHP Fatal error: Unknown: Failed opening required '/var/www/html/yomig/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

Notice the path /var/www/html/yomig. In typical Linux distributions, the www-data or apache user runs as a non-root service for security. If you recently edited files manually using sudo, the ownership of those specific files might still belong to your personal user account (e.g., youruser), while the Apache process tries to read them as www-data. This mismatch results in a permission denied error.

Diagnosing Ownership Mismatches

The discrepancy becomes glaringly obvious when comparing how different applications behave. Small scripts consisting of 4–5 files often run fine because they are likely located in directories where permissions were already correctly set, or the script was created by root or the web server user itself. Conversely, large software suites like PrestaShop (or the yomig directory in this case) usually involve a complex directory structure with thousands of files. If you manually copied these files or edited them individually without adjusting ownership, the permission error manifests as a wall of noise because Apache cannot open a single file required to load the application.

To resolve this, you must ensure that the web server user owns the entire project directory. On Debian-based systems, run the following command to change ownership recursively:

sudo chown -R www-data:www-data /var/www/html/yomig

For RHEL/CentOS/Fedora systems, replace www-data with apache or apache2:

sudo chown -R apache:apache /var/www/html/yomig

Verifying Directory Permissions

Ownership is only half the battle. You must also ensure that directories allow traversal and files allow execution or reading. Standard practice for web roots involves setting directories to 755 (or 750) and files to 644. If a directory is set to 700, Apache cannot enter it, leading to the same "failed to open stream" error.

You can enforce these permissions globally using find:

sudo find /var/www/html/yomig -type d -exec chmod 755 {} \;
sudo find /var/www/html/yomig -type f -exec chmod 644 {} \;

The Mod_rewrite Context

Regarding the mod_rewrite configuration change: enabling this module itself does not cause permission issues. However, if you added a RewriteBase directive or aliased a directory in your .htaccess file without ensuring that directory is accessible to the web server, Apache will attempt to serve content it cannot read. The error log entry File does not exist: /var/www/html/favicon.ico further suggests that while the main application fails due to permission issues, static assets might also be missing or misconfigured in the virtual host setup.

If you are using a shared hosting environment where you cannot change file ownership via SSH, this specific error usually indicates that your hosting provider has restricted access to certain folders after a configuration update, or you need to contact them to reset permissions for the large application files.

Preventing Future Issues

When deploying large applications like PrestaShop, always run the installation script as the web server user if possible, or ensure the deployment process explicitly sets ownership and permissions immediately after file transfer. Relying on manual edits without a subsequent permission check is a common pitfall when scaling from small prototypes to full-scale e-commerce platforms.

Our network