This is a demonstration of how the deployment of a LAMP stack on a minimal application can be automated using bash scripts. In this case, we would deploy Wordpress to a web server on Google Cloud Platform.
- Unix Bash Shell
- Google Cloud Platform
- Apache
- PHP
- MySQL
-
I chose to host the demo application on a cloud platform for the following reasons:
-
It is relatively easy to set up a brand new virtual server instance on the cloud compared to dealing with a physical server.
It will be nice to point out that like many cloud hosting providers, GCP gives new users a trial period when they use some specified resources for free.
-
Cloud service providers have a pay-as-you-go option where you only get to pay for resources as you use them. By leveraging this option, going through this exercise cost me far less than a dollar. I didn't have to worry about, say a monthly subscription as is mostly obtainable in traditional hosting.
-
-
-
Bash scripts, like any other shell script allow us to run a myriad of small (and often very fast) programs in a series. Though other scripting languges like Python, Perl and Ruby can do this, they are not optimized for it.
-
For example, while Python can run the same programs as sjell scripts (bash), you often times will be forced to do bash scripting in the python script to accomplish the same thing, leaving you with both python and bash. Bash allows you to automate command line tasks by using the same language you would if you type the commands out manually.
-
Perl, Python, and Ruby scripts often end up complicated to perform a task that would have been much simpler with shell scripts.
-
Before you can test out the scripts, the following must have been taken care of:
-
You should have an account on Google Cloud Platform. You can visit here to sign up if you don't.
-
You should have the Cloud SDK installed. This will enable you interact with GCP resources in your account from the command line.
For instance, the automation scripts use the
gcloud
commands available in the SDK to create, start and make SSH connections to a web server instance. -
Create a project from your GCP console for the test purpose.
-
Ensure you authentice the CLI by running the
gcloud auth login
command on your terminal, and that your demo project from 3. is set to your current project.Below is a screenshot of what a successful CLI authentication looks like. Take note of the current project which in your case should be the name of your own project.
-
You need to add some parameters as project-wide metadata (similar to environment variables). These variables will be used to configure your Wordpress database and SQL after installation. Follow the same pattern shown in the sample file, but feel free to update the values to what ever you choose.
Once we have the above prerequisites sorted out, then we are good to run our script!
-
Clone the repository and navigate to the project folder in your terminal.
-
Execute the scripts by running
./scripts/provision_instance.sh <instance-name>
.instance-name
should be any name of your choice to identify your web server that will be created.If all things go well, you should have your web server up and running in your project dashboard. Note that
lamp02
was theinstance-name
I chose while executing the script. -
Enter the external IP address of your server in a web browser and you should see your new Wordpress installation ready for set up.
-
You can go ahead to complete the set up and try out the installation.