Over the course of the past 4 years I’ve experimented with a bunch of different local development environments for my freelance client work. I started with Scotch Box, transitioned to Boss Box, and finally back to bare bones LAMP, mostly because I develop on Ubuntu and I find Apache2 to be an easier web server to configure than nginx. The final addition of mkcert (generating locally trusted SSL certificates) rounded up my local development environment requirements.
The only thing missing was an automated way to provision a new site. As I explain the mkcert article, spinning up a new site requires a few steps I have to follow each time.
- create new Apache VirtualHost config files
- create a new database
- create a client directory in my local sites directory
- add a record to my /etc/hosts file
- create the SSL certs
- restart the Apache2 webserver
And then I have to do the reverse when I want to delete a site.
So I decided to put these commands together in two sitesetup and sitedrop bash scripts.
To install these scripts to your local workstation, download the separate files, edit the HOME_USER, SSL_CERTS_DIRECTORY, and SITES_DIRECTORY variables at the top to match your local setup, make them executable, and copy them to your /usr/local/bin/ directory.
wget https://gist.githubusercontent.com/jonathanbossenger/2dc5d5a00e20d63bd84844af89b1bbb4/raw/889ec6da4e1727b63a383256172c65afb9da107e/sitesetup.sh // edit the variables sudo chmod +x sitesetup.sh sudo cp sitesetup.sh /usr/local/bin/sitesetup
wget https://gist.githubusercontent.com/jonathanbossenger/4950e107b0004a8ee82aae8b123cce58/raw/8b1ceb8ca7bf17d04a15f274f1fccdd665e89dd0/sitedrop.sh // edit the variables sudo chmod +x sitedrop.sh sudo cp sitesetup.sh /usr/local/bin/sitedrop
Once installed you can run either
sudo sitesetup sitename
to provision a new site or
sudo sitedrop sitename
to drop an existing site.
Next step will be to turn these into something that you can install quickly with one command, but that’s still a work in progress.
Leave a Reply