Vagrant LEMP stack


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:

│   Vagrantfile

│       index.html
│       info.php

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


# info.php file


I Created a “” 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:


sudo dnf install -y git unzip net-tools

sudo dnf install -y nginx

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

sudo systemctl start nginx

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

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| = "rockylinux/8"
  config.ssh.insert_key = false  

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



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


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 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.