• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • 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.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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