Marlin vagrant is a WordPress optimized vagrant server created for local development environment for servers that use WordPress optimized Digital Ocean droplets. Vagrant box is named after marlin which is one of the fastest animals in the world.
This vagrant server can be used as plain local server for serving your files or testing static PHP, but it's also perfect for WordPress development.
Marlin is currently a development VM and under testing.
Feature | Version / amount |
---|---|
Ubuntu | 14.04.3 LTS (Trusty Tahr) |
MySQL | 5.5 |
PHP | 5.6.15 |
WordPress optimizations | PHP modules recommended for optimal WordPress performance |
Vagrant | NFS, provision.sh with pre-installed packages, speed optimizations |
CPU cores | 1 |
RAM | 1 GB |
nginx | 1.4.6 |
HHVM | 3.10.1 |
This is based on jolliest-vagrant, our first Vagrant box with Apache. We needed faster and scalable environment, so started to use Digital Ocean droplets and needed a local development server identical to that. And so Marlin vagrant was born.
Read the original background story about Dude's vagrant-servers here.
To start this vagrant box, always run vagrant up --provision
, with provision -hook to ensure all the stuff are loaded up properly.
- Installation on Mac/Linux
- Installation on Windows
- How to add new vhost
- How to remove a project or vhost
- Connecting with another computer in LAN
- Port forwarding (optional)
- [Recommended post-installations](#recommended post-installations)
- Create a self-signed SSL Certificate for marlin-vagrant
- Sequel Pro settings for MySQL
- Troubleshooting and issues
- WP-CLI alias
- Mac OS X or Linux
- Simple knowledge of web servers
- WordPress projects under the same folder
- dudestack in use
- Install Virtualbox
- Start Virtualbox, check updates and install all the latest versions of Virtualbox and Oracle VM Virtualbox Extension Pack, if asked
- Install vagrant (Mac OS X Homebrew:
brew install vagrant
) - Install vagrant-triggers with command
vagrant plugin install vagrant-triggers
- Install VirtualBox Guest Additions -updater vagrant-vbguest with command
vagrant plugin install vagrant-vbguest
- Clone this repo to your Projects directory (path
~/Projects/marlin-vagrant
is depedant in dudestack) - (Optional, do this for example if you want to use other image or encounter problems with included Vagrantfile) If you don't know or don't care, don't do this step. Modify Vagrantfile:
config.vm.box
andconfig.vm.box_url
to match your production server OS,config.vm.network
for IP (I recommend it to be10.1.2.4
to prevent collisions with other subnets) (For Linux you need to remove, :mount_options...
if problems occur with starting the server. Please remove parts that give you errors). If you don't need to access server from LAN with co-workers to update WordPress for example, remove completely line withconfig.vm.network "public_network"
. You may also need to try different ports than 80 and 443 if your Mac blocks them. For example change the ports to 8080 and 443 (also change triggers accordingly) - If you store your projects in different folder than ~/Projects, change the correct path to
config.vm.synced_folder
- Edit or add packages to match your production server packages in provision.sh if needed (it's good out of the box though)
- Add
10.1.2.4 somesite.dev
to your /etc/hosts - Run
vagrant up --provision
. This can take a moment.
If you make any changes to Vagrantfile, run vagrant reload
or vagrant up --provision
if the server is not running, or if you change provision.sh while running, run vagrant provision
.
You can always see the server status by vagrant ssh
'ing to your vagrant box and typing sudo service nginx status
. If it's not started, run sudo service nginx start
. Note: if your server doesn't start, please ensure you either have removed example.dev from vhosts/
and /etc/nginx/sites-available
and /etc/nginx/sites-enabled
or created a directory called example
to your Projects dir.
- Install Virtualbox for Windows
- Install Vagrant for Windows
- Install Git for Windows
- Right click My Computer (or This Compu
ter on Windows 10), click Properties, click Advaned System Settings tab, click Environment Variables. Change
VBOX_MSI_INSTALL_PATH
toVBOX_INSTALL_PATH
. In Windows 10, you can go to Advanced System Settings simply typing it when Start Menu is open. - Start
cmd
- Navigate to root of
C:\
with double dots..
mkdir Projects
to create a project dir andcd Projects
to enter it- Clone this repo to Projects with command
git clone git@github.com:digitoimistodude/marlin-vagrant.git
- Edit
Vagrantfile
with your favorite editor and rename~/Projects
toC:/Projects
. Remove, :mount_options => ['nolock,vers=3,udp,actimeo=2']
- Run
vagrant up --provision
, wait when box is installed and Allow access if it asks it. This can take a moment. - Add
10.1.2.4 somesite.dev
to your C:/Windows/system32/drivers/etc/hosts file and have fun!
It's simple to manage multiple projects with nginx's sites-enabled configs. If your project name is jolly
, and located in ~/Projects/jolly, just add new config to vhosts. vhosts/jolly.dev would then be:
server {
listen 80;
#listen [::]:80 default ipv6only=on;
access_log /var/www/jolly/access.log;
error_log /var/www/jolly/error.log;
root /var/www/jolly;
index index.html index.htm index.php;
server_name jolly.dev www.jolly.dev;
include hhvm.conf;
include global/wordpress.conf;
# Static File Caching
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
}
Run vagrant provision
, add 10.1.2.4 jolly.dev
to /etc/hosts
and boom! http://jolly.dev points to your project file.
If you remove a project from Projects folder, or rename it, you should also remove/rename vhosts/projectname.dev
correspondingly and make sure after vagrant ssh
you don't have that conf to point nonexisting files in /etc/nginx/sites-enabled
and /etc/nginx/sites-available
. Otherwise the server wont' start!
For example, if we create test project to ~/Projects/test and then remove the folder, next time you are starting up nginx fails. You will have to vagrant ssh
and sudo rm /etc/nginx/sites-enabled/test.dev && sudo rm /etc/nginx/sites-available/test.dev && /vagrant/vhosts/test.dev
.
You should be good to go after setting up /etc/hosts to 192.168.2.242 jolly.dev
(depending on your local subnet of course) on remote computer. If you have problems like I had, run this command on your vagrant host PC (not inside vagrant ssh!):
sudo ssh -p 2222 -gNfL 80:localhost:80 vagrant@localhost -i ~/.vagrant.d/insecure_private_key
This also helps in some cases where you are unable to open http://localhost in browser window.
Vagrantfile
has port forwarding included, but Mac OS X has some limitations. If .dev-urls are not reachable from local area network, please add this to /usr/bin/forwardports
by sudo nano /usr/bin/forwardports
:
echo "
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 8443
" | sudo pfctl -f - > /dev/null 2>&1;
echo "==> Fowarding Ports: 80 -> 8080, 443 -> 8443";
osascript -e 'tell application "Terminal" to quit' & exit;
Chmod it by chmod +x /usr/bin/forwardports
and run forwardports
. You have to do this every time after reboot, if you are co-working in LAN.
I have not included everything to this box since I want it keep as minimal as possible, but here's some recommended pieces you should install especially on production (I'll add more later):
- rocket-nginx - Nginx configuration for WP-Rocket
- ngx_pagespeed - The PageSpeed modules are open-source server modules that optimize your site automatically.
- Go to the directory you cloned this repo by
cd ~/Projects/marlin-vagrant
- SSH into your vagrant box:
vagrant ssh
sudo mkdir /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
(press enter all the way through)sudo nano /etc/nginx/sites-enabled/yourwebsitename.dev
and make sure it looks like something like this:
server {
listen 443 ssl;
access_log /var/www/yourwebsitename/access.log;
error_log /var/www/yourwebsitename/error.log;
root /var/www/yourwebsitename;
index index.html index.htm index.php;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
server_name yourwebsitename.dev www.yourwebsitename.dev;
include hhvm.conf;
include global/wordpress.conf;
}
- Restart nginx:
sudo service nginx restart
WP-Cli is included in dudestack per project within composer.json
and won't work by default. You'll need this alias on your Mac or Linux .bashrc
or .bash_profile
file:
alias wp='ssh vagrant@10.1.2.4 "cd /var/www/"$(basename "$PWD")"; /var/www/"$(basename "$PWD")"/vendor/wp-cli/wp-cli/bin/wp"'
After restarting Terminal or running . ~/.bashrc
or . ~/.bash_profile
you will be able to use wp
command directly on your host machine without having to ssh into vagrant.
==> marlin: Booting VM...
==> marlin: Waiting for machine to boot. This may take a few minutes...
marlin: SSH address: 127.0.0.1:2222
marlin: SSH username: vagrant
marlin: SSH auth method: private key
marlin: Warning: Connection timeout. Retrying...
marlin: Warning: Authentication failure. Retrying...
marlin: Warning: Authentication failure. Retrying...
marlin: Warning: Authentication failure. Retrying...
marlin: Warning: Authentication failure. Retrying...
...
This is probably if you use jolliest-vagrant or another vagrant box with same ssh keypairs. This can be solved with cat ~/.ssh/id_rsa.pub
, copying that key, then going to cd ~/Projects/marlin-vagrant && vagrant ssh
, typing password, then adding the file to VM's known_hosts with nano ~/.ssh/known_hosts
and saving the file while connecting.
In any issue, error or trouble, please open an issue to issue tracker.
Choose SSH tab and add following settings.
Setting | Input field |
---|---|
Name: | vagrant mysql |
MySQL Host: | 127.0.0.1 |
Username: | root |
Password: | vagrant |
Database: | optional |
Port: | 3306 |
SSH Host: | 10.1.2.4 |
SSH User: | vagrant |
SSH Password: | vagrant |
SSH Port: | 22 |