Installing Vagrant

In this series, I’ll demonstrate some of the web development tools I use. Today we’ll cover Vagrant — a virtual environment management tool.

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.

If you are a developer, Vagrant will isolate dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of the tools you are used to working with (editors, browsers, debuggers, etc.). Once you or someone else creates a single Vagrantfile, you just need to vagrant up and everything is installed and configured for you to work. Other members of your team create their development environments from the same configuration, so whether you are working on Linux, Mac OS X, or Windows, all your team members are running code in the same environment, against the same dependencies, all configured the same way. Say goodbye to “works on my machine” bugs.

 

Let’s get into how to setup Vagrant by HashiCorp:

  1. First, make sure you have your virtualization software installed. For this example, we’re running Oracle’s VirtualBox as it’s an excellent and easy to use open source option. See my VirtualBox Installation Guide here.
  2. Find the appropriate package for your system and download it.
  3. Run the installer for your system. The installer will automatically add vagrant to your system path so that it is available in terminals.
  4. Verify that it is installed by running the command vagrant from the command line – it should run without error, and simply output the options available. If you receive an error, please try logging out and logging back into your system (this is particularly necessary sometimes for Windows).

That’s it, you’re all set. Now go ahead and take a look at my Introduction to ScotchBox which is a great web development option, which uses a vagrantbox.

 

Footnote: It’s also worth mentioning that recently Docker has gained a lot of attention and for some web developers its a great option. I’ve only looked into it a bit, and will probably create a series using that tool later this year.

 

Version Disclosure: This document was written while the current version of vagrant is 2.2.4 and virtualbox is 6.0.4 – different versions might be slightly different.

Installing Virtual Box

In this series, I’ll demonstrate some of the web development tools I use. Today we’ll cover VirtualBox — an Open Source Virtualization product for your local machine.

Oracle VM VirtualBox (formerly Sun VirtualBox, Sun xVM VirtualBox, and Innotek VirtualBox) is a free and open-source hosted hypervisor for x86 computers and is under development by Oracle Corporation. VirtualBox may be installed on a number of host operating systems, including Linux, macOS, Windows, Solaris, and OpenSolaris. There are also ports to FreeBSD and Genode.  It supports the creation and management of guest virtual machines running versions and derivations of Windows, Linux, BSD, OS/2, Solaris, Haiku, OSx86 and others, and limited virtualization of macOS guests on Apple hardware.

In general, our application for web development is to emulate our production web server environment which is often a LAMP or WIMP stack. For our examples in this series, we’re going to look at the most popular, the LAMP stack (Linux, Apache, MySQL, and PHP).

 

The installation and setup of VirtualBox are very simple:

  1. Verify that you have a supported host operating system – that is, the desktop operating system that you’re on right now. https://www.virtualbox.org/manual/UserManual.html#hostossupport
  2. Navigate to https://www.virtualbox.org/wiki/Downloads and download the version that is right for your host operating system.
  3. Host OS Specific Steps:
    1. For Windows installations double-click on the downloaded executable file. Select either all or partial component installation – for web development make sure the network components are also selected — USB and Python support is optional
    2. For Mac installations double-click on the downloaded dmg file. And follow the prompts.
    3. For Linux – see this link: https://www.virtualbox.org/manual/UserManual.html#install-linux-host

For most people that is just about it, you’re installed and all set with VirtualBox. The next step for most web developers will be to install Vagrant, which makes managing virtual images super easy!

 

In some situations, your host machines BIOS settings need to be changed because your manufacturer has turned off the required settings by default. You don’t need to worry about this unless you get an error when trying to use a virtual machine. You might get a message like:

  • VT-x/AMD-V hardware acceleration is not available on your system
  • This host supports Intel VT-x, but Intel VT-x is disabled
  • The processor on this computer is not compatible with Hyper-V

This issue is can occur regardless of the virtualization technology you use (VMWare, XenServer, Hyper-V, etc).

How to configure Intel-VT or AMD-V:

  1. Reboot the computer and open the system’s BIOS menu. Depending on the manufacturer, this is done by pressing the delete key, the F1 key or the F2 key.
  2. Open the Processor submenu (also may be listed under CPI, Chipset, or Configuration)
  3. Enable Virtualization, Intel-VT, or AMD-V. You may also see Virtualization Extensions,  Vanderpool, Intel VTd, AMD IOMMU, if the options are available.
  4. Select Save & Exit.

You should be now all set, reboot into your host operating system and try again.

Version Disclosure: This document was written while the current version of virtual box is 6.0.4 – different versions might be slightly different.

 

Scotch Box – Dead simple Web Development

In this series, I’ll demonstrate some of the web development tools I use. Today we’ll cover Scotch Box — a virtual development environment for your local machine.

