• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question How create user mysql direct in database psa and mysql ?

chusmsanchez

New Pleskian
Hello good mornig for everyone.

I am developing a web app and I need to create databases with its corresponding user using php (or another method that you can recommend) every time a web visitor registers.

I understand that I must enter the values in the plesk mysql and psa database.

I have the problem in the plesk psa database when entering the password value in the accounts table. I don't know what kind of encryption plesk uses to save the password.

It would be necessary to be able to connect correctly through php using that inserted user.

I hope I explained myself correctly, sorry for my English.

Thanks.
 
It is not entirely clear why your web application needs to create a user Plesk in psa database? Isn't your app standalone from Plesk?
 
The idea is that for each user registered in the application, a different database is created with its assigned user so if in the future there is a problem in a database, to be able to administer or manage the databases of all clients from the plesk panel inside the subscription.

I have seen that databases and users can be created as follows:


PHP:
// Create database
$sql="CREATE DATABASE $namedb";
echo $sql."\n";
if (mysqli_query($con,$sql) == false){
  echo "Error creating database: " . mysqli_error($con)."\n";
  exit(1);
}

// Create user
$sql='GRANT usage on *.* to ' . $nameuser . '@localhost identified by ' . "'" . "$dbuserpass" . "'";
echo "$sql"."\n";
if (mysqli_query($con,$sql) == false){
  echo "Error creating database user: " . mysqli_error($con)."\n";
  exit(1);
}

// Create user permissions
$sql="GRANT all privileges on $nameuser.* to $dbuserpass@localhost";
echo "$sql"."\n";
if (mysqli_query($con,$sql) == false){
  echo "Error creating database user: " . mysqli_error($con)."\n";
  exit(1);
}




But the question is ... if I do it like this, will the mysql databases and users be reflected within the plesk subscription?

What way would be safer?


Thanks.
 
Maybe it will be better to call Plesk CLI utilities from your PHP code?

 
I have never called a function of that type from php, I will try.

The second option seems interesting, in the manual it also appears to create users (for databases).

Thanks a lot.
 
I am reading the manual and the connection method, but it creates insecurity, since to call the API you need the root user.

If they go into the code somehow and take those values, I'm totally beaten ...

Another option?

With the idea that I had previously, I could play with the privileges of the user in each table (just let create, or insert for example), but I don't know if I'm on the right track.

Thanks
 
Correct.

But the role that I can assign you is to manage databases. If someone takes access, they could delete databases since I can't limit that role to just create.

Thanks
 
Back
Top