Title: SetEnv
Last modified: September 11, 2019

---

# SetEnv

 *  Resolved [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/setenv/)
 * Hi,
 * This is a great plugin but I can’t use on my hosting as the host will not allow‘
   SetEnv’ on the in the config. Is there any way to avoid this?
 * Thanks,
    Ben

Viewing 15 replies - 1 through 15 (of 15 total)

 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11923121)
 * Ahh.
    We should be able to overcome this. We could create a _.htaccess_ file 
   in the folder where WebP Express stores the webp images and add the following
   rule:
 *     ```
       <IfModule mod_headers.c>
         <FilesMatch "\.webp$">    
           Header append "Vary" "Accept"
         </FilesMatch>
       </IfModule>
       ```
   
 * If you have set “Destination folder” to “mingled”, those rules will also need
   to be added to the .htaccess in the uploads folder.
 * In a similar fashion, you should add vary:accept header for jpegs and pngs too.
   This needs to be put in a .htaccess that contains the original images, ie in 
   uploads or wp-content:
 *     ```
       <IfModule mod_headers.c>
         <FilesMatch "\.(jpe?g|png)$">    
           Header append "Vary" "Accept"
         </FilesMatch>
       </IfModule>
       ```
   
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11923123)
 * I shall test this out tomorrow.
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11924689)
 * Yes, it does indeed work.
    And actually, you don’t even need the FilesMatch directive
   in the cache folder, as there is only webp files stored there.
 * So, create an .htaccess file in `wp-content/webp-express/webp-images/.htaccess`
   and insert the following:
 *     ```
       <IfModule mod_headers.c>;
           Header append "Vary" "Accept"
       </IfModule>
       ```
   
 * – And make sure to set the “Destination folder” to “separate”.
 * And add this to your `wp-content/.htaccess`:
 *     ```
       <IfModule mod_headers.c>
         <FilesMatch "\.(jpe?g|png)$">    
           Header append "Vary" "Accept"
         </FilesMatch>
       </IfModule>
       ```
   
 * This will get the Varied Image responses work.
 * Alternatively, you could of course simply rely on Alter HTML.
    -  This reply was modified 6 years, 7 months ago by [rosell.dk](https://wordpress.org/support/users/roselldk/).
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11924698)
 * I have added a task to the roadmap to have WebP Express detect when SetEnv is
   unavailable and modify the rules accordingly.
    [https://github.com/rosell-dk/webp-express/issues/332](https://github.com/rosell-dk/webp-express/issues/332)
 *  Thread Starter [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11929300)
 * Hi Rosell,
 * Thanks for the great support on this. This does not work for me, I have made 
   the updates as recommended and its still breaks the site. I am sure its SetEnv
   as I have the plugin working great on a different site with more or less the 
   same set up (same theme and plugins) but hosting which allows SetEnv and is working
   great.
 * Thanks,
    Ben
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11939792)
 * Ok. I will close this for now. I’m guessing that it is very unusual not to have
   SetEnv. When I try to disable it on my local machine it warns me that it is an
   essential module and that disabling it is a very a bad idea.
 * I shall get back to you if I make any progress on this.
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11939804)
 * Oh, btw, there is a new 0.15.0 out which has changes in the .htaccess rules and
   test buttons for testing out the rules. Could you try it out and tell me which
   of the rules that works? (there is a test button next to each)
 *  Thread Starter [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11947316)
 * Thanks again for looknig into the this problem. With the new version I am getting
   fatal error, when trying to activate the plugin –
 * Fatal error: Uncaught Exception: Cannot get relative path from document root 
   to dir without resolving to directory traversal. It seems the dir is not below
   document root in /data/shardstor02/home/161a313b13fawgsi/public_html/wp-content/
   plugins/webp-express/lib/classes/PathHelper.php:162 Stack trace: #0 /data/shardstor02/
   home/161a313b13fawgsi/public_html/wp-content/plugins/webp-express/lib/classes/
   Paths.php(476): WebPExpress\PathHelper::getRelPathFromDocRootToDirNoDirectoryTraversalAllowed(‘/
   data/shardstor…’) #1 /data/shardstor02/home/161a313b13fawgsi/public_html/wp-content/
   plugins/webp-express/lib/classes/HTAccessRules.php(234): WebPExpress\Paths::getCacheDirForImageRoot(‘
   separate’, ‘doc-root’, ‘themes’) #2 /data/shardstor02/home/161a313b13fawgsi/public_html/
   wp-content/plugins/webp-express/lib/classes/HTAccessRules.php(779): WebPExpress\
   HTAccessRules::redirectToExistingRules() #3 /data/shardstor02/home/161a313b13fawgsi/
   public_html/wp-content/plugins/webp-express/lib/classes/HTAccess.php(417): WebPExpress\
   HTAccessRules:: in /data/shardstor02/home/161a313b13fawgsi/public_html/wp-content/
   plugins/webp-express/lib/classes/PathHelper.php on line 162
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11947485)
 * Thanks for reporting!!!
 * I found the bug.
    Can you please test it for me?
 * In `plugins/webp-express/HTAccessRules.php` line 231 you should see the following
   code:
 *     ```
                       $cacheDirForThisRoot = Paths::getCacheDirForImageRoot(
                           self::$config['destination-folder'],
                           self::$config['destination-structure'],
                           self::$htaccessDir
                       );
       ```
   
 * Change it to:
 *     ```
                       $cacheDirForThisRoot = Paths::getCacheDirForImageRoot(
                           self::$config['destination-folder'],
                           'image-roots',
                           self::$htaccessDir
                       );
       ```
   
 * That should solve the particular bug. But the trouble is that the “destination
   structure” option is set to “doc-root” on your system where document root cannot
   be used. In order to prevent other errors, the value should not be defaulted 
   to “doc-root” when doc-root cannot be used.
 * In config.php, I have changed line 70 to:
 * ‘destination-structure’ => (Paths::canUseDocRootForRelPaths() ? ‘doc-root’ : ‘
   image-roots’),
 * Hope to hear from you soon!
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11947554)
 * I have released the above changes as 0.15.3. I’m pretty confident they will fix
   the problem. But still hope to hear from you soon 🙂
 *  Thread Starter [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11958748)
 * Hi Rosell,
 * I am still having problems. Getting this message –
 * +++++++++++++++++++++++++++
 * Sep 19 11:54:40 tp-web02-a apache2-error [Thu Sep 19 10:39:04.945544 2019] [php7:
   error] [pid 9069] [client 10.7.45.27:48536] PHP Fatal error: Uncaught Exception:
   Cannot get relative path from document root to dir without resolving to directory
   traversal. It seems the dir is not below document root in /data/shardstor02/home/
   161a313b13fawgsi/public_html/wp-content/plugins/webp-express/lib/classes/PathHelper.
   php:162\nStack trace:\n#0 /data/shardstor02/home/161a313b13fawgsi/public_html/
   wp-content/plugins/webp-express/lib/classes/Paths.php(476): WebPExpress\\PathHelper::
   getRelPathFromDocRootToDirNoDirectoryTraversalAllowed(‘/data/shardstor…’)\n#1/
   data/shardstor02/home/161a313b13fawgsi/public_html/wp-content/plugins/webp-express/
   lib/classes/SelfTestHelper.php(44): WebPExpress\\Paths::getCacheDirForImageRoot(‘
   separate’, ‘doc-root’, ‘uploads’)\n#2 /data/shardstor02/home/161a313b13fawgsi/
   public_html/wp-content/plugins/webp-express/lib/classes/SelfTestRedirectAbstract.
   php(71): WebPExpress\\SelfTestHelper::cleanUpTestImages(‘uploads’, Array)\n#3/
   data/shardstor02/home/161a313b13fawgsi/public_html/wp-content/plugins/webp-express/
   lib/classes/SelfTestRedirectAbstract in /data/shardstor02/home/161a313b13fawgsi/
   public_html/wp-content/plugins/webp-express/lib/classes/PathHelper.php on line
   162, referer: [https://allurban-uat.mytimpani.co.uk/wp-admin/options-general.php?page=webp_express_settings_page](https://allurban-uat.mytimpani.co.uk/wp-admin/options-general.php?page=webp_express_settings_page)
 * +++++++++++++++++++++++++
 * Technical support from my hosting company commented –
 * I’m not sure why the plugin isn’t using the WordPress core functions for finding
   where directories are. It seems they’re worked out that wp-content is a symlink,
   and they’re trying to work out exactly where it’s full path on the system is.
   I’m not sure if there’s any reason they need the full path, on linux, they can
   ignore the fact there’s a symlink there, and it should Just Work for basically
   anything?
 * At a guess, what’s might be catching them out is that they’re might be trying
   to recurse through the open_basedir restriction we set as an additional restriction
   to what any one site can access so we can monitor if someone’s trying to break
   out of their jail (they’d typically hit open_basedir restrictions, causing logs
   whilst playing).
 * +++++++++++++++++++++++++
 * I hope this helps and thanks for sticking with this issue. If this is turning
   out too mch work don’t worry but I would really like to use this plugin. On other
   hosting where I have had a sucessfully set up it’s had a very positive impact.
 * Thanks,
    Ben
 *  Plugin Author [rosell.dk](https://wordpress.org/support/users/roselldk/)
 * (@roselldk)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11958769)
 * The error you got there is when you run the self-test, right?
    Try saving options
   and then running self-test. Make sure that “Destination structure” is “image-
   roots” (the other option should not be selectable)
 *  Thread Starter [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11959334)
 * Hi,
 * I am still failing on the 2nd and 3rd tests. This time the plugin is not breaking
   the site but the most of the images are no appearing. Below is a copy of the 
   test code which are failing. I was hopping to attached a screen shot of the settings
   to make sure all look OK but not possible through this tread.
 * **_[ 1,029,048 characters removed ]_**
    -  This reply was modified 6 years, 7 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11959497)
 * @benrobert Please do not post large code or responses like that here, it doesn’t
   work after ~10 lines or so. You posted much more than that.
 * If you need share that data please use [https://pastebin.com/](https://pastebin.com/)
   instead and post the link to that paste.
    -  This reply was modified 6 years, 7 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
 *  Thread Starter [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * (@benrobertson)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11960202)
 * Sorry about the excessive code.
 * Here are the summaries from test 2 (Testing redirection to converter) –
 * Making a HTTP request for the test image (pretending to be a client that supports
   webp, by setting the “Accept” header to “image/webp”). FAILED
    Request URL: [http://allurban-uat.mytimpani.co.uk/wp-content/uploads/webp-express-test-images/LHiHgO.JPEG](http://allurban-uat.mytimpani.co.uk/wp-content/uploads/webp-express-test-images/LHiHgO.JPEG)
   Response: 500 Internal Server Error
 * Here are the summaries from test 3 (Create webp files upon request?)
 * However. As the “content-type” header reveals, we did not get a webpSurprisingly
   we got: “text/html; charset=UTF-8”
    The test FAILED.
 * Thanks,
    Ben

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘SetEnv’ is closed to new replies.

 * ![](https://ps.w.org/webp-express/assets/icon.svg?rev=1918288)
 * [WebP Express](https://wordpress.org/plugins/webp-express/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/webp-express/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/webp-express/)
 * [Active Topics](https://wordpress.org/support/plugin/webp-express/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/webp-express/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/webp-express/reviews/)

 * 15 replies
 * 3 participants
 * Last reply from: [BenRobertson](https://wordpress.org/support/users/benrobertson/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/setenv/#post-11960202)
 * Status: resolved