1

Sorry if this a repeat of a question that has been asked before but I have not been able to find my exact situation. We are trying to migrate our website server from a Windows 10 VM (yes I know) to a Windows Server 2019 VM. We have some PHP on our site that writes files to some of our other servers on the same domain and have been able to do so without issue using file_put_contents like so:

file_put_contents("\\\\server\\folder\\folder\\folder\\".$filename, $file);

Now all of a sudden, to run the same code on our new server I get a Warning on this line, "Failed to open stream: Permission denied". I have permission to access this folder, I can browse to \server\folder\folder\folder and create a file there. I even tried mapping this server to a letter drive on my new web server, and still same error. I can put the file on the local C drive just fine but that's it.

Running fileperms on the folder path gives Warning: fileperms(): stat failed. Running is_writable on the folder path returns false, I just can't see how. Running it on the old Windows 10 web "server" returns true. I've read some things about needing to enable certain settings on the server you're trying to access, but I just can't think of what would allow one VM to access it and not another. Both VM's are logged in with the same user with admin rights. I can bring up the same folder in file explorer and write to it, just not via PHP. What obvious thing am I missing?

Thanks!

Mike
  • 31
  • 5
  • It's a network share, and the user, under which your webserver/php runs, has no access (this is usually a good thing...) – Honk der Hase Oct 25 '22 at 19:51
  • So I just have to add newwebservername\user to the list of authorized users on the Security tab of the network share? But then how come our old website can access it just fine - is it because it's Windows 10? – Mike Oct 25 '22 at 20:11
  • Are you running PHP through a web server or the CLI? Seems the latter, just want to be sure – Chris Haas Oct 26 '22 at 03:18
  • @ChrisHaas we are using IIS. – Mike Oct 26 '22 at 10:10

1 Answers1

1

After weeks of banging our heads against the wall we finally figured this out. On our old web server, when right-clicking the website from the Sites file tree in IIS, under Manage Website -> Advanced Settings, the Physical Path Credentials field was set to the credentials needed to access these folders. On the new server it was blank. I'm not sure how this got missed but in any case, after entering the correct credentials here everything immediately worked.

Mike
  • 31
  • 5