A basic instant messaging chat system that utilizes WebSockets in both PHP (server) and JavaScript (client).
Spiteful-Chat uses a MySQL Server set-up relational database to store user profiles, chats, media designations, and messages.
The real media data is saved to /private/spiteful-chat/chats/media/
The steps to host your own version of this repository are as follows:
- Download the zipped source code and unpack within your virtual host environment
- Import database.sql into a new MySQL database and install dependencies using composer
$ composer install
and npm$ npm install
- Create a /private/spiteful-chat/ directory at the same level as your DOCUMENT_ROOT directory
- Create /private/spiteful-chat/database.php:
<?php $GLOBALS["connection"] = new mysqli($host, $username, $password, $database);
Note: You may need to change the required resource in websocket/spiteful-chat.php to match your full path as $_SERVER["DOCUMENT_ROOT"] cannot be used there
- Create /private/spiteful-chat/private-variables.php
<?php
// Google - Used for Google services
$googleClientId = "your-client-id.apps.googleusercontent.com";
$googleLoginUri = "https://your-domain/spiteful-chat/cwg.php";
// Vapid - Used for notifications
/* Generate using
require "vendor/autoload.php";
use Minishlink\WebPush\VAPID;
var_dump(VAPID::createVapidKeys()); */
$vapidPublic = "vapid-generated-public-key-should-be-longer-than-private-key";
$vapidPrivate = "vapid-generated-private-key";
// Session - Used for JWT signature validation
$sessionKey = ""; // Generate using bin2hex(random_bytes(32))
- Create /private/spiteful-chat/chats/media/ directory
- Ensure PHP / Apache / Nginx (typically www-data) has appropriate read/write permissions to the new directories (often overlooked)
- If you are using Apache enable both the proxy and proxy-wstunnel modules
- Add the following to your SSL virtual host (Apache) or server block (Nginx) (usually port 443):
For an Apache setup
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/_ws_/
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/_ws_/(.*) ws://127.0.0.1:12345/$1 [P,L]
ProxyPass /_ws_/ ws://127.0.0.1:12345
ProxyPassReverse /_ws_/ ws://127.0.0.1:12345
For a Nginx setup
location ~ /_ws_/* {
rewrite ^/_ws_/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:12345;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Get more information about this configuration here for Apache or here for Nginx
- Run
$ php websocket/spiteful-chat.php
to start the websocket server
We welcome contributions to enhance the functionality and stability this project. Whether you're a developer, designer, or just an enthusiast, you can help make this project better.
Feel free to submit issues with questions, bug reports, feature requests, or the like.
If you want to contribute code here are the steps to get started:
- Fork this project
- Clone your fork of this project
- Depending upon your situation follow the hosting steps
- Create a new branch with an appropriate name
- Make your changes or additions
- Test and debug your changes
- Make commits with detailed names and/or descriptions
- Push your commits to your fork
- Open a pull request
- Be ready to make any necessary changes required by the reviewers
Whitespace Rules
This project enforces whitespace rules using prettier.
Run the following before each commit:
npx prettier . --write