Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path is outside resolved document root when using Apache Alias directive. #585

Open
annpocoyo opened this issue May 13, 2023 · 1 comment

Comments

@annpocoyo
Copy link

Problem:

My httpd configuration uses the Alias /blog /opt/homebrew/var/httpd/wordpress directive so I don't break the permissions of the blog. But this causes the plugin to think the path is outside document root.

Relevant part of httpd.conf:

# WordPress
Alias /blog /opt/homebrew/var/httpd/wordpress
<Directory /opt/homebrew/var/httpd/wordpress/>
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   <IfModule mod_authz_core.c>
	  Require all granted
   </IfModule>
   <IfModule !mod_authz_core.c>
      Order allow,deny
      Allow from all
   </IfModule>
</Directory>
@annpocoyo
Copy link
Author

A workaround is to manually set $_SERVER['DOCUMENT_ROOT'] to $_SERVER['CONTEXT_DOCUMENT_ROOT'] which returns the correct document root in this context.

This is best done by setting the auto_prepend_file php configuration directive which automatically loads a php file before any piece of code.

Here's a example:

fix-doc-root.php (Place anywhere):

<?php
$_SERVER['DOCUMENT_ROOT'] = $_SERVER['CONTEXT_DOCUMENT_ROOT'];

Updated part of httpd.conf:

# WordPress
Alias /blog /opt/homebrew/var/httpd/wordpress
<Directory /opt/homebrew/var/httpd/wordpress/>
   # Fix DOCUMENT_ROOT
   php_value auto_prepend_file path/to/fix-doc-root.php

   # Other stuff
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   <IfModule mod_authz_core.c>
	  Require all granted
   </IfModule>
   <IfModule !mod_authz_core.c>
      Order allow,deny
      Allow from all
   </IfModule>
</Directory>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant