Skip to content

Instantly share code, notes, and snippets.

@Jakiboy
Created April 4, 2023 20:51
Show Gist options
  • Save Jakiboy/52e7c108088913eee79b5b503c027dfc to your computer and use it in GitHub Desktop.
Save Jakiboy/52e7c108088913eee79b5b503c027dfc to your computer and use it in GitHub Desktop.
Vagrant (Virtualbox)
# Update / Upgrade
apt-get update
apt-get upgrade -y
apt-get --purge autoremove -y
# Setup Apache Server
apt-get install apache2 -y
apt-get install libapache2-mod-php7.4 -y
a2enmod rewrite
a2dissite 000-default
a2dissite default-ssl
# Setup MySQL Server
apt-get install mariadb-server -y
service mysql restart
# Setup PHP
apt-get install php7.4-common -y
apt-get install php7.4-cli -y
apt-get install php7.4-curl -y
apt-get install php7.4-intl -y
apt-get install php7.4-imagick -y
# Setup PhpMyAdmin
apt-get install phpmyadmin -y
echo 'Include /etc/phpmyadmin/apache.conf' >> /etc/apache2/apache2.conf
# Setup Permissions
adduser --disabled-password --gecos "" webmaster --uid 1500
usermod --password $(echo 123456789 | openssl passwd -1 -stdin) webmaster
usermod -aG www-data webmaster
usermod -d /var/www -m webmaster
echo 'export APACHE_RUN_USER=webmaster' >> /etc/apache2/envvars
service apache2 restart
service ssh restart
# Install Composer
apt-get install composer -y
# Install WP-CLI
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod u+x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
# Install GIT
apt-get install git -y

Vagrant (Virtualbox)

⚡ Init

vagrant init debian/bullseye64

⚡ Provision

vagrant provision

⚡ UP

vagrant up
# vagrant up --provision

⚡ Login

vagrant ssh

⚡ Configuration

@ /etc/apache2/apache2.conf

EnableSendfile Off

@ ./Vagrantfile

  # Setup virtualbox
  config.vm.provider :virtualbox do |vb|
    vb.name = "debian-server-remote"
    vb.memory = 2048
    vb.cpus = 2
    vb.customize ["modifyvm", :id, "--ioapic", "on"]
  end
  # Setup ssh
  config.ssh.port = 55555
  # Setup network
  config.vm.hostname = "debian.server.remote"
  config.vm.usable_port_range = 2200..55555
  config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 443, host: 443, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 22, host: 55555, host_ip: "127.0.0.1", id: "ssh"
  config.vm.network "private_network", ip: "192.168.33.10"
  # Setup sync
  UID = 1500
  GID = 33
  config.vm.synced_folder "./www", "/var/www",
    create: true,
    owner: UID, # webmaster
    group: GID # www-data
  # Setup provision
  config.vm.provision "shell", path: "provisioner.sh"

⚡ Provisioner

# Update / Upgrade
apt-get update
apt-get upgrade -y
apt-get --purge autoremove -y

# Setup Apache Server
apt-get install apache2 -y
apt-get install libapache2-mod-php7.4 -y
a2enmod rewrite
a2dissite 000-default
a2dissite default-ssl

# Setup MySQL Server
apt-get install mariadb-server -y
service mysql restart

# Setup PHP
apt-get install php7.4-common -y
apt-get install php7.4-cli -y
apt-get install php7.4-curl -y
apt-get install php7.4-intl -y
apt-get install php7.4-imagick -y

# Setup PhpMyAdmin
apt-get install phpmyadmin -y
echo 'Include /etc/phpmyadmin/apache.conf' >> /etc/apache2/apache2.conf

# Setup Permissions
adduser --disabled-password --gecos "" webmaster --uid 1500
usermod --password $(echo 123456789 | openssl passwd -1 -stdin) webmaster
usermod -aG www-data webmaster
usermod -d /var/www -m webmaster
echo 'export APACHE_RUN_USER=webmaster' >> /etc/apache2/envvars
service apache2 restart
service ssh restart

# Install Composer
apt-get install composer -y

# Install WP-CLI
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod u+x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp

# Install GIT
apt-get install git -y

⚡ Reload

vagrant reload
# vagrant reload --provision

⚡ Status

vagrant status

⚡ Share

vagrant plugin install vagrant-share
vagrant share

⚡ NFS

Host: (Windows)

Disable-WindowsOptionalFeature -FeatureName ServicesForNFS-ClientOnly, ClientForNFS-Infrastructure 
-Online -NoRestart

Guest: (Linux)

apt-get install nfs-common rpcbind
mount -v -t nfs -o vers=3 192.168.33.1:/c/www /var/www
vagrant ssh -- -t 'sudo mount -v -t nfs -o vers=3 192.168.33.1:/c/www /var/www; /bin/bash'

⚡ Stop

vagrant halt

⚡ Remove

vagrant destroy
Vagrant.configure("2") do |config|
# Init box
config.vm.box = "debian/bullseye64"
# Setup virtualbox
config.vm.provider :virtualbox do |vb|
vb.name = "debian-server-remote"
vb.memory = 2048
vb.cpus = 2
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
# Setup ssh
config.ssh.port = 55555
# Setup network
config.vm.hostname = "debian.server.remote"
config.vm.usable_port_range = 2200..55555
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 443, host: 443, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 22, host: 55555, host_ip: "127.0.0.1", id: "ssh"
config.vm.network "private_network", ip: "192.168.33.10"
# Setup sync
UID = 1500
GID = 33
config.vm.synced_folder "./www", "/var/www",
create: true,
owner: UID, # webmaster
group: GID # www-data
# Setup provision
config.vm.provision "shell", path: "provisioner.sh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment