Vagrantfile for installing Nginx unit in a Vagrant VM

Last updated on April 12th, 2023 at 08:20 am.

Vagrantfile for installing Nginx unit in a Vagrant VM

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:

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.

Comment Here

Need WordPress help? Linux Server help? Talk to us.

  • We are your own WordPress customer service.
  • We set up Linux servers and install or migrate WordPress. Learn more here.
  • We support WooCommerce too.
  • Check out our WordPress customer support plans here or contact us below .

If you have any questions regarding WordPress support, Linux server support or any of our services, feel free to reach out or read more on our services page.

Join this free course:

How to host multiple WordPress
websites on a VPS

Close me!