• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.

Create subdomain from PHP

B

BorisÃ…

Guest
Hi,

I'm trying create subdomain from PHP script using CLI. I run via shell_exec command

Code:
/usr/local/psa/subdomain --create <subdomain_name> -domain <domain_name> -www-root </www/root>

I'm not able to create subdomain because following error ocure:

Code:
Unable to connect to database: get_admin_password() failed: file_get_contents() failed:

What am I doing wrong? Is it possible to do this by CLI or I have to use RPC instead?

Thank you for your suggestions.
 
I checked it using
Code:
whoami
and answer was 'www-data'. Then I start session in PHP script and user change to domain system user.
 
hey,

I haven't have an answer for you. but maybe you can use the plesk api instead of the cli commands !?

regards, martin
 
Create subdomain from PHP - SOLVED

I find solution for using CLI from PHP on Ubuntu 10.04.

Using CLI can root only (or psaadm but I don't know password). Then Apache user has to be granted as root for invoking this commands. For security reasons is better run PHP as FastCGI or CGI instead of as Apache module, because Apache user is for FastCGI or CGI domain user and for PHP running as Apache modul it is www-data. It is not good idea grant www-data user any root access because all PHP aplications for any domain where PHP is running as Apache modul run under this user.

When application is running under user which we know (it could be www-data, but I don't recommand), then we grant this user to run for examle /usr/local/psa/subdomain application as root by changing sudoers file.

To find out under which user is PHP application running, just create simple PHP page with following code:
Code:
<?php
  echo "I'm running under ".shell_exec("whoami")." user";
?>

To modify /etc/sudoers file type as root
Code:
sudo visudo

and add this line at end of file
Code:
php_user ALL=NOPASSWD: /usr/local/psa/subdomain

where php_user is known user under which PHP application is running.

Thats all and works for me. Something like this should be part of CLI documentation.

I was trying to change to RPC API, but it is insufficient for my needs.
 
Back
Top