How to Develop a Facebook App on Your Local Server using SSH

When you develop for facebook you usually run you app on your developer machine and connect a test app in Facebook with the local installation. Once finished, you put the final app onto some dedicated server and connect the real Facebook app to that. So setting up the local development environment usually includes some network setup, for instance as described here: However, I find these router and network setup design troublesome and I also want something that is flexible, especially when I switch from desktop to mobile development.

If you have access to a dedicated, root or v-server on the internet, you can achieve a very easy network setup using ssh port forwarding. You basically use the internet box as the target url for your Facebook app and forward some port from that internet port to your local test web server over the ssh tunnel. By doing so, you are totally mobile, you can open the port on the internet box from anywhere you want.

So, let’s say you configured your facebook app “myapp” like this:

You see in this example that facebook will tell your browser to load the iframe content from the URL that is on port 9090. So you need to forward this port 9090 to your developer machine.

In order to forward ports on public network interfaces you will mostly need to enable the “GatewayPorts” option in the ssh server of you internet box. This is a setting in the /etc/ssh/sshd_config (Debian):

just add the following line to /etc/ssh/sshd_config:

GatewayPorts yes


/etc/init.d/ssh restart

Then you can start forwarding the port to your local machine. Just issue an

ssh -R '*:9090:localhost:9000'

It will look like you just only logged into the remote machine but in addition to that, a tunnel has been opened from port 9090 remote to port 9000 local. So if you have something listening on your local machine on port 9000, i.e., your development web server, than you can point the browser to your facebook app:

and it will display the content as retrieved via the tunnel (9090) from your local machine (9000). As soon as you close the ssh connection, the tunnel will also be gone and you can then initiate the same ssh connection from you laptop if you are going outside.

The biggest benefit of this solution is that you will never have to change IP addresses anywhere, not in the facebook app setting, not at dyndns etc. This is especially useful if your IP address changes frequently like on mobile internet.

Pretty simple, and no need to configure multiple apps for multiple environments. Just move and reconnect via ssh. If you want, you can easily do the next step and put a web server like Apache or nginx on the internet box. From there you can reverse proxy from a certain virtual host (e.g., to your forwarded port on the same machine (9090). In a setup like this, you would not need to enable the “GatewayPorts” option in the ssh server, because then it would be sufficient to listen only on the local interface ( Such a setup would be a little closer to most production setups with load balancers and such.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s