Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting up a $5 Staging Server with Forge, Envoyer, and Nginx

Ever wanted to have your very own staging server? Here is how to make that happen for $5 bucks a month (assuming you are already using Forge and Envoyer).

1. Spin up a new server with Forge on Digital Ocean for $5 bucks.

For first time Forge users, I would highly suggest this great blog post from the one and only Matt StaufferUp and running with Forge

If you learn better through video, check out the free Forge series on Laracasts - Server Management With Forge

2. Set up Envoyer to auto-deploy from your staging branch

Again for first time Envoyer users, reference the following blog post — Setup Envoyer for the first time or head over to Laracasts to check out their free series on Envoyer.

Note: Be sure to check the PHP7 option when setting up your new server in Envoyer. If this is a new server created in Forge, it is PHP7 by default.

3. Set up your hosts file to point to your digital ocean IP

Check out how to setup a Local DNS record under the Local DNS section of this link. This is not a required step but adds a few conveniences for you.

  1. This will allow you to access your staging site using a URL like http://staging.mysite.com instead of using the IP address of your server or setting up a DNS record that you likely don't want exposed to the world.
  2. For picky OAuth providers (Twitter), you can provide a callback_url that isn't localhost or 127.0.0.1. Use the address you have set up in your hosts file and you should be good.

4. Configure NGINX for Basic Auth

In the case that someone does stumble upon your staging box, it would be nice to have at least a single layer of security between them and the secret goods you're working on. Use this guide to setup Basic Auth on a Digital Ocean NGINX box. It takes all of five minutes and will help you sleep at night. Use this key generator to generate a random and secure password for your Basic Auth setup.

Note: Basic Auth can be pretty dang susceptible to brute force attacks. Use a lenghty random password and don't expose anything on your staging site that could compromise you or your users.

How to log out of Basic Auth

If your site is http://staging.mysite.com, prefix your site address with log:out@ so it would look like http://log:out@staging.mysite.com. This sends through a request with the username of log and a password of out which will return a 401 and log you out of the site.

Wrapping Up

I've been using this for a few months and have been pretty happy with it. Hope this can help a few of you who are looking to do the same! Good luck.

Notes: A few commenters mentioned that using a $5 server equipped with 512MB of RAM can cause some problems when running composer install or npm install. You can read the following post to learn how to set up a swap file on digital ocean. Thanks to @jbpapp and @simondavies for the tip!

published: true
preview: Ever wanted to have your very own staging server? Here is how to make that happen for $5 bucks a month using Envoyer, Forge, and Digital Ocean.
@mattstauffer

This comment has been minimized.

Show comment
Hide comment
@mattstauffer

mattstauffer Jan 27, 2016

Nice work! This is a really solid writeup.

Nice work! This is a really solid writeup.

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
Owner

JacobBennett commented Jan 27, 2016

Thanks @mattstauffer!

@olimorris

This comment has been minimized.

Show comment
Hide comment
@olimorris

olimorris Jan 28, 2016

This is really great. I read. I actioned within 5 minutes.

This is really great. I read. I actioned within 5 minutes.

@jbpapp

This comment has been minimized.

Show comment
Hide comment
@jbpapp

jbpapp Jan 31, 2016

Great article. One thing to mention, if you have troubles with composer, you should enable swapping, 'cause most probably the $5 server with 512MB RAM won't be able to install the dependencies. At least it happened with me.

Here's a a tutorial:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

jbpapp commented Jan 31, 2016

Great article. One thing to mention, if you have troubles with composer, you should enable swapping, 'cause most probably the $5 server with 512MB RAM won't be able to install the dependencies. At least it happened with me.

Here's a a tutorial:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

@justutiz

This comment has been minimized.

Show comment
Hide comment
@justutiz

justutiz Jan 31, 2016

You don't need Envoyer for that. Forge can autodeploy itslef.

You don't need Envoyer for that. Forge can autodeploy itslef.

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
@JacobBennett

JacobBennett Feb 1, 2016

@olimorris Awesome! So handy to have one. Saved me a few times already.

Owner

JacobBennett commented Feb 1, 2016

@olimorris Awesome! So handy to have one. Saved me a few times already.

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
@JacobBennett

JacobBennett Feb 1, 2016

@jbpapp have heard a few others complain about this as well. Thanks for the link!

Owner

JacobBennett commented Feb 1, 2016

@jbpapp have heard a few others complain about this as well. Thanks for the link!

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
@JacobBennett

JacobBennett Feb 1, 2016

@justutiz true, I happen to use both so this tutorial makes use of both services. Thanks!

Owner

JacobBennett commented Feb 1, 2016

@justutiz true, I happen to use both so this tutorial makes use of both services. Thanks!

@sudiptpa

This comment has been minimized.

Show comment
Hide comment
@sudiptpa

sudiptpa Feb 1, 2016

Really great article, helped me alot.

sudiptpa commented Feb 1, 2016

Really great article, helped me alot.

@simondavies

This comment has been minimized.

Show comment
Hide comment
@simondavies

simondavies Jun 24, 2016

I would also iterate what @jbpapp mentioned the $5 set up only has 512ram and when running npm install it will killed it, half way through it, so they will need to set up a swap file during installation, in order then perform this. This helpped me using ubuntu 16.04 - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

I would also iterate what @jbpapp mentioned the $5 set up only has 512ram and when running npm install it will killed it, half way through it, so they will need to set up a swap file during installation, in order then perform this. This helpped me using ubuntu 16.04 - https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
@JacobBennett

JacobBennett Jun 27, 2016

Thanks @simondavies! I have seen other people run into this as well. Might modify the article to reference this link.

Owner

JacobBennett commented Jun 27, 2016

Thanks @simondavies! I have seen other people run into this as well. Might modify the article to reference this link.

@abstractFlo

This comment has been minimized.

Show comment
Hide comment
@abstractFlo

abstractFlo Jul 7, 2016

I think 5$ is not true, 10$ for Forge, 10$ for Envoyer and 5$ for node. There is also a 25$ Staging Server ;)

I think 5$ is not true, 10$ for Forge, 10$ for Envoyer and 5$ for node. There is also a 25$ Staging Server ;)

@JacobBennett

This comment has been minimized.

Show comment
Hide comment
@JacobBennett

JacobBennett Jul 7, 2016

@abstractFlo I did point out in the article that this assumes you are already using Envoyer and Forge ;) You can make it happen without either of these if needed, but that is outside the scope of this particular article. Thanks for reading!

Owner

JacobBennett commented Jul 7, 2016

@abstractFlo I did point out in the article that this assumes you are already using Envoyer and Forge ;) You can make it happen without either of these if needed, but that is outside the scope of this particular article. Thanks for reading!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment