You are not logged in.

#1 2014-03-12 23:00:33

kwhershey
Member
Registered: 2012-08-27
Posts: 16

Apache Directory access problems

I'm having problems accessing a directory from a php script.  I know the php is correct since I had it loaded on my raspberry pi and it worked there, but the arch apache permissions are a little more strict.  The relevant portions of my httpd.conf are:

<Directory />
    Options FollowSymLinks Indexes
    AllowOverride all
    Order deny,allow
    Allow from none
</Directory>


<Directory /media/external/hosting>
    Options FollowSymLinks Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

and in my php, I try to access the folder with:

 $dir=opendir("/media/external/hosting/");
while (($file=readdir($dir)) !== false)
{
    if ($file != "." and $file != ".." and $file != "index.php")
    {
        array_push($files, $file);
    }
}
closedir($dir);

I have tried looking at other explanations of how to do this, and mine seems to match, but it's not working.  Is there something wrong with my httpd.conf?  Is this the proper way to allow access to this directory?

Offline

#2 2014-03-12 23:20:36

kermana
Member
Registered: 2009-04-13
Posts: 60

Re: Apache Directory access problems

Have you tried adding "/media/external/hosting/" to the open_basedir in php.ini?

From the php docs:

open_basedir string
Limit the files that can be accessed by PHP to the specified directory-tree, including the file itself. This directive is NOT affected by whether Safe Mode is turned On or Off.

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 don't have much php experience but my understanding is that it will refuse to access anything on filesystem unless it is explicitly allowed to do so.

Last edited by kermana (2014-03-12 23:21:08)

Offline

#3 2014-03-12 23:24:17

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,572
Website

Re: Apache Directory access problems

kwhershey wrote:
    Order deny,allow
    Allow from none

Are you using Apache 2.2? If not, this is wrong. Seek out the mega-thread on the apache update, or/and read the migration notes for Apache 2.2 -> 2.4.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2014-03-13 01:28:12

kwhershey
Member
Registered: 2012-08-27
Posts: 16

Re: Apache Directory access problems

I am using Apache 2.2.

Offline

#5 2014-03-14 20:00:30

kwhershey
Member
Registered: 2012-08-27
Posts: 16

Re: Apache Directory access problems

I also added /media/external/hosting/ to my open_basedir and it didn't work.  Still no response from the page.

Offline

#6 2014-03-15 00:03:51

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,730
Website

Re: Apache Directory access problems

What are the current permissions of the directory where the file in question resides?

R.

Offline

#7 2014-03-15 02:36:38

kwhershey
Member
Registered: 2012-08-27
Posts: 16

Re: Apache Directory access problems

Fully open.  rwx for all, owned by my local user with the users group.  I don't really care who owns it, that's just what it's set as.

Offline

#8 2014-03-15 04:54:32

ralvez
Member
From: Canada
Registered: 2005-12-06
Posts: 1,730
Website

Re: Apache Directory access problems

Are you using "plain old" PHP or are you using a Framework?

p.s: Also, what do you see in your /var/log/httpd/error_log?

Last edited by ralvez (2014-03-15 04:56:41)

Offline

#9 2014-03-15 17:10:46

kwhershey
Member
Registered: 2012-08-27
Posts: 16

Re: Apache Directory access problems

There are just a ton of warnings:

 PHP Warning: readdir() expexts parameter 1 to be resource, boolean given 

I'm assuming these are all from the opendir not working, so it returned false.

Offline

Board footer

Powered by FluxBB