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

Note: Unlike Node.js, the PHP server does NOT support WebSocket. Set UseWebSocket = false in FriendManagerSettings.

Configuration

Edit config.php:

SettingOptionsDescription
database.type"sqlite" or "mysql"Database driver
database.pathPath stringSQLite database path
database.hostHost stringMySQL host
database.nameName stringMySQL database name
cors.enabledtrue/falseEnable CORS headers

REST API Endpoints

All endpoints require the X-User-Id header to identify the current user.

Authentication

POST /api/auth

Friends

GET /api/friends
POST /api/friends/:friendId
DELETE /api/friends/:friendId

Friend Requests

GET /api/friend-requests
POST /api/friend-requests
PUT /api/friend-requests/:requestId
DELETE /api/friend-requests/:requestId

Blocked Users

GET /api/blocked-users
POST /api/blocked-users
DELETE /api/blocked-users/:userId

Rooms & Invitations

GET /api/rooms
GET /api/rooms/:userId
POST /api/rooms
PUT /api/rooms/:roomId
GET /api/invitations
POST /api/invitations
DELETE /api/invitations/:invitationId

User 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:

  1. Upload the .Server/php/ folder contents to your web root
  2. Configure config.php with your database credentials
  3. Set UseWebSocket = false in 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]