The Easier Way to Develop Web Applications
Tags: programming, beginners, productivity, cloud
Published: 2022-01-04 16:46:48

## TL;DR
It’s common to work with a virtual machine when developing and deploying web applications. Capturing changes made to a VM makes your deployment repeatable and easier to maintain.  [Pieces](https://pieces.app/) enables you to easily save common snippets of information for future reference, like config files or SQL commands while building your project!



![A turtle in the clouds](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mctjnr8pnae75kwbd2h8.png)

## Intro
In the age of [GitHub pages](https://pages.github.com/) and [Replit](https://replit.com/), it can be easy to overlook the work that goes into deploying, securing, and maintaining an internet-facing server.

Cloud compute platforms are where developers go when they require a [high degree of customizability, scalable resources, and efficient pricing](https://www.atlassian.com/continuous-delivery/principles/cloud-computing) for their web applications. Whether you wish to deploy a personal portfolio site or a SaaS product with 100,000 users, the cloud will help you accomplish that. There are different ways of leveraging cloud resources, [virtual machines (VMs)](https://azure.microsoft.com/en-us/overview/what-is-a-virtual-machine/) being one of the most common methods.

The challenge with VMs is that many pieces of information can get lost when you make changes. Getting into the habit of saving these edits allows you to be more productive; you'll know exactly what you did, and eventually be able to automate your deployments (be it through [shell scripts](https://www.shellscript.sh/), [containers](https://www.docker.com/resources/what-container), or [configuration management tools](https://en.wikipedia.org/wiki/Configuration_management#Operating_system_configuration_management)).

[Pieces](https://pieces.app/) can help track changes to configuration files, secrets, commands and more in your projects. Let’s look at a specific scenario!

## Scenario
You and your friend are launching a podcast on Koalas. In your research, you've quickly realized that a website will be necessary for the podcast to gain traction.

![A koala glancing thoughtfully at a laptop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aaop3wr80k5bpqgziwjy.jpg)

You begin by googling podcast website hosting, but are displeased by the prices you see. "Fear not!", you proclaim to your friend. "I am a seasoned Linux user who knows enough cloud compute to be dangerous. If we spin up a VM, I could get [Wordpress](https://wordpress.org) running today!"

Your friend glances at you thoughtfully. "I have faith that you can do that," they begin. "But remember when you lost our database password? It’s really important you keep track of all the changes you make to the web server."

You pause. You're used to moving fast and breaking things, not writing documentation. You experience vivid mental imagery of the file-folder hell you have for shell command snippets; randomly placed text files with no context.


![Not to be confused with "folder1"](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9x41ceppkca319rva35r.png)

Your friend interrupts to show you something on their laptop. "Here," they say, "I'll send you a link to an app you can use to capture the **commands** you run, **app secrets**, and **config files**. It's called Pieces. All you gotta do is copy and paste things into it."

"Oh!" You respond sarcastically. "Another clipboard app! Just what I need."

"Well, not exactly..."

## Web server configuration

I begin my website by spinning up a virtual machine instance on my favorite cloud compute platform. I opt to perform the installation of Wordpress by hand, because vanilla Ubuntu server is free to use. Plus, I gain sick satisfaction from watching progress bars fill in my terminal.


![Time well spent](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6zffnrx4208eqkna8vt.png)

### SSH
**Saving an SSH key to Pieces**

My Ubuntu virtual machine needs a public key for SSH authentication.

![SSH key import in Microsoft Azure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/530e4k4cke80g52l6irh.png)

I create a new key pair by running the command
`ssh-keygen -t rsa -b 4096`

I name my new keypair koalaCast.
Followed by...

`cat koalaCast.pub`

... outputting the public key to the terminal.

I then copy and paste that into Pieces for future reference. Losing this public key would effectively lock me out of my server, so it’s important I keep it on hand!


![A public key, saved to Pieces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4s0ausqof0x8a2aztq8x.png)

Neat! We can easily reference this later if we need quick access to the koalaCast public key.

For good measure, I also drop the shell snippet I leverage to connect to the virtual machine into Pieces.


![A command to connect to the koalacast VM via SSH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b54xrcn0c8wirzm2lrun.png)

### App secrets
**Saving a MySQL database password to Pieces**
Our MySQL database will act as storage for our Wordpress installation.

Once MySQL is installed, I’ll run the built-in security script. This removes some insecure default settings that ship with MySQL, and allows me to specify the root password.

`# mysql_secure_installation`

I mash a series of random numbers and letters.

`9sBzdRcw4D4Et7Y8US3w65c#`

I then save that to Pieces for easy future access!


![MySQL root password saved to the Pieces app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ebdao9pzywlwa8w8o9qw.png)

### Configuration files
**Saving file changes that aren’t captured in bash history**

When using Apache web server, website configuration details are written in virtual host syntax. It is unique to Apache, and important to retain when setting up a web server. The content of this file determines how your website will handle user traffic.

I’ll create my website directory, and assign proper permissions...

`# mkdir /var/www/koalacast.io`
`# chown -R $USER:$USER /var/www/koalacast.io`

Then, create a blank .conf file to which I’ll write virtual host instructions.

`# vi /etc/apache2/sites-available/koalacast.io.conf`

I devise the following configuration while reading the Apache documentation...

`<VirtualHost *:80>
    ServerName koalacast.io
    ServerAlias www.koalacast.io
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/koalacast.io
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>`

...and save to Pieces. If there are connection issues on port 80, I can quickly reference the rules I wrote for that virtual host.


![My Apache virtual host file saved to Pieces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1v7niq7w2iqwfa1dyiak.png)

I also drop in a related link to the Apache documentation. This allows me to view that webpage from my virtual host snippet!


![The related link for my Apache virtual host snippet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/514n5yr1w15qlym6mi06.png)

### SQL commands
**Ensure you never lose a SQL command again**

The SQL commands I run are not logged to my bash history, but I still want to keep track of what changes I make to my database.

`ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '9sBzdRcw4D4Et7Y8US3w65c#'`

I use this command to change the root password. Most of the time, this command would be captured in ~/.mysql_history. However, if you log into mysql leveraging sudo...

`$ sudo mysql -u root`

... it may not be captured in a .mysql_history file. To be safe, I drop that command into Pieces before I run it!

![The SQL command I used to change the root password in my database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tkapdpejewtgarukpj0s.png)

## The outcome
The koalacast website has been fully set up, and your Pieces app contains all the file changes and secrets you created during the installation process.

You and your friend hop on a call so they can access the web server and its moving parts.

“Hey, can you send me the public key for the SSH user koalacast?”

![Searching for and copying my public key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/diee9iyf8jsclieib42n.gif)

“You’ve got the database password, right?”

![One database password coming right up!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mwgum35bbcie5q1aircp.gif)

“Are there any other pieces you think I’ll need?”

![Welcome to my ASCII zoo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k34m5fxbtp9tna996la5.gif)

---

Thank you for reading! If you enjoyed this article, [check out our app](https://code.pieces.app/install), [follow us on Twitter](https://twitter.com/getpieces), and [give our Medium publication a follow!](https://medium.com/getpieces)