title: PHP Websocket on LAMP Ubuntu
body: <p>So I have been searching on this for quite some time now and tried a lot of things but just couldn't figure out how to make it work. I created a PHP WebSocket server (ratchet) on my local machine using XAMPP and an angular (v5) frontend, worked without any issues. </p>
  
  <p>Then I tried to deploy both on a DigitalOcean instance where a LAMP stack is running because the app is more than just the WebSocket chat and the rest (a RESTful API) is working fine, but when the JavaScript tries to connect to the WS I get</p>
  
  <pre><code> WebSocket connection to 'ws://&lt;ip-address&gt;:8888/chat' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p>So what I did do was to enable the apache2 mods <code>proxy</code> and <code>proxy_wstunnel</code> and created an entry for a vhost</p>
  
  <pre><code>&lt;VirtualHost *:8080&gt;
      DocumentRoot /var/www/html_backend/web
  
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  
      &lt;Directory "/var/www/html_backend/web"&gt;
              AllowOverride All
              Allow from All
      &lt;/Directory&gt;
  
      ProxyRequests Off
      ProxyPass "/chat/" "ws://localhost:8888/"
      # also tried 0.0.0.0 and 127.0.0.1 instead of localhost
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>The PHP server socket is started like this</p>
  
  <pre><code>public function actionStart() {
      $app = new App('localhost', 8888, '0.0.0.0');
      $app-&gt;route('/chat', new Chat());
      $app-&gt;run();
  }
  </code></pre>
  
  <p>And in JS I try connecting to this</p>
  
  <pre><code>this._socket = new WebSocket('ws://&lt;ip-address&gt;:8888/chat');
  </code></pre>
  
  <p>I also tried it on port 8080 where it should be proxied from, but then it returned a 404 error.</p>
  
  <p>On port 80 I have my frontend and on port 8080 my backend, which is working so far. I can start the WebSocket on port 8888 which did not give me any errors I detected but when trying to connect to it I get the upper error message. This is just for testing and I don't have an SSL cert yet but first I wanted to get this to work or do I require one? I tried lots of URL combinations found all over the web but none was working so far. </p>
  
  <p>Just while writing I noticed that the socket is started from <code>/var/www/html_backend</code> and not <code>/var/www/html_backend/web</code> may the <code>DocumentRoot</code> cause issues with proxying?</p>
  
  <p>I hope someone can point me in the right direction because all "working" solutions I found were not so helpful thus far.</p>
  
  <p>Best Regards</p>