Vagrant box CentOS 8 LAMP
Make a Vagrant box with CentOS 8 LAMP stack, plus configure it for development.
-
Host: Linux or Mac.
-
Guest: CentOS 8.3, Apache 2.4, MariaDB 10.5, PHP 7.4, Python 2 & 3, 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.
Summary
VM = virtual machine
Quick installation
In host machine terminal:
mkdir -p ~/VM && cd $_
git clone --depth 1 https://github.com/stemar/vagrant-centos-8.git centos-8
cd ~/VM/centos-8
vagrant up --provision
vagrant ssh
Steps
- Prerequisites
- Vagrant preparation
- Virtual machine provisioning
- Configuration checks
Result
- 64bit Centos 8.3 virtual machine with virtual 64GB HDD, 3GB RAM and updated LAMP stack from Bento.
- Custom
.bashrc
to modify bash settings inside the virtual machine. - Configure LAMP settings from the host machine instead of inside the virtual machine.
- Provisioning in
bash
because 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_ports
values insettings.yaml
.
- Copied SSH keys to use the same in and out of VM.
- Copied Git and Subversion configurations to use the same in and out of VM.
- Synchronized projects/code directories.
- Apache serves any local website at
http://domain.com.localhost:8000
with 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.ini
settings from.htaccess
for all local websites.
Prerequisites
SSH keys, Git config and Subversion config settings from host machine are copied in virtual machine.
Check if you have them on your host machine:
ll ~/.ssh
ll ~/.subversion
cat ~/.gitconfig
Vagrant preparation
Edit values in settings.yaml
.
- Edit the
:machine
values if necessary. - Add arrays to the
:forwarded_ports
value 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_folder
values to match your host machine pathname. - Edit the
:copy_files
values:- Ex.: Remove the Subversion array if you don't have it on your host machine.
- Edit the
:php_error_reporting
value if necessary.
Edit config
files if needed.
- Edit the
VirtualDocumentRoot
public directory value invirtualhost.conf
. - Add
VirtualHost
s invirtualhost.conf
. - Edit
php.ini.htaccess
values. - Add/edit lines to
bash_aliases
.
Edit provision.sh
if needed.
- Add/edit Linux tools.
- Add/edit PHP libraries.
- Add anything you need.
Virtual machine provisioning
Provision the box from the host machine terminal:
cd ~/VM/centos-8
vagrant up --provision
To halt the box:
vagrant halt -f
To boot the box without provisioning:
vagrant up
If anything goes wrong:
vagrant destroy -f
vagrant box update
vagrant up --provision
Check the status of all Vagrant machines on your host machine:
vagrant global-status
Connect to the box through SSH:
vagrant ssh
Bash prompt in virtual machine is now:
[vagrant@centos-8 ~]$
Configuration checks
Check LAMP settings
Check synchronized folders:
ll ~/Code
ll /vagrant
Check versions:
cat /etc/redhat-release
httpd -V
mysql -V
php -v
svn --version
git --version
openssl version
curl --version
Check Apache configuration:
apachectl configtest
httpd -D DUMP_VHOSTS
cat /etc/hosts
cat /etc/httpd/conf/httpd.conf
ll /etc/httpd/conf.d
cat /etc/httpd/conf.d/php.conf
cat /etc/httpd/conf.d/ssl.conf
cat /etc/httpd/conf.d/localhost.conf
cat /etc/httpd/conf.d/virtualhost.conf
cat /etc/httpd/conf.d/adminer.conf
sudo cat /etc/httpd/logs/error_log
Check MariaDB databases:
mysql -u root
MariaDB [(none)]> SHOW DATABASES; quit;
Check PHP modules and variables:
php -m
php -i
Browse local websites
Check localhost
You see the default Centos "Testing 123.." page.
Check Adminer
http://localhost:8000/adminer.php
- Username:
root
- Password: leave empty
Check your domain(s)
Replace domain.com
with your domain and your custom forwarded port number.
http://domain.com.localhost:8000