Im beginner in php language. in my web project i created a filepath.config.ini file which stores all file path in the website directories. for eg.
CLASS1 = bin/myclass1.php
CLASS2 = bin/myclass2.php
and im accessing those path by using:
require $_SERVER['DOCUMENT_ROOT'].'/'.GetfilePath('CLASS1');
in localhost server its working good and giving me path like this
D:/myproject/bin/myclass1.php
when i upload those file on test server im getting this open_basedir restriction error.
Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/usr/local/apache/htdocs/projectfolder/bin/myclass1.php) is not within the allowed path(s): (/home/:/usr/lib/php:/tmp)
i know we can disable this restriction...but i dont know how to do that :P.
but is it good to use this server DOCUMENT_ROOT ???
or is their any alternate way to use the file path? what you people do to access those file path.
and what happen if i disable the open_basedir restriction? is it secure to do that?
please help me what to do?
Edit your php.ini file (PHP: Configuration Changes) and either disable open_basedir or add /usr/local/apache/htdocs to it.
Related
I have a server with 30 websites.
Now I want to copy a file from site A to site B.
Code:
$sExternPath = str_replace(strtolower(SITENAME), strtolower($aBoardInfo['name']), CORE_PATH_PRIVATE);
$sNewLogo = file_get_contents(CORE_PATH_PRIVATE.'users_upload/company_logos/'.$sFileName);
//Put it in the folder
file_put_contents($sExternPath.$sFileName, $sNewLogo);
Error:
[20-Mar-2015 10:32:30] PHP Warning: file_put_contents() [function.file-put-contents]: open_basedir restriction in effect. File(/var/www/vhosts/SITEB.nl/private/logo.jpg) is not within the allowed path(s): (/var/www/vhosts/SITEA.nl/:/tmp/) in /var/www/vhosts/SITEA.nl/httpdocs/pages/login/script.php on line 1262
[20-Mar-2015 10:32:30] PHP Warning: file_put_contents(/var/www/vhosts/SITEB.nl/private/logo.jpg) [function.file-put-contents]: failed to open stream: Bewerking niet toegestaan in /var/www/vhosts/SITEA.nl/httpdocs/pages/login/script.php on line 1262
/var/www/vhosts/SITEB.nl is outside the tree set in the open_basedir setting -You need to edit your php.ini file and change the open_basedir setting to
'/var/www/vhosts/:/tmp/' rather than '/var/www/vhosts/SITEA.nl/:/tmp/' or unset it by commenting it out, then restart apache.
http://php.net/manual/en/ini.core.php#ini.open-basedir
When a script tries to access the filesystem, for example using include, or fopen(), the location of the file is checked. When the file is outside the specified directory-tree, PHP will refuse to access it. All symbolic links are resolved, so it's not possible to avoid this restriction with a symlink. If the file doesn't exist then the symlink couldn't be resolved and the filename is compared to (a resolved) open_basedir .
As per Wiris guide.
Give execution rights to the web server user on the PHP files contained at to ckeditor/plugins/ckeditor_wiris/integration.
→ My settings: Folder "integration": 755. All files inside this folder: 754
Give write permissions to ckeditor/plugins/ckeditor_wiris/cache and to ckeditor/plugins/ckeditor_wiris/formulas directories to the web server user. Those folders will be used to store formula MathML codes and temporal images.
→ My settings for these folder: 775
However, I get following warnings while trying to open Wiris "Math Popup", and doesn't open properly.
Warning: is_file(): open_basedir restriction in effect. File(/home/my_user_name/public_html/ckeditor/plugins/ckeditor_wiris/integration/../../../../../../../../lib/moodlelib.php) is not within the allowed path(s): (/home/my_user_name:/usr/lib/php:/tmp) in /home/my_user_name/public_html/ckeditor/plugins/ckeditor_wiris/integration/bootstrap.php on line 39
Warning: is_file(): open_basedir restriction in effect. File(/home/my_user_name/public_html/ckeditor/plugins/ckeditor_wiris/integration/../../../../../../lib/moodlelib.php) is not within the allowed path(s): (/home/my_user_name:/usr/lib/php:/tmp) in /home/my_user_name/public_html/ckeditor/plugins/ckeditor_wiris/integration/bootstrap.php on line 39
Are my permissions correct? Do these warnings relate to file/folder permissions? I am using www.serversfree.com webhosting to test this out.
It looks like there's an issue in your installation. Please check the plugin test page:
<url>/ckeditor/plugins/ckeditor_wiris/integration/test.php. There shouldn't be any errors there. Please review the installation instructions at http://www.wiris.com/plugins/docs/ckeditor.
Your permissions are correct. Those warnings are related to an extra check in the /integration/bootstrap.php file, it checks a directory several levels above your working directory and you're not allowed to do so due to an open_basedir restriction in your server. This issue will be fixed in our next plugin release. To supress the warning simply comment the whole bootstrap.php file or add a return true; right after <?php.
Edit: This issue is currently fixed in our latest version.
Please give permission to 777 to folder named cache and formulas
inside path
ckeditor4/plugins/ckeditor_wiris
I have a VPS using FastCGI (WHM/cPanel). As I understand it, open_basedir must be set using a php.ini file in each user's /home/ directory (E.g.: setting it globally in apache config file will not work).
I want to use open_basedir for improved security, as I recently had a hack that involved traversing through different user's directories
I have added this value to a home directory's php.ini file:
open_basedir = /home/USERNAME/public_html:/usr/lib/php:/usr/local/lib/php:/tmp
What I want to know is, is there a way to test that this is functioning properly? Presumably I would want to try and execute a .php file in another user's directory from within that first user...however I don't know of a good way to test this. Any suggestions would be greatly appreciated.
Try listing the contents of a different user's public_html folder:
<?php
print_r(shell_exec('ls /home/$anotheruser/public_html/'));
?>
If open_basedir is configured properly, you will see a directory listing for that folder.
Running PHP 5.3.1 on a Windows server, I have to modify a PHP script to access XML files on a network share. For various reasons the files cannot be placed on the PHP server, and I am not allowed to create a mapped drive on the PHP server so I have to modify the open_basedir parameter in PHP.ini to include the UNC path to the share, e.g.:
open_basedir = "E:\inetpub\;E:\DB_HubDataFiles\;\\stdmfps01\inter-departements$\CVSC-CDT-Estimation-Cedule\"
However when I try to access files on the share I get the "open_basedir restriction in effect" error. I am trying to access the files as follows:
$jobfilename = "//stdmfps01/inter-departements$/CVSC-CDT-Estimation-Cedule/" .$job . ".xml";
if (file_exists($jobfilename)) {
$jobxml = simplexml_load_file($jobfilename);
etc...
I have been assured that it is not a problem of rights, and anyway the error indicates a problem with open_basedir. So my questions are:
does open_basedir handle UNC paths under Windows (I have seen conflicting statements about this)?
if so is there some problem with my syntax?
do I have other options than using open_basedir?
Thanks.
Anyway, here's what ended up working for me, even if I am not totally clear why:
In php.ini changed the open_basedir parameter to use the IP address instead of the server name, and used the parent directory of the directory where my files are located, instead of the directory itself:
\\\nnn.nnn.nnn.nnn\inter-departements$\
instead of:
\\servername\inter-departements$\CVSC-CDT-Estimation-Cedule\
In the PHP script used the IP address as well:
$jobfile = "//nnn.nnn.nnn.nnn/inter-departements$/CVSC-CDT-Estimation-Cedule/" . ($jobid) . ".xml";
This worked for me: Replace the backslashes with slashes
open_basedir = "E:\inetpub\;E:\DB_HubDataFiles\;//stdmfps01/inter-departements$/CVSC-CDT-Estimation-Cedule/"
I've got some trouble on a apache2 server with using symlink.
The base www folder is in "/var/www//htdocs".
I did a symlink form /home//log" to "/var/www//htdocs/l/" and called it "log".
In my oppinion, all rights are given correctly for the www-data user and the group for .
In my script, i got this error:
Warning: fopen(): open_basedir restriction in effect.File(/var/www/<domain>/htdocs/l/log/logs_test.log) is not within the allowed path(s): (/var/www/<domain>:/usr/share/pear:/usr/share/php:/tmp:/usr/share/phpmyadmin) in /var/www/<domain>/htdocs/l/test.php on line 7 Warning: fopen(/var/www/<domain>/htdocs/l/log/logs_test.log): failed to open stream: Operation not permitted in /var/www/<domain>/htdocs/l/test.php on line 7
This problem should be solved when I add in the apache2.conf the real-path from the symlink. But, and this is my problem: I would not add the real-path for every symlink.
I hope you can understand my problem, if you need some more information, let me know.
Yes the problem is with the open_basedir security restrictions in PHP. You just need to relax the restriction if you want to open files outside the specified directory tree. Read here for more options on how to do this:
http://www.php.net/manual/en/ini.core.php#ini.open-basedir