php filehandling in a symlink doesn't work - php

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

Related

Accessing files that are on another hard disk

Recently I mounted another hard drive to /mnt/sdb on Debian server as the first hard disk was already full. Then, I started to upload files to the second hard drive such as images.
In order to access new files, I created a shortcut from web folder and linked to the new hard drive folder. I can access files through html and everything is working fine, but The problem is when I access files via php with functions such as imagecreatefromjpeg I receive following errors:
Warning: imagecreatefromjpeg(): open_basedir restriction in effect.
File(foldername/filename.jpg) is not within the allowed path(s):
Warning: imagecreatefromjpeg(foldername/filename.jpg): failed to open stream: Operation not permitted
How can I access files with php functions?
Supposing your PHP is implemented as a module of apache, locate your php.ini file (it could be /etc/php/7.1/apache2/php.ini), you will find a not uncommented line beginning with open_basedir = and append the path to the directory where the pictures are, something like /mnt/sdb/some_sub_directory, using : as separator from the previous path.
After saving changes in the php.ini file, restart apache for applying these with some command like:
sudo /etc/init.d/apache2 restart

PHP: Copy file from site A to site B

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 .

CKEditor integration with Wiris PHP plugin: open_basedir restriction

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

Permission denied when opening localhost

I had recently installed Apache, PHP and MySQL in Ubuntu. And copied the files I created to the var/www directory. But when I open http://localhost it is showing
Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Fatal error: Unknown: Failed opening required '/var/www/index.php'
(include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
How can I run my project normally? It was working fine in windows.
According to this article, you need to give read/execute permissions to Owner, Group, and Everyone.
Set permissions on the problem file to 777. Note, you should avoid doing this on a server that's accessible from the internet.
http://webomania.wordpress.com/2007/03/12/permission-denied-in-unknown-on-line-0/
To fix this problem, look at the line in your ErrorLog, to find out which folder it is trying to access.
If a block already exists for that folder, make sure it is set to allow access as necessary. If not, add a block to your Apache configuration file, allowing access as required. See the example below for folder /usr/local/awstats/htdocs.
Order allow,deny
Allow from all
for a complete reference, check the apache wiki

Open Base Directory Cross Domain

Changing the open_basedir directive to work with subdomains works absolutely fine on my server by simply setting the directive to:
C:\Inetpub\vhosts\domain.net\subdomains\beta\httpdocs\;C:\Inetpub\vhosts\domain.net\httpdocs\
However, when I try to do the same from one hostname to another, the open base directory does not work. This is what I am setting:
C:\Inetpub\vhosts\domainOne.net\httpdocs\;C:\Inetpub\vhosts\domainTwo.net\httpdocs\
I know that this can be quite challenging to achieve with FastCGI and PHP, but surely there is an easy fix?
I have tried giving permissions to the user of the current site, on the other sites folder but this has not worked.
The error being returned (as expected) is the following:
Warning: include(): open_basedir restriction in effect.
File(C:\Inetpub\vhosts\domainOne.net\httpdocs_snippets_global\paths.php)
is not within the allowed path(s):
(C:\Inetpub\vhosts\domainTwo.com\httpdocs\;C:\Inetpub\vhosts\domainOne.net\httpdocs)
in C:\Inetpub\vhosts\domainTwo.com\httpdocs\index.php on line 3
Warning:
include(C:\Inetpub\vhosts\domainOne.net\httpdocs_snippets_global\paths.php):
failed to open stream: Operation not permitted in
C:\Inetpub\vhosts\domainTwo.com\httpdocs\index.php on line 3
So my question is, how do I open the base directory cross domain on a Windows Server running IIS 7, Plesk 11 and PHP 5.3 running as FastCGI Application?
Thanks in advance
All sorted, the open base directory setting was indeed correct.
I was on the right lines with adding permissions to the user, I just added the wrong user!
So quite simply, if you run into this, assuming this is the issue you are experiencing, just make sure the user of the website in question also has permissions on the folder and files of the included directory.

Categories