0

I have a problem with linking my external storage to my PHP home directory.

I'm using Litespeed web server on Linux Centos 6 and everything work normally in my user home directory.

But I want to create a load balancer between my 2 hard drives for serving better in peak times.

I use configs below in httpd.conf to creating an alias and it works well when I'm trying to download files directly like https://example.com/cdn/file.mp4

Alias /cdn/ "/cdn/files/"
<Directory "/cdn/files">
    Options Indexes MultiViews
    AllowOverride All
    Require all granted
    Allow from all
</Directory>

But if I try to use the path in php scripts for example check file_exists seems that I can't.

I set my home user and group in external directories.

Any idea ?!

Update 1 : I tried symbolinks from home dir to external dir and still no result.

Update 2 : my simple php code :

<?php 
  if(file_exists('/cdn/files/file.mp4') || file_exists('/cdn/file.mp4') || file_exists('./cdn/file.mp4') || file_exists('./~cdn/file.mp4')){
    echo "yes";
  }else{
    echo "no";
  }
?>

result : no

APB
  • 307
  • 1
  • 2
  • 8
  • Are you able to access these files manually through the console? – TimSch Oct 08 '18 at 10:26
  • yeah, files are accessible and even I can download them directly with the link. – APB Oct 08 '18 at 10:30
  • Sorry it seems that I didn't read properly. Then please share the piece of code with which you use it. – TimSch Oct 08 '18 at 10:32
  • I don't think the problem is function because everything are fine when I'm using functions with main home directory path. file_exists('/cdn/files/file.mp4') or '/cdn/file.mp4' – APB Oct 08 '18 at 10:36
  • Well when you are able to access the remotely stored files your conf might work well. So I suspect your function call making trouble. – TimSch Oct 08 '18 at 10:51
  • Does the user who runs the script have permission to access the files? – TimSch Oct 08 '18 at 10:52
  • yes, the user and group is same as the main home directory and also directory permissions. – APB Oct 08 '18 at 11:02
  • Possible duplicate of https://stackoverflow.com/questions/6930150/file-exists-returns-false-but-the-file-does-exist – TimSch Oct 08 '18 at 11:34
  • nothing change. – APB Oct 08 '18 at 13:40

1 Answers1

0

The problem was in php.ini open_basedir value. I must append the full path to the new disk in open_basedir value.

Also add open_basedir value in httpd.conf file like below:

<Directory "/home/user/public_html">
   php_admin_value open_basedir /home/user/public_html/:/cdn/files
</Directory>

<VirtualHost myip:80>
   <Directory "/home/user/public_html">
      php_admin_value open_basedir /home/user/public_html/:/cdn/files
   </Directory>
</VirtualHost>

<VirtualHost myip:443>
   <Directory "/home/user/public_html">
      php_admin_value open_basedir /home/user/public_html/:/cdn/files
   </Directory>
</VirtualHost>

I hope this be useful for someone :)

APB
  • 307
  • 1
  • 2
  • 8