SLSCoder Posted February 7, 2023 Share Posted February 7, 2023 I'm trying to access a font file: usr/share/fonts/truetype/verdana.ttf As you can see the file does exist and owner, group and public have permissions to read it. It is owned by root not www-data but I can't see how that's a problem if public has read permissions. My code: if(file_exists("usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; returns: file does NOT exist no file How can I make my fonts in usr/share/fonts/truetype/ accessible to PHP? Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/ Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 /usr Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605459 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 Thanks. I can't believe I didn't see that! It didn't work though. So, now my code is: if(file_exists("/usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; The response is still: file does NOT exist no file Also, when I showed errors none appeared. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605460 Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 Add this line echo "Root: {$_SERVER['DOCUMENT_ROOT']}<br>"; Let's see what you are using and determine if the /usr folder is part of your domain. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605461 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 It is not part of the domain. I don't see why that'd matter. Root: /var/www/dev.aecperformance.com file does NOT exist no file Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605464 Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 If the root of your domain is /var/www.... you are clearly reaching outside of that with /usr.... Could you post the actual code you ran to produce this last post? Curious. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605467 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 Then is it impossible to access folders outside the domain root from the website like /usr/share/ ? I'm accessing multiple folders in /var/www/ for things like PHPWord, JpGraph, etc. They're accessible to all the domains I run. In fact, the app that needs the fonts is JpGraph. <?php echo "Root: {$_SERVER['DOCUMENT_ROOT']}<br>"; if(file_exists("/usr/share/fonts/truetype/verdana.ttf")) echo "file exists<br>"; else echo "file does NOT exist<br>"; $file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf"); if($file === false) echo "no file<br>"; else echo $file . "<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605469 Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 Are you serving this domain yourself on your own box? Or is it shared hosting from somebody else? If it is shared then you only have the part of the box then begins with the first two parts of that 'root' path, I think. My root has 3 folders of which the lowest one is the web root folder. I can see one folder above that where I store things like my php files so they are not available using html. Your php can probably only see /var/www Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605470 Share on other sites More sharing options...
requinix Posted February 7, 2023 Share Posted February 7, 2023 Also, take a look at your PHP error logs, in case there's anything in there that might be relevant to this issue... And by the way, even if this isn't shared hosting and you own the box, if you need the Verdana font then just bundle it into your application's codebase. Far more reliable than making sure you have fonts installed on what should be a headless box. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605471 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 It's my box. It's a standard debian apache 2 installation. All the sites are in /var/www/ Where are the PHP error logs? What does "bundle it into your application's codebase" mean? Multiple sites; multiple PHP apps will need access to the fonts. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605472 Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 Move the fonts folder to something in or below /var/www such as /var/www/fonts That way all of your apps should see them no matter which domain they are in. Of course I have no experience in running apps so I may be wrong but that would make sense to me. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605473 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 OK, I moved the fonts to /var/www/fonts/truetype and set ownership & group to www-data. The permissions look right. JpGraph seems to be happy now. Funny though, the JpGraph default path was /usr/share/fonts/truetype which is what sent me down that trail. I just didn't realize that you can't access any folder on the server from a PHP website. It's fixed now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605474 Share on other sites More sharing options...
requinix Posted February 7, 2023 Share Posted February 7, 2023 Just now, SLSCoder said: I just didn't realize that you can't access any folder on the server from a PHP website. You can, but it depends on configuration. Or a lack of, such as for the open_basedir PHP setting that would restrict your code from doing anything outside of a specific set of directories if it had been set. I don't know where your PHP logs are. Start looking at /var/log. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605475 Share on other sites More sharing options...
SLSCoder Posted February 7, 2023 Author Share Posted February 7, 2023 Thanks. open_basedir is not set. It's remmed out. I saw that on stackoverflow. You were right /var/log Nothing in there. I wonder why it wouldn't access /usr/share. Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605478 Share on other sites More sharing options...
ginerjm Posted February 7, 2023 Share Posted February 7, 2023 Because you put your root in a different branch of the file system. I think the sample you used was just that - a sample. Your user (as you now see) had to be "/var/www". When you setup your tree on day 1 if you had used 'usr' things would have worked. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315890-why-cant-i-access-the-fonts-directory-from-php/#findComment-1605479 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.