Vagrant LEMP stack

#Introduction

In this tutorial, I wrote deploy Vagrant LEMP stack. I will install and configure the LEMP stack for this web application.

What does lemp stand for ?

Linux operating system, and Nginx (pronounced engine-x, hence the E in the acronym) webserver. MySQL database and dynamic content processed by PHP.

My Environment for Vagrant LEMP stack

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

Vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-LEMP
│   Vagrantfile
│
├───Files

│       index.html
│       info.php
│
└───shell

        web-lemp-rocky.sh

Files Folder contains test Nginx and PHP with index.html and info.php files.

“>

The content index.html and info.php files

# index.html file

<html>
    <h2>DevopsRoles.com</h2>
</html>

# info.php file

<?php
phpinfo();
?>

I Created a “web-lemp-rocky.sh” script to install Nginx, MySQL, and PHP on Rocky Linux. I use the provisioning shell of Vagrant to deploy LEMP on Rocky Linux.

The content script is as below:

#!/bin/bash


#Tools
sudo dnf install -y git unzip net-tools

#Apache
sudo dnf install -y nginx

#chkconfig --add nginx
sudo systemctl enable nginx
sudo systemctl stop nginx

sudo systemctl start nginx

#PHP
sudo dnf install php php-fpm php-gd php-mysqlnd php-cli php-opcache
sudo systemctl enable php-fpm
sudo systemctl start php-fpm

#MySQL
sudo dnf install -y mysql mysql-server mysql-devel
sudo systemctl enable mysqld.service
sudo systemctl start mysqld

mysql -u root -e "SHOW DATABASES";

# content
# sudo rm -rf /var/www/html/*
sudo cp -rf /vagrant/Files/{index.html,info.php} /usr/share/nginx/html/
# cd /vagrant
#sudo -u vagrant wget -q https://raw.git.....

sudo systemctl restart nginx

Create a Virtual Machine

Navigate to my working directory

cd Rocky-LEMP
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  

  config.vbguest.auto_update = false
  
  config.vm.define "webserver" do |webserver|
    webserver.vm.hostname = "devopsroles.com"
    webserver.vm.network "private_network", ip: "192.168.4.4"
    webserver.vm.network "forwarded_port", guest: 80, host: 8888
    webserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LEMP\\shell\\web-lemp-rocky.sh"

  end

end

Deploy LEMP on Rocky Linux

vagrant up

To connect to Web Server.

vagrant ssh webserver

The output terminal as below

Vagrant LEMP stack

Opens a browser that can access your Server’s IP address.

Vagrant LEMP Stack Nginx 1

Testing PHP

Vagrant LEMP stack

Conclusion

You have to use the Vagrant LEMP stack on Rocky Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.