PHP script cannot connect to the database

I see. well I do not know how did you install your sql server but on ubuntu it should be simple like this:

sudo apt update
sudo apt install mysql-server

Then run:

sudo mysql_secure_installation

and follow the screen and use common sense - its just few questions like password for sql root user etc… you should be fine.