{"id":8637,"date":"2014-11-10T07:01:26","date_gmt":"2014-11-10T07:01:26","guid":{"rendered":"https:\/\/wp.okra.host\/article\/open_basedir-restriction-message\/"},"modified":"2021-03-07T14:37:54","modified_gmt":"2021-03-07T13:37:54","slug":"open_basedir-restriction-message","status":"publish","type":"ht_kb","link":"https:\/\/kb.okra.host\/de\/article\/open_basedir-restriction-message\/","title":{"rendered":"open_basedir-Beschr\u00e4nkungsmeldung"},"content":{"rendered":"<h2 id=\"overview\" >Overview<\/h2>\n<p>When attempting to access a file in PHP, the script will yield a warning similar to:<\/p>\n<pre><b>Warning<\/b>: fopen(): open_basedir restriction in effect. File(\/var\/www\/myresource) is not within the allowed path(s): \r\n(\/home\/virtual\/site2\/fst:\/var\/www\/html:\/usr\/local:\/usr\/bin:\/usr\/sbin:\/etc:\/tmp:\/proc:\/dev:\/.socket) in <b>\/home\/virtual\/site2\/fst\/var\/www\/html\/myfile.php<\/b> on line <b>3<\/b><\/pre>\n<h2 id=\"cause\" >Cause<\/h2>\n<p>This is caused by mistakenly referencing a path within a pivot root inconsistent with PHP.\u00a0PHP runs with a separate filesystem visibility for high-throughput performance, whereas FTP and control panel access require\u00a0low-throughput, but heightened security. PHP implements\u00a0a different security subsystem and different access rights.<\/p>\n<h2 id=\"solution\" >Solution<\/h2>\n<p>Prepend the\u00a0<em>HTTP Base Prefix<\/em> value taken from the <a title=\"Logging into the control panel\" href=\"https:\/\/kb.okra.host\/control-panel\/logging-into-the-control-panel\/\">control panel<\/a> under\u00a0<strong>Account<\/strong> &gt;\u00a0<strong>Summary<\/strong> &gt;\u00a0<strong>Web<\/strong>. For example, the following PHP snippet would be corrected as follows:<\/p>\n<pre data-language=\"php\"><code>&lt;?php\r\n   \/\/ INCORRECT\r\n   \/\/ Will yield open_basedir warning\r\n   $key = file_get_contents(\"\/var\/www\/secret.hash\");\r\n   \/\/ CORRECT\r\n   $key = file_get_contents(\"\/home\/virtual\/site12\/fst\/var\/www\/secret.hash\");\r\n?&gt;<\/code><\/pre>\n<p>For convenience, the web server will populate an environment variable named <code>SITE_ROOT<\/code> that contains the value of <em>HTTP Base Prefix<\/em>. A better example would be:<\/p>\n<pre data-language=\"php\"><code>&lt;?php\r\n   $key = file_get_contents($_SERVER['SITE_ROOT'] . \"\/var\/www\/secret.hash\");\r\n   \/\/ do whatever, $key works!\r\n?&gt;<\/code><\/pre>\n<p>Just don&#8217;t forget too that PHP requires <a title=\"Writing to files\" href=\"https:\/\/kb.okra.host\/php\/writing-to-files\/\">special\u00a0permissions<\/a> for write\u00a0access!<\/p>\n<h2 id=\"see-also\" >See Also<\/h2>\n<p>PHP: <a title=\"Writing to files\" href=\"https:\/\/kb.okra.host\/php\/writing-to-files\/\">Writing to files<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview When attempting to access a file in PHP, the script will yield a warning similar to: Warning: fopen(): open_basedir restriction in effect. File(\/var\/www\/myresource) is not within the allowed path(s): (\/home\/virtual\/site2\/fst:\/var\/www\/html:\/usr\/local:\/usr\/bin:\/usr\/sbin:\/etc:\/tmp:\/proc:\/dev:\/.socket) in \/home\/virtual\/site2\/fst\/var\/www\/html\/myfile.php on line 3 Cause This is caused by mistakenly referencing a path within a pivot root inconsistent&#8230;<\/p>","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[63],"ht-kb-tag":[],"class_list":["post-8637","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-php"],"_links":{"self":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/comments?post=8637"}],"version-history":[{"count":1,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8637\/revisions"}],"predecessor-version":[{"id":8638,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8637\/revisions\/8638"}],"wp:attachment":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/media?parent=8637"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-category?post=8637"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-tag?post=8637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}