Many people begin development by working directly on live, production web servers. Sometimes they’ll work in a sub-directory or a different URL. However, there are several drawbacks to this approach.

  1. Performance: Every update of your files requires them to be sent over the internet, and equally your tests also need to come back over the internet. While each of these is probably only an extra second of latency for each file, it can quickly add up over the lifetime of development.
  2. Security: Let’s face it, development code isn’t the most secure out of the gate. I recently was developing a custom framework and in the process of writing the code for the display of images, introduced a bug which would dump any file to the browser, even php code or environment variables.
  3. Debugging: Debugging tools such as Xdebug shouldn’t be installed on production servers as it can accidentally expose sensitive data.
  4. Connectivity: You must be connected to the internet to develop, so internet connection, no development.

So for most of my projects, I develop first on my laptop. But instead of installing a full LAMP stack on my desktop (where I’ve got a database and web server running full time in the background), I use a Virtual Machine through Oracles Free VirtualBox Hypervisor.  And instead of having one virtual machine host multiple projects, which might have different development needs (specific PHP versions, databases, etc), I spin up a new virtual instance for each project. This is made super easy through a tool called Vagrant. As they say:

Development Environments Made Easy

This post assumed you already have both Oracles VirtualBox and Vagrant installed on your local machine.

My favorite development stack is Scotch Box — perhaps this is because I love scotch, but more likely because it’s (in their own words): THE PERFECT AND DEAD SIMPLE LAMP/LEMP STACK FOR LOCAL DEVELOPMENT

It’s three simple command line entries and you get access to:

  • Ubuntu 16.04.2 LTS (Xenial Xerus) OS
  • Apache Web Server
  • PHP v7.0
  • Databases: MySql, PostgresSQL, MongoDB, SQLite
  • NoSQL/Cache: MemCashed, Redis
  • Local Email Testing: MailHog
  • Python v2.7
  • Node.js
  • Go
  • Ruby
  • Vim
  • Git
  • Beanstalkd
  • And much more.

Within PHP it includes tools like Composer, PHPUnit, WP-CLI. Also since this is designed for development PHP Errors are turned on by default. It works with most frameworks outside of the box, with the exception of Laravel which needs just a bit of tweaking. All major CMS are supposed like WordPress, Drupal and Joomla.

And if you want access to more updated versions, such as PHP 7.2 or Ubuntu 17.10.x, you can pay just $15 for their pro version which comes with so much more!

So how to do install it?

  • From the command line, go to your desired root directory, such as Documents
  • git clone https://github.com/scotchio/scotchbox myproject
  • cd myproject
  • vagrant up                    (learn how to install vagrant)

You can replace “my-project” with whatever you want to name this specific development project.

After you run “vagrant up” it will take several minutes to download the code from the internet. Then you’ll be all set. You can browse http://192.168.33.10/

For shell access SSH to 127.0.0.1:2222 with the username of vagrant, and password of vagrant.

You’re all set.

Configure Plesk as OpenVPN Server with Windows 10 as Client

Plesk is a powerful web server management tool. Among the included features is an OpenVPN Server, so when you’re working remotely you can connect directly to your server remotely. This can be very helpful if you’re a developer who works remotely from insecure locations like a Starbucks Coffeeshop or other remote location. The instructions provided by Plesk are not really clear on this topic, nor at least not fully up-to-date and the included client download package is a legacy version of the OpenVPN client.

TLDR (in summary) if you’re the only person who manages both the Plesk Server and uploads files, and you want a really secure setup, read on. Otherwise, you can just stop here, because this is NOT going to give you any real-world benefits.

As of the writing of this post, Plesk only supports a single remote host at a given time. And if you configure multiple devices they all use the same encryption key. Additionally, you’re limited to traffic intended for the Plesk server directly, and it does not route traffic more broadly within either the server LAN or to the WAN. This results in a network configuration known as split-tunneling. Meaning only traffic for the remote server is sent over the tunnel and all other traffic still goes out your internet connection. So the net result is a secure connection just to your Plesk server, but nothing else. If you’re already using FTPS and SSH, then this really provides NO benefit for you. There are feature requests to extend the Virtual Private Network features of Plesk, but as of this writing, it has not been implemented yet.

Also, because technology changes quickly, please note the following – this documentation is based on the following software versions:

  • Plesk Onyx Version 17.8.11 Update #38
  • OpenVPN Windows Client 2.5.0.136 (link)
  • Windows 10 Enterprise, Version 10.0.17134.523

