In this article, we cover how to set up the Mojolicious development environment using the Vagrant.
We also cover:
- Installation of VirtualBox
- Installation of Vagrant
- Create Vagrantfile
- Execute vagrant
A Vagrant is a tool focused on giving a uniform development environment across different operating systems.
It manages virtual machine environments and lowers the development environment setup time.
It also helps in getting rid of the "works on my machine" phrase commonly used by software developers.
Before installing Vagrant, we need to install VirtualBox on our operating systems.
If you are using MacOS,
brew update && brew upgrade
brew install virtualbox # Virtualbox installation
brew install vagrant # Vagrant Installation
On Debian/Ubuntu OS,
sudo apt update
sudo apt install virtualbox
sudo apt install vagrant
yum install virtualbox
yum install vagrant
To verify that the installation, run the following command that will print the Vagrant version:
Setting up the vagrant is fairly easy. We need to create a new directory to setup the root of the application.
Setup the Vagrantfile
Above command creates Vagrantfile in the current diretory i.e. vagrant_mojo
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.
Clear all the content of the 'Vagrantfile'
Vagrant.configure("2") do |config|
config.vm.box = "generic/ubuntu2004"
config.disksize.size = '25GB'
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8443
# Can access 3000 port from parent OS
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 3306, host: 30306
# If you are using postgres uncheck this
# config.vm.network "forwarded_port", guest: 5432, host: 54320
# For SSH
config.ssh.forward_agent = true
# Current folder is synced with the Vagrant VM /vagrant_data directory
config.vm.synced_folder "./", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
vb.memory = "5192"
# IMPORTANT: Vagrant run this shell script setup.sh during the configuration.
config.vm.provision:shell, path: "setup.sh"
Create a new file setup.sh and update the following content
echo "Installing Mojolicious"
sudo curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious
echo "Installing MariaDB on vagrant machine"
sudo apt update
sudo apt install mariadb-server -y
echo "Installing the Perl Module"
sudo cpan install DateTime -y
sudo cpan install DBIx::Class -y
sudo cpan install Crypt::PBKDF2 -y
sudo cpan install Mouse -y
sudo cpan install Email::Valid -y
sudo cpan install Mojolicious::Plugin::Authentication -y
sudo cpan install Mojolicious::Plugin::StaticCache -y
# Setting up the Mojolicious APP
mojo generate app vagrant_mojo
Save and exit the file. And run the following command.
This will take a little time to finish it up. Once the installation is done.
Mojo app is already created under the "/vagrant_data".
It will start the webserver at http://127.0.0.1:3000. Go to you browser of the operating system and type http://localhost:3000.
Now, you can do any changes from your main OS under the synced directory.
It will change the app by default in ubuntu OS (VirtualBox). It also preserves the environment from regular OS updates.