0

I am completely new to backend web development and have made a project using php, but I now want to use websockets to make everything more efficient. To do so, I am going to use Ratchet. I am running Apache 2.4.33. When I attempt to run my test file, I get a 400 error. I do not yet have a server nor a domain and was hoping to run the test files on my local machine. Here is my what user.conf file looks like:

<VirtualHost *:80>
    ServerName localhost

    ProxyPreserveHost On
    ProxyPass / localhost:8080/
    ProxyPassReverse / http:localhost:8080/
    ProxyRequests Off
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://localhost:8080%{REQUEST_URI} [P]
</VirtualHost>

As I mentioned, whenever I try to run my server.php code, the page comes up as 'HTTP ERROR 400'. There might be issues with my code, but I am fairly certain is has to do with how I set up my conf file.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37
  • _"There might be issues with my code"_ - Then you should really show us that. When debugging, it's important that you don't assume where the issue is. Please show us _all_ the relevant code and we might be able to see what's going on. – M. Eriksson Feb 08 '19 at 06:55
  • @MagnusEriksson The code i'm working with is straight from a tutorial from Ratchet. I don't believe there is any issue with it. Here is the link to the tutorial: http://socketo.me/docs/hello-world. I copied it line for line. The only part that is not offered in the tutorial is the setup for the conf file. – TEEBQNE Feb 08 '19 at 16:43

1 Answers1

0

There were errors in my config file. I ran apachectl -S to find what they were. Here is the working config file for anyone else struggling with this like I was:

<Directory "/Users/User/Sites/ProjectFolder">
   AddLanguage en .en
   AllowOverride All
   Options Indexes MultiViews FollowSymLinks
   Require all granted
</Directory>

ProxyRequests Off
RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule /(.*) ws://127.0.0.1:8080/$1 [P,L]
<VirtualHost localhost:8080>
        ProxyPass / ws://localhost:8080/
        ProxyPassReverse / ws://localhost:8080/
</VirtualHost>

If you are using Ratchet make sure that your composer.json is set up correctly with a valid version. Then upgrade it by running php composer upgrade. Finally, make sure to reset the apache server with sudo apachectl restart.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37