Of course there is a way, preferably it is to acquire both machines under the same provider, which are as close as possible to each other and you must configure the connection to the database allowing connections to it (machine 1) from the outside, you must configure a mysql user and a password for that and allow configuration only from the IP of machine 2, machine 1 would be the main host (Host 1) with the Server and the Database.
Machine 2 (host 2) would have the website configured to be able to connect to machine 1. That's all.
Together with cloudflare on machine 2 you can limit connections only to the PHP server port 80 only for cloudflare IPs, as well as on machine 1 block all connections except for the connection game ports and the mysql database port.