Skip to content

Installation & Configuration

Johnny Mast edited this page Apr 19, 2020 · 4 revisions

Downloading the project

Installing the project using composer is hands down the easiest way to get started. This method will download the project from GitHub and automatically install its dependencies for you. Presuming you installed composer execute the following commands on the command-line.

$ composer create-project johnnymast/mysql_websocket_chat chat
$ cd chat

In the above example I am using a mac so my prompt will display different then you if you are on windows.

Websocket configuration

This project can be split into two different components. The WebSocket server is the server.php in the root directory. The second part is the frontend part located in public/index.php. For the WebSocket server, there are two configuration options that you can configure in includes/config.php.

Flag Description
WEBSOCKET_SERVER_IP This flag allows you to configure the WebSocket server's IP-address. By default, the value 127.0.0.1 has been set.
WEBSOCKET_SERVER_PORT This will configure what port the WebSocket server will listen on. The default value has been set to 8080. You can change this value if it clashes with other services running on your machine.

Database configuration

This server can run either with or without a database. By default i have disabled the use of a database server (ENABLE_DATABASE) but you can enable it by switching the ENABLE_DATABASE to true in the includes/config.php file.

Flag Description
DATABASE_HOST The database username goes in here. By default this has been set to root.
DATABASE_USERNAME The database username goes in here. By default this has been set to root.
DATABASE_PASSWORD Enter the password to access the database there. By default this has been set to root.
DATABASE_DB Enter the name of the database here. By default this has been set to socket_chat.
ENABLE_DATABASE This flag will turn using the database on or off by setting its value to true or false.

Please note if you enable the database make sure you update the credentials as well (see table above). Also if you enable the database make sure you have imported database.sql into your database.

Fire up the WebSocket server

Before opening the chatroom in a browser you first need to start the WebSocket server. The WebSocket server is the server.php file located in the project root.

$ php ./server.php

Fire up the WebServer

You can use any kind of service like apache or nginx to host public/index.php. If you don't have access to one of those you can also use PHP's built-in development webserver.

$ cd public
$ php -S 127.0.0.1:8000