Deploy LAMP on rocky Linux using Vagrant

#Introduction

In this tutorial, How to deploy LAMP on Rocky Linux using Vagrant. LAMP is Linux Operating System, Apache Web Server, MySQL Database, and PHP Programming Language.

Development Environments Made Easy Quote by www.vagrantup.com

My Environment

  • Host OS: Window 11 or Ubuntu / Centos or Rocky server.
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

Deploy LAMP on rocky Linux using Vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-LAMP
|   Vagrantfile
|
+---Files
|       gitconfig
|       index.html
|       info.php
|
\---Scripts
        lamp-rocky.sh

Create a Virtual Machine

Navigate to my working directory and create an initial Vagrantfile if one does not already exist.

cd Rocky-LAMP
vagrant init rockylinux/8

Configure the Virtual Machine

You need to edit the Vagrantfile and paste the content as below

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

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

  config.vm.box = "rockylinux/8"
  config.vm.hostname = "devopsroles.com"
  config.ssh.insert_key = false
  config.vm.network "private_network", ip: "192.168.4.4"
  config.vm.network "forwarded_port", guest: 80, host: 8888
  config.vbguest.auto_update = false
  # Install LAMP on Rocky server
  config.vm.provision "shell", 
  path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LAMP\\Scripts\\lamp-rocky.sh"
  # Test HTML
  #config.vm.provision "file", 
  # source: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LAMP\\Files\\index.html",
  # destination: "/var/www/html/index.html"
  #Test PHP
  #config.vm.provision "file", 
  # source: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LAMP\\Files\\info.php",
  # destination: "/var/www/html/info.php"
end

I use provision shell to install Apache, MySQL, and PHP on Rocky Linux. The script update OS, install the packages: Apache PHP and MySQL.

The content “lamp-rocky.sh” script is as below:

#!/bin/bash

#Update OS
sudo yum update -y --exclude=kernel

#Tools
sudo yum install -y git unzip

#Apache
sudo dnf install -y httpd httpd-devel httpd-tools

#chkconfig --add httpd
sudo systemctl enable httpd.service
sudo systemctl stop httpd

sudo systemctl start httpd

#PHP
sudo dnf install -y php php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

#MySQL
sudo yum 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} /var/www/html/
# cd /vagrant
#sudo -u vagrant wget -q https://raw.git.....

sudo systemctl restart httpd

Deploy LAMP on Rocky Linux

We use the “vagrant up” command line. This command creates and configures guest machines according to your Vagrantfile

vagrant up

How to connect to the virtual machine.

vagrant ssh

The output terminal as below

C:\MyData\Vagrant_VMS\Projects\Vagrant\Rocky-LAMP>vagrant ssh
[vagrant@devopsroles ~]$ cat /etc/redhat-release
Rocky Linux release 8.5 (Green Obsidian)
[vagrant@devopsroles ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:fc:e9:96 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute eth0
       valid_lft 85565sec preferred_lft 85565sec
    inet6 fe80::a00:27ff:fefc:e996/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:cf:7f:96 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.4/24 brd 192.168.4.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fecf:7f96/64 scope link
       valid_lft forever preferred_lft forever

You need to open a browser that can access your Server’s IP address.

The resulting output picture as below:

image 8

A page displaying the PHP version among other parameters such as details of PHP extensions enabled will be displayed below

Deploy LAMP on rocky Linux

Conclusion

You have to deploy LAMP on rocky Linux using Vagrant. 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 *

Comment moderation is enabled. Your comment may take some time to appear.

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