Make a Vagrant box with Debian 12 LAMP stack, plus configure it for development.
-
Host: Linux or Mac.
-
Guest: Debian 12, Apache 2.4, MariaDB 10.11, PHP 8.2, Python 3.9, NPM 9+, Node.js 18+, Git 2+.
-
Leave code and version control files physically outside the VM while virtually accessing them inside the VM.
-
Use any GUI tool (IDEs, browsers, database administration applications, Git clients) outside the VM to access code and data inside the VM.
Read Stemar Vagrant boxes.
VM = virtual machine
In host machine terminal:
mkdir -p ~/VM && cd $_
git clone --depth=1 https://github.com/stemar/vagrant-debian-12.git debian-12
cd ~/VM/debian-12
vagrant up --provision
vagrant ssh- Prerequisites
- Vagrant preparation
- Virtual machine provisioning
- Configuration checks
- 64bit Debian 12 virtual machine with virtual 64GB HDD, 3GB RAM and updated LAMP stack from Bento.
- Custom
.bash_aliasesto modify bash settings inside the virtual machine. - Configure LAMP settings from the host machine instead of inside the virtual machine.
- Provisioning in
bashbecause the commands can easily be copied/pasted inside a VM or server for troubleshooting. - Keep multiple Vagrant boxes in a separate location than your projects/code location.
.vagrant/is created independently within each VM directory.- Multiple Vagrant boxes can be run concurrently from separate terminal tabs.
- Avoid port collision by editing
:forwarded_portsvalues insettings.yaml.
- Copied SSH keys to use the same in and out of VM.
- Copied Git configurations to use the same in and out of VM.
- Synchronized projects/code directories.
- Apache serves any local website at
http://domain.com.localhost:8000with VirtualDocumentRoot. - Add more VirtualHost blocks from the host machine and re-provision the Vagrant box.
- MariaDB and Adminer with no password for username
root.- Avoid writing a password a zillion times through development.
- Adminer served at
http://localhost:8000/adminer.php. - Development-specific
php.inisettings from.htaccessfor all local websites.
SSH keys, Git config settings from host machine are copied in virtual machine.
Check if you have them on your host machine:
ll ~/.ssh
cat ~/.gitconfigEdit values in settings.yaml.
- Edit the
:machinevalues if necessary. - Add arrays to the
:forwarded_portsvalue if necessary.- Ex.: Change the forwarded ports of this virtual machine to avoid port collision if you have multiple virtual machines running at the same time.
- Change
:synced_foldervalues to match your host machine pathname. - Edit the
:copy_filesvalues: - Edit the
:php_error_reportingvalue if necessary.
Edit config files if needed.
- Edit the
VirtualDocumentRootpublic directory value invirtualhost.conf. - Add
VirtualHosts invirtualhost.conf. - Edit
php.ini.htaccessvalues. - Add/edit lines to
bash_aliases.
Edit provision.sh if needed.
- Add/edit Linux tools.
- Add/edit PHP libraries.
- Add anything you need.
Provision the box from the host machine terminal:
cd ~/VM/debian-12
vagrant up --provisionTo halt the box:
vagrant halt -fTo boot the box without provisioning:
vagrant upIf anything goes wrong:
vagrant destroy -f
vagrant box update
vagrant up --provisionCheck the status of all Vagrant machines on your host machine:
vagrant global-statusConnect to the box through SSH:
vagrant sshBash prompt in virtual machine is now:
vagrant@debian-12:~$Check synchronized folders:
ll ~/Code
ll /vagrantCheck versions:
lsb_release -a
sudo apache2 -v
mysql -V
php -v
git --version
openssl version
curl --version
npm -v
nodejs -vCheck Apache configuration:
sudo apachectl configtest
sudo apachectl -V
cat /etc/hosts
cat /etc/apache2/apache2.conf
cat /etc/apache2/envvars
ll /etc/apache2/conf-available
ll /etc/apache2/conf-enabled
ll /etc/apache2/sites-available
ll /etc/apache2/sites-enabled
cat /etc/apache2/conf-available/localhost.conf
cat /etc/apache2/sites-available/virtualhost.conf
cat /etc/apache2/conf-available/adminer.conf
sudo cat /var/log/apache2/error.logCheck MariaDB databases:
mysql -u root
MariaDB [(none)]> SHOW DATABASES; quit;Check PHP modules and variables:
php -m
php -iYou see the "Apache2 Debian Default Page".
http://localhost:8000/adminer.php
- Username:
root - Password: leave empty
Replace domain.com with your domain and your custom forwarded port number.
http://domain.com.localhost:8000