Skip to content

Vagrant

Mark Howells-Mead edited this page Oct 9, 2019 · 1 revision

This process was initially developed by colleagues at frappant.ch at the beginning of 2017. Scotchbox will be used: a pre-defined distribution.

Install software

Set up a project for Vagrant

Create the Vagrantfile

…in the document root.

Use the following example YAML file for project configuration.

Edit the following information in the Vagrantfile for your project.

  • Comment the appropriate code blocks for the appropriate PHP version in/out.
  • Comment in the appropriate block for SSL if you need it.

Create a database and user

Using Sequel Pro in SSH mode.

  • MySQL Host: 127.0.0.1
  • Database user: root
  • Database password: root
  • SSH host: [IP from the Vagrantfile]
  • SSH user: vagrant
  • SSH password: vagrant

Use Vagrant

  • Start server: vagrant up
  • Re-provision the configuration: vagrant provision
  • Re-start the server: vagrant reload
  • Stop server: vagrant halt
  • View all current machines: vagrant global-status
  • Reset list of all current machines: vagrant global-status --prune
  • Destroy Vagrant machine: vagrant destroy [ID]. Alternative: delete in VirtualBox

I.P. addresses for separate projects

Each project should receive its own I.P. address, according to the convention 192.168.33.X. .0, .1 and .255 are reserved and may not be used.

Log files

Edit the project's php.ini file to choose where to save an error log file. For example, error_log = /var/www/web/php_errors.log puts the file into the web root of the project.

Setup SASS and Compass in VVV

Problems

500 Internal Error

If you're running TYPO3, then clear the typo3temp/Cache folder. This may resolve any inexplicable issues. If you're running WordPress, then add the following lines to wp-config.php.

ini_set('display_errors',true);
error_reporting(E_ALL);

.dev / 127.0.53.53

If the domain isn't reachable in the browser and a ping results in the I.P. address 127.0.53.53, this indicates a DNS conflict. Make sure that the Vagrantfile is correct, then completely remove the pre-existing VM using vagrant destroy and ensure that the .vagrant folder is also removed. Then re-run vagrant up.

Also be aware that the TLD suffix .dev may become a valid public suffix. In this event, an alternative suffix will need to be used.

Exports file

Problem: NFS is reporting that your exports file is invalid.

Lösung:

sudo rm /etc/exports
sudo touch /etc/exports
vagrant halt
vagrant up --provision

Unreachable

The initialisation of a virtual machine with Vagrant adds an entry to the hosts file at etc/hosts. If the machine is deleted manually, then this entry is not automatically removed. Make sure that there is only one entry in the hosts file per domain.

Mounting NFS shared folders

If the server request times out, there's an error in the configuration within the Vagrantfile. Check the following.

  • Invalid IP address for the domain/machine.

WordPress

WP CLI

vagrant ssh into the running Vagrant box, then run the following commands to install the WP CLI binary. Run CLI commands from /var/www/web – the webroot of the project in the virtual machine – over the SSH connection.

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
sudo chmod 0777 /usr/local/bin/wp

Test WP CLI:

cd /var/www/web
wp --info

Mailcatcher

GUI

Use the IP address from the Vagrant config file with the port number 1080 appended.

WordPress

define('WP_SMTP_HOST', 'localhost');
define('WP_SMTP_PORT', 1025);
define('WP_SMTP_USER', '');
define('WP_SMTP_PASSWORD', '');
define('WP_SMTP_FROM', 'John Doe <[email protected]>');
Clone this wiki locally