Search code examples
webserverapplication-server

Application Server and Web Server on Two Different Machines


Today I'm hosting a Laravel v4 web application on a MacMini. Why a Mac? Because I created the application logic in Objective-C (leveraging my experience with iOS dev). Whether or not this was the right choice isn't the point of the question.

What I'm interested in knowing is how can I separate my web and application server. For instance, if I put my web server on Linode (or whatever) how do I go about communicating back and forth between the web server and the application server? Is there some sort of resource I can look to to understand how to do this?


Solution

  • Assumptions

    Here's some assumptions I'm making:

    1. I'm guessing Laravel and the Objetive-C Application are part of the same "system" and so I'm just gonna treat this as if you need a web server to send requests to a PHP application.
    2. The Linode server will be a web server which sends request to the PHP application (Laravel)

    Hosting PHP Applications

    There are three moving parts:

    1. The web server (Apache, Nginx)
    2. The application gateway (PHP-FPM)
    3. The application

    The gateway and the code must live on the same computer/server. The web server can live on a separate computer/server.

    This means you'll need your Macintosh to run PHP-FPM, which can then listen for remote connects and send them to the PHP application.

    Macintosh

    Install php-fpm on your mac. Make sure it can listen for remote network connections. This is usually done in the www.conf file in the listen directory, you can listen for connections on the remote network interface (whatever IP address the computer is assigned).

    Linode

    Install Nginx or Apache and have it proxy FastCGI requests off to your macintosh server at the macintosh's IP address (the one you set up to listen to addresses in the step above).

    Firewalls

    You may need to ensure the firewalls at both ends allow incoming/outgoing connects on the networks being used to communicate to eachother.