• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

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