Solved

Apache access to files on another server

Posted on 2013-01-31
11
276 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 82

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 82

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
 
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 82

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 82

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 82

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now