Solved

Apache access to files on another server

Posted on 2013-01-31
11
277 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
 
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

14 Experts available now in Live!

Get 1:1 Help Now