Solved

Apache access to files on another server

Posted on 2013-01-31
11
279 Views
Last Modified: 2013-02-04
I'm running a php application that has to be able to access files on another server.  ie: Webserver is 192.168.1.4 and needs to access files on a folder in 192.168.1.14.

Tried to create an alias through Apache, but was not able to return a valid file handle using readdir() or scandir().

Thank you in advance.

AielloJ
0
Comment
Question by:AielloJ
  • 5
  • 5
11 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38841692
You probably are not able to get the correct permissions.  What OS?  You might be able to create a mapped drive on Windows that will give you local access.  If the remote files are on a web server, then PHP can access them.  If they are PHP files though, you can't get the code in them, only the results.
0
 
LVL 13

Author Comment

by:AielloJ
ID: 38841774
Hi Dave,

I'm running Apache under Windows 7.  I created a mapped drive and a symbolic link using MKLINK.  Both were successful, but neither allowed access to the other drive.  The files I'm trying to access are text files I'm processing through the PHP script.  The C:\EDI folder in the example below is a a symbolic link to the 192.168.1.14 machine.

Alias /EDI/ "C:/EDI/"

<Directory "C:/EDI/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

I'm also not certain what the directory name I should be using inmy PHP code.  I've seen
  //servername/sitename/alias
  /sitename/alias
and a variety of other formats as the directory/folder syntax.

My preference would be to just be able to create an Apache alias and not have to do anything special in the Win7 or Win7/DOC area.

Best regards,

AielloJ
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38842021
An Apache alias won't get you around the permissions problems.  Apache itself is set up with very limited access and that is only to the directories specified in 'httpd.conf'.  But Windows (and Linux too) permissions also have to be set to allow access.  There is no way to do it only with Apache.  Windows 7 is pickier about permissions anyway.
0
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 13

Author Comment

by:AielloJ
ID: 38843250
I'm a domain administrator, so access shouldn't be an issue, unless Apache runs at a different priority.  This is for a small intranet, and I'm the IT Administrator.  Can I add the directories into the 'httpd.conf' file?
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 250 total points
ID: 38844769
Yes, 'httpd.conf' is the place to add them.  But every file and directory has specific permissions.  Adding them to Apache does not change or override that.  Files on another machine have to 'shared' to access them remotely at all.  Windows normally blocks external access to 'My Documents' from other users because it belongs to a specific user.
0
 
LVL 13

Author Comment

by:AielloJ
ID: 38845284
Dave,

Since all the machines are on the domain, is there a domain username or group that Apache runs under?  I could give the appropriate permissions to the group or account.

AielloJ
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38845458
I have never had a Windows domain setup so I don't know.  Can you directly access the directory you're talking about without a login from the computer where Apache is running?
0
 
LVL 13

Author Comment

by:AielloJ
ID: 38845474
Yes.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38845640
I can't get it to work on my Windows XP network.  I have 'alias' working fine for local directories.  But I can't get it to work with a direct remote access or a mapped drive setup.  I don't know what else to tell you.  You can click on "Request Attention" above and see if someone else can help you.
0
 
LVL 16

Accepted Solution

by:
grahamnonweiler earned 250 total points
ID: 38846820
On Windows (regardless of version), both Apache and therefore PHP, run at the "system" level. When you login to windows and create a mapped drive then you are creating that at whatever "user" you have logged in as - which neither Apache nor PHP have access to.

PHP can however access a different drive within the same network provided that drive is open to "everyone" - meaning no security/permissions at all. In PHP you would acess the drive using SMB, for instance:

\\192.168.1.14\edi\myfile.txt

However, as the backslash would be treated as an escape sequence by PHP you need to "double" up, for example:

\\\\192.168.1.14\\edi\\myfile.txt

Obviously, as there is no ability to "secure" the shared drive, this is not anideal situation, and therefore you should ensure you at least secure access to the shared resource by IP addresses.

While an "alias" within the HTTP.CONF (using the same method as stated above) on Apache will "sometimes" work in Windows, it is by no means reliable, and thus the direct access through PHP is the more reliable option.

Again I would stress, that this does introduce new security aspects that need to be considered carefully before attempting to use this in a production environment.
0
 
LVL 13

Author Closing Comment

by:AielloJ
ID: 38850583
Thanks for the help guys.  Found the solution and thought I'd share it.  Apache runs at the access level of the system it's installed on, regardless of what system we want to access files on.  Go into Control Panel -> Services and right click on the Apache service (wampapache on WAMP).  There's a tab that says Login As.  Set the login account as one that has access to the system you're trying to access the files on.

Points in appreciation for your efforts.

Best regards,

AielloJ
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ProxyPass - Problem 5 186
Xampp Not Stopping 9 42
browser caching 4 77
Re-negotiation handshake failed: Not accepted by client!? 8 771
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question