Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

28
Emulating Staging Servers w/ über-awesome Vagrant, CentOS, & LAMP

description

Get your local development environment up, running, and closely matching your production server is less than 30 minutes with vagrant.

Transcript of Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Page 1: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Emulating Staging Servers

w/ über-awesome Vagrant, CentOS, & LAMP

Page 3: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

You need to learn Vagrant

NOWNo Excuses

Page 5: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

$ mkdir my-vagrant-installs # or whatever$ vagrant init chef/centos-6.5$ vagrant up$ vagrant ssh

Page 6: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Vagrant...the best thing since peanut butter and jelly

Page 7: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

So what is Vagrant

Page 8: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

No More● “It works on my machine”● I can’t install that on my shared host● Do they have that on Xampp?● Do they have that package for my operating

system?

Page 9: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

But… but…

...there’s port, homebrew, heroku

Yeah that’s true. But let me enlighten you.

Page 10: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Can port do this?

Strap a squirrel to a rocket ship and launch it to Greenland?

Page 11: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Vagrant can’t do thateither BUT it can:

● create a base Linux server using your favorite flavor (Ubuntu, CentOS, Debian, others)

● run set-up scripts (provisioning scripts)● set up port forwarding● allow tinkering with anything linux related, breaking it,

destroying it, and starting from scratch again● and much much more for an easy payment of...

A few lines of Ruby code and some shell commands

Page 12: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

More Reasons● try things that will break your production

server without the heart attacks● having a virtualized server locally can be

much faster and convenient for development● it’s the closest thing to your actual production

server so dev/prod parity is much more realistic

Page 13: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Vagrant is Digital Nomad FriendlyNo Internet or sucky connection, No problem.

Page 14: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Staging Server vs VagrantVagrant is just another VPS living inside of your computer. So you could treat it as such.

● VirtualHosts● SSH● SSL● Node.js, Python, Ruby, Clojure, Nginx, whatever

Page 16: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

CentOS, PHP 5.6, Apache, and Working Dev Environment in under 10 minutes

Page 17: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

$ vagrant init chef/centos-6.5A `Vagrantfile` has been placed in this directory. You

are now

ready to `vagrant up` your first virtual environment!

Please read

the comments in the Vagrantfile as well as

documentation on

`vagrantup.com` for more information on using Vagrant.

$ vagrant up$ vagrant ssh

Page 19: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

# make sure httpd is started after a restart$ chkconfig httpd on$ service iptables stop # turn off firewall (dev)$ exit$ exit

# now we’re back on our host machine$ vim Vagrantfile

# uncomment config.vm.network "forwarded_port", guest: 80, host: 8080# change the host port to something else if it conflicts

$ vagrant reload$ curl localhost:8080hello

Page 20: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Sexy Right?

Page 21: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Taking it one step further

Page 22: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

# we’re on our host machine$ echo '<?php echo "hello on my host machine\n";' > index.php$ vagrant ssh$ sudo rm -rf /var/www/html$ sudo ln -s /vagrant /var/www/html

$ exit

$ curl localhost:8080

Page 23: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Other cool features● sharing your environment and exposing it

with a url to a co-worker/friend/evil h4x0r with vagrant connect

● spooling up AWS/DigitalOcean/Rackspace instances

● using configuration management packages like puppet, chef, and ansible

● creating your own base box

Page 24: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

http://docs.vagrantup.com/v2/

Page 25: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Where’s my box...ershttp://www.vagrantbox.es

http://www.vagrantcloud.com

Online Configuratorshttps://puphpet.com

http://rove.io

Page 27: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Questions!?Sock ‘em to me

Page 28: Emulate Staging Servers W/ Vagrant, CentOS & LAMP PHP 5.6

Follow me y’all @2upmedia

http://linkedin.com/in/2upmedia

https://coderwall.com/p/u/2upmedia