Opendkim-genkey cmd is not working wile sending the command via PHP through browser

Viewed 151

I am using Centos 8 as a server.

I am running this command on my server as a root user.

opendkim-genkey --domain=example.com --selector=example --subdomains

This command works properly.

The problem comes while I run/execute this command.

shell_exec("opendkim-genkey --domain=example.com --selector=example --subdomains");

Via browser, the result of this command is an error opendkim-genkey: command not found.

I know that this issue is related to some permission. But I don't know how and where to give the permission to run this command via PHP.

Does anyone have the proper solution for it?

2 Answers

Your command shell_exec is being run through PHP, which is not running as a root.

If you wish to run PHP as a root, you should add a PHP user to a sudoers file. Be careful since this will introduce a security vulnerability.

I find the solution:

First, you have to find the actual path of the command in your server

which opendkim-genkey

O/P :

/usr/sbin/opendkim-genkey

Now, You know the actual path of the command. Now create links to files or directories of opendkim-genkey in /usr/bin.

ln -fs /usr/sbin/opendkim-genkey /usr/bin/opendkim-genkey

now you are able to run/execute the command via apache user.

Related