Let’s get started on how to configure the OpenVPN Server.

  1. Start by installing the Plesk Extension: Virtual Private Networking
  2. Then open the Extensions shortcut via the navigation pane > Virtual Private Networking.
  3. On the Preferences page that opens, specify the following parameters:
    1. Remote Address: Leave this blank as you’re intending to remotely connect TO the Plesk server.
    2. Remote UDP port: You can leave this field blank if you have not specified the remote address above.
    3. Local UDP port, your server will listen for incoming VPN traffic on this local UDP port. The default port is 1194.
    4. Local peer address and Remote peer address: Usually leave the default. This needs to be a separate address space from either your existing WAN or LAN of the server, as well as ideally not overlapping with the local IP address that you’ll be connecting from as well.
    5. Click OK.
  4. The Plesk VPN component is initially disabled. To use the VPN functionality, enable the component by clicking the “Switch On” button.
  5. Click on “For a Windows Client” button to download the package. BUT DO NOT use the OpenVPN client included.
  6. Extract the package to any location.
  7. Open the extracted files and copy the vpn-key to you c: directory
  8. Then open the openvpn.conf file using any text editor, such as Notepad, or my preferred editor, Notepad++
    1. Change the line: secret system/vpn-key
      To read: secret c://vpn-key
    2. Save the file as openvpn.ovpn
  9. Then move the file from its current location to c:\ — in Windows 10 usually the security permissions will prohibit you from directly saving-as to the c: directory.
  10. From the start menu, run OpenVPN Client — not the OpenVPN GUI.
  11. Right-click on the sys-tray icon and select Import > From File. Point it to your c:\openvpn.ovpn file
  12. In a few seconds (but not immediately), it will show the VPN in the listing when you right-click on the OpenVPN Client sys-tray icon. Click on the Plesk Server, then select Connect.

You should be all set, and you can test your connection by trying to ping your server from the command line to the IP address selected above, typically 172.16.0.1 — if this resolves then your VPN is setup properly. You can also go to a http://www.WhatIsMyIP.com and verify that all other web traffic is routing through your local internet connection and not your server.

You’re now configured to access your server over the VPN tunnel.

 

Now, you’ll need to access your Plesk server using that IP address, which can itself be problematic. Sure FTP/FTPS to 172.16.0.1 will work just fine, but if you try to navigate to the Plesk Web Console, at https://172.16.0.1 you’ll get a certificate error because the certificate is signed for the FQDN (Fully Qualified Domain Name) such as Plesk.example.com

You could modify you hosts file, but then you’ll have all sorts of problems connecting if your not connected via the VPN tunnel.

 

So this begs the question, why even bother with this? The only reason I can think of is if you’re using Plesk as a GUI management for your web servers, and you want to really keep the sever closed off. With the VPN setup, you can close down FTP/FTPS ports, as well as the Plesk ports like 8443 to the outside world. It creates a much more secure setup and is a good ideal if you’re the only one who is going to manage this server. But otherwise, if other people need to use FTP or the console, then there is no reason to implement this.

 

 

Install Composer on a Dreamhost VPS Instance

I have started to experiment with web development tools again and quickly ran into frameworks and tools which utilize Composer and there is mixed information on how to use composer with Dreamhost in a VPS environment, so I’m creating a blog post here. I’ll also add how to provision additional specific frameworks as we explore them as well.

  1. Through the Dreamhost console, verify which version of PHP you’re running.
    1. Domains > Manage Domain
    2. Look for the domain and you’ll see the PHP version, such as 5.6
  2. SSH into your VPS server
  3. The Phar extension for PHP must be enabled, do this by:
    1. verify you’re in the correct directory by typing “pwd”
    2. it should respond that you’re at /home/{{username}}
    3. Create a new directory “mkdir .php” – if you receive an error that it already exists, that is okay
    4. Move into that directory “cd .php”
    5. Now you’ll create a directory with the same name as your PHP version, in this case I’ll name it “mkdir 5.6”
    6. Move into that directory “cd 5.6”
    7. Now we’ll create (or edit) a file named phprc by typing “nano phprc”
    8. This will now have a full screen text editor, copy and paste the following into the editor:
      extension = phar.so 
      suhosin.executor.include.whitelist = phar
    9. To save changes you’ll press control-x, then Y, then {{enter}}
    10. You’ll be back at the command prompt.
    11. Test it by typing: “php -m | grep Phar” – the results should simply say “Phar”. If it just returns you to the command prompt without anything, then double-check your steps above.
  4. Enter the following to return back to your home directory: “cd ~”
  5. Now you’ll enter the website you want to use composer with, for example for my website http://www.sample.com you’ll enter “cd http://www.sample.com”
  6. Now you can install Composer here, or if necessary move into a subdirectory, if necessary.
  7. To install composer, simply type: “curl -sS https://getcomposer.org/installer | php”

Now to use it, whenever you are referred to use Composer, simply go into this directory and you’ll need to use the command “php composer.phar” followed by whatever you’ve been prompted to use composer for, such as:

  • You’re instructed to use:
    composer require twbs/bootstrap
  • What you’ll type is:
    php composer.phar require twbs/bootstrap

     

This is based on the assumption that you’ll only use Composer for one or two things, but if you’re a developer or will be using composer a lot of times, you’ll want to checkout how to make it available globally: https://help.dreamhost.com/hc/en-us/articles/214899037-Installing-Composer-overview

Note that about 90% of the information for this was based on that dreamhost.com hosted article, however how some finer elements were missing, and certain assumptions about using linux were made that not everyone will necessarily know. Additionally, the part about how to convert the composer call that most websites reference into the php composer.phar part is also missing.

 

Enjoy!

 

Powered by WordPress.com.

Up ↑