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
Related
I'm trying to run this code:
$img = new Imagick('ttt.jpg');
$quality = $img->getImageCompressionQuality();
echo $quality;
I have two websites which have this code and they are running on plesk.
This code works fine on one of the websites but on the other one I get:
open_basedir restriction in effect. File is not within the allowed path
I gave the permission of 777 to the folder and containing files.
Both websites are using PHP 7.3 and therefore the same php.ini file
I'm using Plesk and Windows Server 2016
What am I missing?
Ok I got it, it's in the PHP settings of each website, there is an option called open_basedir which is set to none on the website on which the imagick code works
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 .
I'm running php 5.5.12 on Windows Server 2008 with IIS7 and FastCGI.
Here's one of the log errors I'm getting:
file_put_contents(): open_basedir restriction in effect. File(C:\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.0.3\content\vod\test.smil) is not within the allowed path(s): (C:\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.0.3\content\vod;C:\Windows\TEMP\;E:\webpage;C:\php) in E:\webpage\dev\vod\createsettings.php on line 41
Here's my open_basedir line in php.ini:
open_basedir = "C:\Program Files (x86)\Wowza Media Systems\Wowza Streaming Engine 4.0.3\content\vod;C:\Windows\TEMP\;E:\webpage;C:\php"
As you can see, the destination directory is in fact specified in open_basedir, but it's acting as if it's restricted.
Commenting out open_basedir and restarting IIS results in no error and everything works as expected.
Changing the destination directory to one of the other open directories (C:\Windows\TEMP, for example) also works fine with no errors.
I've read eight pages worth of issues here but haven't seen a match. Thanks in advance for any help you can offer!
You're going to run into a lot of permission issues trying to use PHP and C:\Program Files (x86). Both the 32-bit and 64-bit Program Files directories in Windows are very picky when it comes to write permissions. If you move the directory outside of Program Files and right into the C:\ drive it should alleviate some problems. (i.e., C:\temp is usually easily accessible with PHP when doing file uploads, session storage, etc...).
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
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.