How to run PHP Ratchet WebSocket Application on AWS EC2 Instance with Apache
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](https://github.com/ratchetphp/Ratchet).

So for implement Ratchet library in my project, I have found this [live chat tutorial using Ratchet WebSocket](https://www.webslesson.info/2021/01/build-real-time-chat-application-in-php-mysql-using-websocket.html) 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](https://user-images.githubusercontent.com/68006491/134647821-af017c31-fdcd-4e4d-b7a2-faa57e167035.png)**

**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?
```