Shell Scripting a Complete LAMP Stack Deployment on Ubuntu
Stop Typing Commands By Hand
You want to deploy a web server. So you log into your fresh Ubuntu box and start hammering out package install commands. One by one. Waiting. Staring at the blinking cursor. Let's be real. Doing this manually is a massive waste of your time. You are not a robot. Stop acting like one.
Your First Real LAMP Stack Bash Script
Enter automation. A custom lamp stack bash script takes that entire tedious thirty-minute process and crushes it into three seconds. You write it once. You run it forever. We are going to pack Apache, MySQL, and PHP into a single executable file. No typos. No forgotten dependencies. Just smooth, repeatable magic.
Prepping Your Ubuntu Canvas
Before we write the script, your server needs to be ready. Automated lamp ubuntu deployments rely on a clean slate. Grab a fresh Ubuntu instance. Open up your favorite text editor. Nano, Vim, whatever. I do judge a little if you use Nano, but let us keep moving. Create a blank file. Name it install_lamp.sh.
The Meat and Potatoes of the Code
Start your file with the classic bash header. Then throw in a quick apt update command to clear the cobwebs. Next up? Apache. Tell the package manager to install apache2. Boom. Web server installed. But a web server is useless without data. So we tell the script to grab mysql-server. Finally, slap the PHP packages in there. Done. The entire stack, weaponized in plain text.
Execute and Grab a Beer
You saved the file. Now you need permission to run it. Change the file permissions to make it executable. Hit enter. Run the script. That is it. Watch the terminal scroll by like you are in the Matrix. Your server is configuring itself while you do absolutely nothing. Hit your server IP in a browser. If you see the Apache default page, you nailed it.