Virtualmin domain name registration in PHP
In a PHP web page I need to run this following command to create a new domain:
virtualmin create-domain --domain DOMAIN --pas开发者_如何学编程s PASS --plan 'Standard Package' --limits-from-plan --features-from-plan
This is usually executed in a shell but I don’t know how to do it from a web page and also I need to take the DOMAIN
and PASS
strings from a web form. Can anyone help with the PHP code? My skills are basic and I have already tried a few things that just don’t work.
How about shell_exec()
?:
shell_exec("virtualmin create-domain --domain DOMAIN (...)");
or the backtick operator
:
`virtualmin create-domain --domain DOMAIN (...)`
You can access parameters submitted via a HTML form with the $_POST
array. But make sure to validate the user input. I suggest to read a tutorial about this.
You have to run this command as root or using sudo. I'm currently looking into the same thing, but there doesn't seem to be a 100% safe and secure way of running it using root/sudo.
However, if you would like, you can call a script in php as sudo and change password request off. You can pass the variables into it
exec("sudo /your/script.sh $Domain $Pass");
Your bash script would look like this:
#!/bin/bash
domain=$1
pass=$2
virtualmin create-domain --domain $domain --pass $pass --plan 'Standard Package' --limits-from-plan --features-from-plan
You should allow executing your script without password prompt. Run sudo visudo
in console and add the following string to the end:
nobody ALL = NOPASSWD: /your/script
You must set up file mode properly to ensure that no one can modify this script and put dangerous contents into it (in root console):
chown root:root /your/script
chmod 755 /your/script
Info sourced from: How to run from PHP a bash script under root user and Pass PHP variables to a Bash script and then launch it
精彩评论