PHP Server
The PHP server provides REST API access for friend management without WebSocket support. It's ideal for shared hosting environments or simpler projects that don't require real-time updates.
Prerequisites
- PHP 7.4+ installed (8.0+ recommended)
- PHP extensions: PDO, pdo_sqlite (or pdo_mysql for MySQL)
- Web server (Apache/Nginx) or PHP built-in server
Quick Start (Local Development)
Step 1: Navigate to Server Folder
Go to .Server/php/ in your Unity project folder
Step 2: Configure Database
Edit config.php to set your database connection (SQLite default or MySQL)
Step 3: Start the Server
For local development, use PHP's built-in server:
php -S localhost:3000
Step 4: Verify Server
Server runs at: http://localhost:3000
UseWebSocket = false in FriendManagerSettings.
Configuration
Edit config.php:
| Setting | Options | Description |
|---|---|---|
database.type | "sqlite" or "mysql" | Database driver |
database.path | Path string | SQLite database path |
database.host | Host string | MySQL host |
database.name | Name string | MySQL database name |
cors.enabled | true/false | Enable CORS headers |
REST API Endpoints
All endpoints require the X-User-Id header to identify the current user.
Authentication
/api/authFriends
/api/friends/api/friends/:friendId/api/friends/:friendIdFriend Requests
/api/friend-requests/api/friend-requests/api/friend-requests/:requestId/api/friend-requests/:requestIdBlocked Users
/api/blocked-users/api/blocked-users/api/blocked-users/:userIdRooms & Invitations
/api/rooms/api/rooms/:userId/api/rooms/api/rooms/:roomId/api/invitations/api/invitations/api/invitations/:invitationIdUser Authentication
The PHP server uses a simple header-based user identification. All requests must include:
X-User-Id: <user_id>
This should be set to the authenticated user's ID from your game.
Production Hosting
Shared Hosting
The PHP server works well with standard shared hosting:
- Upload the
.Server/php/folder contents to your web root - Configure
config.phpwith your database credentials - Set
UseWebSocket = falsein Unity settings
Apache Configuration
Ensure URL rewriting is enabled for clean URLs. Add to .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php?route=$1 [QSA,L]