
Nginx unit is a lightweight Universal Web app server that can run static files, PHP, Python, Ruby, Go, NodeJS, Java and Perl. It is fantastic, and you should learn to use it, is all I can say.
Requirements before running this Vagrant file:
- You need Vagrant installed.
- On Linux, I prefer libvirt instead of Virtualbox. How to install Libvirt.
- You can uninstall Virtualbox, if you have libvirt ready.
- On Linux, you need nfs to sync files between your VM and the host computer. Here is the guide for installing nfs.
Notes:
The Vagrant box used is Debian 11, feel free to use a different box, but you must get the installation steps from the Nginx unit install page. And replace what is added under the Vagrant file section for installing unit (Labelled as # Install unit
)
You can add more Unit modules, in the vagrant file below, only unit-php
is installed. To run other languages such as Python, Java, Ruby, Go etc, you need to install the relevant modules such as : unit-devel unit-jsc11 unit-jsc8 unit-perl unit-python311 unit-ruby
.
Create a Vagrantfile. Copy the vagrant content below into it. Then change directory to where the Vagrantfile is located, and run it using, vagrant up
.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "debian/bullseye64"
config.vm.provider :libvirt do |libvirt|
libvirt.memory = 2048
end
# One Virtual machine
config.vm.define "machine0" do |machine0|
machine0.vm.box = "debian/bullseye64"
machine0.vm.network "private_network", ip: "192.168.53.10"
machine0.vm.synced_folder "~/unitvm/unitfiles", "/vagrant/unitfiles", type: "nfs" , nfs_version: 4, mount_options: ["nolock"]
machine0.vm.hostname = "Machine0"
machine0.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y curl
# Install unit
curl --output /usr/share/keyrings/nginx-keyring.gpg \
https://unit.nginx.org/keys/nginx-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/debian/ bullseye unit
deb-src [signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://packages.nginx.org/unit/debian/ bullseye unit
" > /etc/apt/sources.list.d/unit.list
sudo apt update
sudo apt install -y unit unit-php
sudo systemctl restart unit
SHELL
end
# Configuration for a second machine if you need it
# config.vm.define "machine1" do |machine1|
# machine1.vm.box = "debian/bullseye64"
# machine1.vm.network "private_network", ip: "192.168.53.11"
# machine1.vm.hostname = "Machine1"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y curl git
SHELL
end
If you experience any problems, just leave a comment below and I will see how to assist you. If you need a video guide, for this Nginx unit vagrant installation, let me know.