Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created April 13, 2024 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tournasdim/65f4728ca4ddaddde1b441c68ce4ca04 to your computer and use it in GitHub Desktop.
Save tournasdim/65f4728ca4ddaddde1b441c68ce4ca04 to your computer and use it in GitHub Desktop.
A Vagrant file for an Ubuntu PHP development server . Virtualbox 7 as Provider , Shell as Provisiner , Apache , PHP v8.1 , Mysql 8 , Composer .
# -*- mode: ruby -*-
# vi: set ft=ruby :
# this script loads an Ubuntu 22.04 LTS (Jammy Jellyfish) development server (!!!! not for production )
# If it doesn't load the php-module into apache2 server ( to verify use the "phpinfo();" into a index.php file )
# So we have to manualy login with "vagrant ssh" and use cli command for investigation
# 1) apachectl -M | grep php --> list of all apache's loaded modules (static , shared)
# 2) ls /etc/apache2/mods-available --> if php mod not listed, make an installation with apt-get
# sudo apt-get install libapache2-mod-php8.1 and sudo a2nmode php
# --- OR ---
# sudo apt-get install php8.1-fpm (Fast CGI) and sudo a2nmode php8.1-fpm
$script = <<-SCRIPT
sudo apt-get update -y
sudo apt-get install -y apache2
sudo apt-get install -y mysql-server
#sudo apt-get install -y software-properties-common
sudo apt-get install -y composer
sudo apt-get install -y libapache2-mod-php8.1
sudo systemctl enable apache2
sudo systemctl enable mysql
sudo systemctl restart apache2
sudo systemctl restart mysql
sudo systemctl restart php8.1-fpm
sudo apt-get install -y libapache2-mod-php8.1
SCRIPT
Vagrant.configure("2") do |box|
box.vm.define "ubuntu-22" do |config|
config.vm.box = "ubuntu/jammy64" # Ubuntu 22.04 LTS (Jammy Jellyfish)
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)" # Network card accessible on the local machine
config.vm.network "private_network", ip: "192.168.56.10" # Private IP for the guest machine
config.vm.synced_folder "./www", "/var/www/html" # Shared folder between host and guest
config.vm.provision "shell", inline: $script
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024" # 1GB RAM
vb.cpus = 1 # 1 CPU core
vb.gui = false # Disable the GUI
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment