(Originally posted on Medium.com)

I have deployed a bunch of servers on Linode since I started using Linodeback in 2008. I have circled around Apache, NGINX, Ubuntu, Debian, CentOS 6 and 7 and in the last couple of years I have stuck to CentOS 7 combined with Centmin Mod. Centmin Mod simply gives me a good LEMP stack to work off yet still leaving room to adjust and modify to our project/clients specifications.
Often deploying new servers I want my work to be consistent and with as few repetitive tasks as possible, and this is where a Linode StackScript come in handy.

“StackScripts are usually Bash scripts, stored in the Linode Manager, and can be accessed when you use the Rebuild link from the Linode Dashboard. During the first boot job of the newly created disks, the StackScript will run, using any variable you may have added, and perform the scripted commands.” Source

Our stack

Additional tasks after deploying a new server

Beyond installing/configuring packages you also have all the other stuff that needs to get done in order to have a production-ready server.

  • Set hostname and FQDN
  • Add public key to authorized_keys for easy SSH auth
  • Set the timezone
  • Add IPs to firewall (in our case NewRelic, DeployHQ)
  • Update packages
  • Disable Pure-FTPd (Installed with Centmin Mod, but we don’t use it.)
  • Disable SSH password authentication (Don’t worry. You can always login to your server using Linode LISH)
  • Add Latest version of phpMyAdmin and add htaccess password protection
  • Modify NGINX conf to output nginx-status as HTML
  • Allow your IP to see the nginx-status page

All of the above in one StackScript for fast and consistent VPS deployment

See the Centmin Mod Linode StackScript

The StackScript is executed once the server boots. Give it 10 seconds to boot, start the StackScript and add your private key before complaining that SSH key authentication does not work 🙂

Monitoring the StackScript

Our StackScript outputs to ~/stackscript.log and you can easily monitor it using:
tail -f ~/stackscript.log

When the StackScript is done you will see this at the end of stackscript.log
############ WE ARE ALL DONE ############

With the StackScript having completed you are ready to setup your virtualhost(s). With Centmin Mod this is really easy to do using the centmin.sh menu. Just run the command:

You can read more about setting up virtualhosts with Centmin Mod here.

So there you have it

A peak into my Linode LEMP server deployment workflow. Comments and suggestions are more than welcome and I hope you can find some inspiration from this short write-up.

TLDR; Here’s a link to the StackScript: https://www.linode.com/stackscripts/view/67430