Welcome to Week 3 of development on my Heist Multiplayer Game. This week has been all about setting up the backend server and getting Unity connected to a MySQL database using PHP scripts and MAMP for local testing.
Create a working backend server environment locally with MAMP
Write PHP scripts to handle database interactions
Use Unity’s UnityWebRequest to connect to PHP endpoints
Store and retrieve user data (login, registration, etc.)
---
1. MAMP Setup:
I installed and configured MAMP to run an Apache server and MySQL database locally. This gave me a local environment where I could test PHP scripts and database queries before moving everything online.

2. Database Creation:
I created a MySQL database with table for players, which includes:
id, username, hash, salt, score

3. PHP Scripts:
I used Sublime Text to write basic PHP scripts for:
Testing : I made an echo at the start which indicated that it has connected to mysql database

User Registration: Checking if the user exists, then inserting new entries

Login Authentication: Verifying credentials and sending back success/failure

4. Unity Integration using UnityWebRequest:
In Unity, I used UnityWebRequest.Post() and UnityWebRequest.Get() to send data to my PHP scripts. I also added coroutines to handle async requests and manage responses properly.

CORS Issues: At first, Unity couldn't communicate with MAMP until I configured it properly to allow cross-origin requests.
Error Handling: Debugging PHP from Unity wasn’t straightforward—had to rely on logs and echo statements for now.
The Tutorial that I followed to connect Unity with MySQL database was outdated, I had to research around the idea for the backend and the Unity WebRequest
To assign role to each player , there are 4 players required in this game, therefore each player after logging in has to select a role, the roles cannot be repeated in the group.
This backend foundation is crucial for the game’s player persistence system, leaderboards, and role assignment for heists. Progress is steady, and I’m hyped for what's next!
If you’ve done something similar or have tips on security/hosting, I’d love to hear from you.
Until next week!
– Viplav Patel
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.