0

Upon recommendation of a member of the stackoverflow forum, I hereby ask the following question in this forum, where it apparently fits better (I'm new to this forum).

What exactly I want:

A specific page of my website should load its content (html structure, representing a chat window) from the web server, but its chat functionality, present as PHP Ratchet script on the server-side (placed on the same web server), should work via a WebSocket connection.

In other words, for this specific page, Web Server and WebSocket connections should work simultaneously, while I have only one Apache (2.4) server, on a shared hosting basis, with no root access. And, as stated, both the chat application programmed in Ratchet and the website's HTML page are present on the web server.

When testing this on my localhost, this worked very nicely. When trying to deploy it on my web server however, I got into trouble, and seemingly need to employ an NGINX reverse proxy in front of my web server, or similar (http://socketo.me/docs/deploy). Is that even possible to deploy given my hosting conditions, or do I need to switch to another hosting type? I started with configuring NGINX, but the problem is that I can't actually modify the port to which my Apache Web Server is listening, given that I have no root access.. I feel that I need to switch my hosting type for this purpose?

One of the aspects of this question may be summed up to: Is it possible to place a reverse proxy in between the client and the browser for websocket purposes, when having a web server on a shared hosting basis, without root access?

DevelJoe
  • 187
  • 3
  • 11

1 Answers1

1

Most shared hosting plans only allow you to accept connections on ports 80 (HTTP) & 443 (HTTPS) and do not give you access to the terminal.

Assuming this is the case, you cannot run a Ratchet WebSocket server since it requires terminal access and would be best hosted on a non-HTTP port.

I recommend you run the web server and WebSocket server on a dedication hosting plan where you'll have access to the terminal and have the ability to use any ports you like.

slightly_toasted
  • 804
  • 5
  • 14
  • Yeah, it really looks like that's the better solution. The problem here is that most hosting companies make no security and maintenance work on dedicated or VPS, which is something I would prefer to remain having as a basic feature. So I'm trying to figure it out how I can display web pages and use websocket connections on the same page with one single web server, of a shared hosting account. Thanks for your comment anyway, actually didn't know about the port limit of shared hosting providers. – DevelJoe May 19 '20 at 17:53
  • `The problem here is that most hosting companies make no security and maintenance work on dedicated or VPS` What do you mean by this? – slightly_toasted May 19 '20 at 18:07
  • Also the port limit is from my experience with GoDaddy, could be different in your case. – slightly_toasted May 19 '20 at 18:08
  • Well my host (which actually is GoDaddy for this current project) just informed me that if I switch to a dedicated hosting contract, they will do no more maintenance and security work concerning my server; then it would be all up to me (guess they just wanna exclude their liability from their client's eventual server mistakes). As I'm beginning with websockets etc. now only, I'd obviously prefer if that would keep being monitored too. I'm starting to actually wonder if it es even generally possible to employ websockets on a website hosted on a shared basis...? – DevelJoe May 19 '20 at 18:10
  • If you are on the GoDaddy shared plan you 100% cannot run the Ratchet PHP WebSocket server since it requires terminal access, which does not come with the shared plan. – slightly_toasted May 19 '20 at 18:13
  • As for the security and maintenance it's kind of BS and just a marketing and sales pitch. They will monitor your server and try to detect malware but as long as you're comfortable learning the basics of setting up your own web server, I wouldn't worry about the 'security and maintenance' that GoDaddy offers. – slightly_toasted May 19 '20 at 18:14
  • Why does Ratchet WebSockets require terminal access to work online? Can't you simply redirect to the file which contains the chat application and activates the port listener coded in ratchet via a reverse proxy when the chat page is acessed? Hahahah and for the security and maintenance stuff alright, thanks for that. – DevelJoe May 19 '20 at 18:20
  • And coming back: Is it actually possible to employ WebSockets on your website, when your web server is hosted on a shared basis?? If not I need to switch to dedicated either way.. – DevelJoe May 19 '20 at 18:27
  • First of all you cant run a reverse proxy on GoDaddy shared hosting. Second, take a look at the Ratched docs. In order to run a WebSockers server you need to execute a command such as `php chat-server.php`. Since you don't have terminal access you can't run that command. – slightly_toasted May 19 '20 at 18:29
  • Ratchet seems to run as a standalone PHP executable, not as a PHP page that can be served. – slightly_toasted May 19 '20 at 18:29
  • You can host both Websockets server and Web server on dedicated hosting. – slightly_toasted May 19 '20 at 18:30
  • I will update this post with all this information – slightly_toasted May 19 '20 at 18:30
  • Well if you simply include the code of that chat-server.php file in the php page to be rendered, it actually works...? What you're saying is that if I want everything to work, a dedicated hosting contract with terminal access is required? – DevelJoe May 19 '20 at 18:31
  • Unfortunately Ratchet does not work like that. It needs to be launched as a standalone PHP script, decoupled from the client side frontend. – slightly_toasted May 19 '20 at 18:34
  • oh really..? why ? – DevelJoe May 19 '20 at 18:35
  • Modern web applications have moved towards the decoupling of client and server code. It's easier to manage, secure, containerize, etc... Look up "decoupling frontend and backend" – slightly_toasted May 19 '20 at 18:40
  • Thanks so much dude for all of your explanations and comments; looks like I really gotta switch to a dedicated hosting. – DevelJoe May 19 '20 at 19:07
  • @DevelJoe No problem. Keep in mind you will have to learn a couple things in order to secure and manage your VPS (SSH, firewall, etc..), but there are thousands of guides online so you should have no problem figuring it out. Good luck. – slightly_toasted May 19 '20 at 19:10
  • Will email you, you might wanna remove your email before it gets scraped by bots. – slightly_toasted May 19 '20 at 19:37