简体   繁体   中英

IIS 8 - Access is denied when try to run command with exec in PHP

when try to run this command from PHP it show this error

Access is denied.

$ruta = "C:\OpenSSL-Win31\bin\openssl pkcs8 -inform DER -in Usuarios_XML/$rfc/$archivo.key -out Usuarios_XML/$rfc/$archivo.key.pem -passin pass:".$key;

$ejecuta = exec($ruta . ' 2>&1', $output);
print_r($output);

But when I run it directly from my server in the openssl console it works.

I guess that I need a kind of permission but I have no idea where to change it, some idea how can achieve this?

The server is running Windows Server 2012 , I hope you can help me, thanks.

It is a pretty complicated problem. As I understand so far, the issue is that your command is trying to access the file system and IIS is not allowed to access the file system by default. It work on command prompt becouse command propt has access to file system but when the same command run throught the PHP and WebServer(IIS) it gets denied.

You can try a few things,

  1. Go through the security properties of all the files used in the command (including C:\\OpenSSL-Win31\\bin\\openssl.exe ) and check if the NETWORK USER has access, else add it and give full access.
    To check the secuirty of the file: right click on the file > properties > security tab

  2. If that doesn't help, give IIS an Administrator access. Please check IIS: Application Pool Identities to see how to do it. Since you are giving Administrator access to IIS it has it's own risk of an outside attack. Please research more about it so you should know what your are doing.

In my case the later solution worked, let us know if any of this help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM