Programatically Creating Initial WordPress Site

I’d highly recommend WP-CLI for such tasks. It is a tool that allows installation and configuration of WordPress on the command line.

What you are trying could easily be done:

wp core download
wp core config --dbname=<dbname> --dbuser=<dbuser> --dbpass=<dbpass>
wp core install --url=<url> --title=<site-title> --admin_user=<username> --admin_password=<password> --admin_email=<email>

There are a lot of other commands that you can use to customize your installation even further.