Apache doesn't see the external driver on LAN

I am running PHP/MySQL/Apache on PC1 connected to PC2. Can’t access the driver on PC2 from PHP. The MS explorer can see the connection on both computers. The firewall is switched off on PC2. Apache log is always pointing to C: on PC1 even if I am changing the DocumentRoor pointing in a VirtualHost tag to PC2. The Apache log reports that the file doesn’t exist on C:.

Well, not really sure what you are asking. PHP is a SERVER-SIDE language only. You can use PHP to access folders on the server and sometimes you can use PHP to access shared drives, but, it will not use drivers on other systems. I am guessing you mean something else than “DRIVER”. You can not access data C drives on other computers. You CAN access their “shared” drives. Like the PUBLIC drives on other machines if they have be shared to allow access correctly. Perhaps you should tell us what you are trying to do.

I am using LAN setting and trying to access external content which is not under the DocumentRoot tree.

  1. Created folder under the DocumentRoot tree: ./CAH/PRIME
  2. Made a network connection to the external folder.: \Slave\PRIME
  3. Insured that \Slave\PRIME has unrestricted access.
  4. Applied the following changes to the httpd.conf on Apache:
    Alias “/CAH/PRIME/” “//Slave/PRIME/”
  5. Restarted Apache
  6. Openned sub-folder under \Slave\PRIME\000
  7. Run PHP to access the folder \Slave\PRIME\000
    if (is_dir("./CAH/PRIME/000")) {
    echo “FOUND
    ”;
    }
    else {
    echo “NOT FOUND
    ”;
    }
  8. Result - NOT FOUND

Well, I have no idea what all that apache alias setup is for. In PHP, you just access shared drives using the standard commands. I do it all the time here on my local lan and never have issues.

Let’s just recap what you said and what I know…

You mentioned MS-Explorer and two pc’s. This means you are using Windows, correct?
If you are using Windows, you just SHARE any folder on the remote or slave computer.
You do this in Windows Explorer by right-clicking on it and select PROPERTIES.
Then, under that dialog, you share the folder and give it a name. Then, once shared, you must
set the permissions to allow the other computer to access the folder. I usually just use ALL and
give everyone on the network permission to access it. You can set just the calling computer instead,
but, it is safe on a local LAN if you have a solid firewall so the world can not get into your LAN.
Then, in any PHP program, you can look at the shared folder using the standard //computername/folder.
As an example, here is one of my PHP scripts that reads the directory of a shared folder.
( I changed the names of the computer, but, you should get the idea. )

<?PHP
$filenameArray = [];
$directory = '//remotecomputername/Pictures';
$handle = opendir($directory);

while($file = readdir($handle)){
    if($file !== '.' && $file !== '..'){
        array_push($filenameArray, "file:////remotescomputername/Pictures/$file");
    }
}
?>

As you see, the directory is normal Windows sharing format. The way I accessed the file name list was slightly different because the array I needed had to have all the filenames and they are tricky to acquire sometimes due to slashes. A blog() function might work for this, too.

Anyway, my local LAN runs Apache on a Windows system and runs multiple PHP scripts daily several that access various remote folders. They all work well for me. Are you running a real Apache only server and mentioned the MS-Explorer by mistake? Not sure, but, hope these comments help.

Thank you. The problem is still persisting but you give me a good direction to investigate that.

Well try a test file like the example I showed you. And, post it here. And, check your permissions on the folder. If the permissions are not set, most likely that will cause the issue. But, you can set the error reporting in the test file and see what the actual live errors are and that will tell us the problem. Do you know how to do that? Set all of them to show all errors. And, you should also check your server log. If is is a WAMP, it would be in that folder under a sub-folder named LOGS.

Are you using NAS (Network Access Storage) to store the content? I just want to get a glimpse of your LAN configuration.

Well, what a process to sort this out!!!

My system is a shared drive on a server. But, I have a huge system in my main computer room that has a shared folder. I have a very complicated LAN here. One NAS as you mentioned, several computers linked by wireless to one router. A “bridged” router in another room connected to the first. Wired units to the second router. Seven computers currently active on the LAN. A set up like you see in movies or tv shows. Not bragging, just explaining.

Now, I tested the connections first in Windows. I did have a lot of trouble getting to some of the systems connected to the second router. It seems that you need to use a username in some cases. ALL computers have no login’s that require usernames although Windows apparently, by default, sets them. I figured out that the connection will work using the username of the computer name. ( Meaning the name of the shared system. ) So, one computer is named “ROG” and I accessed it as ROG\www to get to the shared WAMP www folder. It does not work on it’s own. But asked for a username and password. So, I entered just ROG as the username and no password and I got to the folder. Odd set up, Mr. Windows !

This is annoying. Oddly enough, you just need to do it once. I looked into that. It seems that Windows keeps the network share usage connections. It keeps them as a connection name, usernames and passwords. You can see them by going to a command prompt and enter " net use " and it will show them. This shows saved shares. You can delete one if you change the password. But, does not matter for this discussion.

So, to fix this, I looked into it deeper for you. You need to enter the username, even if it is a default into the PHP connection somehow. I have tried hundreds of ways from all kinds of sources on the internet. Some even were mapping the folder to a letter. After hundreds, none worked.

After much reading, I found there is a bug in PHP that has trouble with SMBserver. It seems that MSDN ( Microsoft) knows of this problem and has an odd fix for it. You can alter a registry setting from 1 to 0 on the host machine. The “host” machine means PC2 as it is hosting the data out to PC1. Here is the story I located regarding it all and how it went. Very sorry for all of this! You can try the registry change or set up PC2 with a server system to get to the files…

Hi there !

Had the same problem... but solved it :)
in fact it IS permission related...

my conf:
WEBsrvr nt5 + Apache/1.3.24 (Win32) PHP/4.3.4RC3-dev
SMBsrvr nt5

the deal:
WEBsrvr access a share on SMBsrvr with opendir()

the problem:
$d = opendir('\\SMBsrvr\whatever');
Warning: opendir(\\SMBsrvr\whatever): failed to open dir: Invalid argument in C:\Inetpub\www\script.php on line x
--`this is not a usefull warning !`

$fp = fopen('\\SMBsrvr\whatever\file.ext','rb');
Warning: fopen(\\SMBsrvr\whatever\file.ext): failed to open stream: Permission denied in C:\Inetpub\www\script.php on line y
--`hmm, hmm, more interresting...`

At this point had to investigate a bit more:
Apparently apache + php know that \\SMBsrvr\whatever exists and that it is a valid directory ressource...

Did some packet log on SMBsrvr:
WEBsrvr sends a SMB `Tree Connect AndX Request` using nullSession
SMBsrvr replies by an ACCESS_DENIED

gotcha !

SMBsrvr doesn't allow nullSession...
but why WEBsrvr tries to connect using nullSession ?
because Apache is running as LocalSystem

From MSDN:
`Windows NT - LocalSystem:
The service has limited access to network resources, such as shares and pipes, because it has no credentials and must connect using a null session. The following registry key contains the NullSessionPipes and NullSessionShares values, which are used to specify the pipes and shares to which null sessions may connect:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Alternatively, you could add the REG_DWORD value RestrictNullSessAccess to the key and set it to 0 to allow all null sessions to access all pipes and shares created on that machine.`

Enough blabla:
Either you allow the host of share to accept nullSessions
or you create an account with enough privileges on the apache host and when in mmc/Services/Apache/Connexion "Open a session as" - use the newly created account...

Thank you so much, and bless you.

Sponsor our Newsletter | Privacy Policy | Terms of Service