ratchetphp / Ratchet

Asynchronous WebSocket server
http://socketo.me
MIT License
6.28k stars 744 forks source link

How to run PHP Ratchet WebSocket Application on AWS EC2 Instance with Apache #908

Open tech134 opened 3 years ago

tech134 commented 3 years ago

I have working on one my project using PHP and Mysql, In which I want to implement Chat feature. So for add real-time chat feature, I have used PHP Ratchet WebSocket library.

So for implement Ratchet library in my project, I have found this live chat tutorial using Ratchet WebSocket in which I have got set by step by process for build chat application. And I have successfully make Chat feature in my project in localhost.

But when I have upload my code on AWS EC2 Instance micro server then that code is not work. I have receive WebSocket connection to 'ws://xx.xx.xx.xx:8443/' failed: error.

Currently I have run my code on IP, and I have use both Public and Private IP with different port number. But I have not got any success. Below I have share some my required code.

securiy-groups

bin/server.php

<?php

//server.php

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\Chat;

    require dirname(__DIR__) . '/vendor/autoload.php';

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                new Chat()
            )
        ),
        8443
    );

    $server->run();

?>

And chatroom.php in which I have create websocket object in javascript code, which you can find below.

<script type="text/javascript">

    $(document).ready(function(){

        var conn = new WebSocket('ws://xx.xx.xx.xx:8443');
        conn.onopen = function(e) {
            console.log("Connection established!");
        };
});
</script>

Let me know if you need more information.

Do you have any ideas How can I run my PHP Ratchet WebSocket application on Amazon EC2 Instance?
leksanboy commented 2 years ago

hi @tech134 you need to solve the problem with helathcheck and HTTP protocol with Proxy Pass