Author......Ikaros Kappler Date............2016-10-28 Version................1.0
Virtual machine setup with Vagrant Up and Virtual Box
Four months ago I started to develop software on virtual machines.
Hadn't done that before but it took only some hours to get me
convinced that using virtual machines for web-based software
development is a good idea.
I am using Virtual Box in combination with Vagrant Up here.
Just install them:
Note: My preferred operating system is Debian Linux and I'm going to install the current stable version Debian8 Jessie. Oh, and did I mention that we are gonna using PHP7, which is not yet available in debian's default repositories? :)
I am using Virtual Box in combination with Vagrant Up here.
Just install them:
$ apt-get install vagrant virtualbox
Note: My preferred operating system is Debian Linux and I'm going to install the current stable version Debian8 Jessie. Oh, and did I mention that we are gonna using PHP7, which is not yet available in debian's default repositories? :)
Here comes the setup
Here we go. After installing Virtualbox and Vagrant perform these steps:
Have fun with your virtual machine(s)!
(~ ̄▽ ̄)~
# I am using the Laravel PHP framework. vagrant box add laravel/homestead # Init vagrant and install a debian image. This can take up several minutes # as the whole package needs to be downloaded. # Other available systems are: # vagrant init hashicorp/precise32 # vagrant init hashicorp/precise64 vagrant init debian/jessie64 # That's it for the beginning. Your base system should be downloaded and # stored in a virual box. # Start the virtual machine (this can take some minutes at first run) vagrant up --provider virtualbox # Log in to the virtual machine via SSH. Vagrant's default port # is 2222 (not 22 as it might be in use by you parent system). vagrant ssh# If you want to login into vagrant using PUTTY or Emacs, copy the # public key file into your .ssh directory: cd debian8/.vagrant/machines/default/virtualbox cp vagrant_key ~/.ssh/ # Edit the ~/.ssh/config file (on your parent system): Host 127.0.0.1 User vagrant Hostname 127.0.0.1 ForwardX11 yes ForwardAgent yes IdentityFile /Users/<user>/.ssh/vagrant_key DSAAuthentication yes PubkeyAuthentication yes # Configure the VM's network emacs Vagrantfile config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "private_network", ip: "192.168.33.10"# If you want to take a look at my Vagrant file:# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you know what # you're doing. Vagrant.configure("2") do |config| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "debian/jessie64" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "forwarded_port", guest: 9980, host: 9980 config.vm.network "forwarded_port", guest: 8000, host: 8000 config.vm.network "forwarded_port", guest: 6379, host: 6379 # Create a private network, which allows host-only access to the machine # using a specific IP. config.vm.network "private_network", ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "~/", "/vagrant/data" config.vm.synced_folder "your_project/", "/var/www/html/your_project" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available. See the documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information. # config.push.define "atlas" do |push| # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the # documentation for more information about their specific syntax and use. # config.vm.provision "shell", inline: <<-SHELL # apt-get update # apt-get install -y apache2 # SHELL end# Exit your virtual machine for a moment exit# (Back on your parent system) # If the synced folders do not work ('Guest Additions required') install vagrant-vbguest # (halt the running machine before) vagrant plugin install vagrant-vbguest # Then reload the VM vagrant reload # To stop the virtual machine vagrant halt # OK. Restart and re-login (later I had an alias for this command) vagrant up --provider virtualbox vagrant ssh# (Install emacs) # (Install git) # (Install apache2) # (Install mysql-server and mysql-client) # Install modes for emacs apt-get install php-elisp mmm-mode # Install PHP7 on Jessie # Found at # https://ansas-meyer.de/programmierung/php/php-7-unter-debian-jessie-installieren/ echo 'deb http://packages.dotdeb.org jessie all' > /etc/apt/sources.list.d/dotdeb.list # (IF THAT'S NOT WORKING CHANGE root's PASSWORT) sudo passwd root Passwort: su root # Make sure apt accepts https transport apt-get install apt-transport-https # Add key for apt curl http://www.dotdeb.org/dotdeb.gpg | apt-key add - ## get package list from sources incl. new set source dotdeb apt-get update # Install PHP ## upgrade to php 7 apt-get install php7.0 # Install composer (required to install Laravel) curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer # Install PHP7-mbstring (required by the Laravel installer) sudo apt-get install php7.0-mbstring # Install the PHP XML extension (contains PHP extension 'dom' which is required # by the Laravel installer) sudo apt-get install php-xml # Install laravel (installiert Laravel im Verzeichnis 'your_project') cd /var/www/ sudo composer create-project laravel/laravel your_project --prefer-dist # Set write permissions to Laravel's 'storage' and 'cache' directories (important) chmod -R a+w /var/www/html/your_project/storage chmod -R a+w /var/www/html/your_project/bootstrap/cache/ # Set apache's document root to /var/www/html/your-project/public in emacs /etc/apache2/sites-enabled/000-default.conf # We are almost done. Restart apache and enjoy your freshly setup # debian8-php7-capable virtual machine. server apache2 restart # Check if everything works by loading apache's default page in your favourite # web browser (firefox, chrome, ie, lynx, ...). lynx http://127.0.0.1:8080
Have fun with your virtual machine(s)!
(~ ̄▽ ̄)~
Enjoy and don't forget to help your friends!