Create Vagrant Box for Laravel (Using Nginx)

Set Up Ubuntu Vagrant Box

Find out what boxes are available vagrant box list Add the new newest Ubuntu box (currently xenial/16.04 LTS). vagrant box add envimation/ubuntu-xenial-docker Create a directory for the box and init the ubuntu box. cd ~/ mkdir testlar cd testlar vagrant init envimation/ubuntu-xenial-docker By default, Vagrant syncs the folder with the Vagrantfile in the host machine with the /vagrant folder in the virtual machine. Create a file called in the same folder as the Vagrant file and add the following.

#!/usr/bin/env bash

apt-get update

Include the file in the Vagrantfile.

Vagrant.configure("2") do |config| = "ubuntu/xenial64"
  config.vm.provision :shell, path: ""

It is a good idea to allocate more memory to the virtual box. I got an error when trying to set up the Laravel project. Add this to the Vagrantfile.

  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 = "2000"

Allow port forwarding to view web pages using the server we just set up. :forwarded_port, guest: 80, host: 4567 Also, allow the guest machine to be accessed by a static IP address. “private_network”, ip: “” Now, you can visit in your browser. If you set up Nginx, then you can view your Laravel site via that IP. If you add the following line to your host machine’s host file, you can visit your Laravel site by visiting testlar.test. cd ~/etc sudo vi hosts testlar.test Create a folder called sites in the root folder (~/testlar). Add the following to the Vagrantfile to change the permissions of folders in the VM, so that www-data can modify them.

  config.vm.synced_folder "./sites", "/var/www",
      :owner => 'vagrant',
      :group => 'www-data',
      :mount_options => ['dmode=775', 'fmode=775']

Start up vagrant or reload it. vagrant up vagrant reload –provision

Install Nginx

Enter the vagrant machine and install nginx. cd ~/testlar && vagrant ssh sudo apt-get install nginx

Updating PHP

sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php7.2 sudo apt-get install php7.2-cli php7.2-fpm php7.2-curl php7.2-gd php7.2-mysql php7.2-mbstring zip unzip php7.2-xml If you don’t install php7.2-mbstring, you will get an error when install Laravel. Also, Nginx depends on some of the libraries above.

Install MySQL

sudo apt-get install mysql-server php7.2-mysql (The php7.2-mysql package is possibly part of the ppa:ondrej/php repo because it could not be found before enabling that repo.) Now, we can try connecting to MySQL using SequelPRO. Here is the location of the vagrant box’s SSH private key for SequelPRO if the username/password vagrant/vagrant doesn’t work: /Users/davidsr/testlar/.vagrant/machines/default/virtualbox/private_key To connect to MySQL the first time, use the following command. sudo mysql When the MySQL prompt appears, run the following command to check to see if the root user is using the auth_socket plugin. If it is, we will change it to a password. SELECT user,authentication_string,plugin,host FROM mysql.user; ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’; FLUSH PRIVILEGES; Now, I can use the following info to connect to mysql with SequelPRO. MySQL Host: Username: root Password: password Port: 3306 SSH Host: SSH User: vagrant SSH Key: /Users/davidsr/testlar/.vagrant/machines/default/virtualbox/private_key

Install Composer

Now, I am going to start following this tutorial: In Vagrant, run the two commands sudo apt-get update sudo apt-get upgrade curl -sS | php sudo mv composer.phar /usr/local/bin/composer To install Laravel, run the following commands. cd /var/www mkdir testlar.test cd testlar.test

Install Laravel

composer create-project laravel/laravel testlar –prefer-dist It will take a couple seconds for this command to take affect (no loading)

Also install doctrine/dbal to be able to change table columns.

composer require doctrine/dbal

Configure Nginx

Replace the contents of the file named default with the code below. cd /etc/nginx/sites-available sudo vi default

server {
        listen 80;
        listen [::]:80;
        root /var/www/testlar/public;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name testlar.test;

        location / {
                try_files $uri $uri/ /index.php?$query_string;

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

        location ~ /\.ht {
            deny all;

Make sure nginx setup is okay. sudo nginx -t sudo service nginx restart If ubuntu is using Apache instead of nginx, you can switch to nginx by disabling apache. sudo update-rc.d apache2 disable Now, you should be able to visit dox.test. Change the permissions for the storage directory. You have to do this on your host machine (not the virtual machine). Open a new tab in your terminal or exit vagrant and go to the location of this vagrant installation. exit cd ~/testlar sudo chmod -R 777 html/test/storage Now, visit the site. http://localhost:4568/ That’s it! Hopefully it will work! I noticed Firefox cached the Nginx welcome page. Try a different browser if you keep seeing that message. Set Up Node and NPM Set Up VueJS If you get the error “SyntaxError: Invalid or unexpected token” after compiling the JS, it may be an error with Nginx. Bullets would be injected at the end of my JavaScript file; the JavaScript file would just end for no reason; and the strange this is that it would work if I renamed the file, but if I made any changes, the error would happen, again. I updated Nginx, and it started working. cd /etc/nginx sudo vi nginx.conf Change sendfile on; to sendfile off;


I’ve encountered countless errors when working with Laravel. Here are some references for your benefit if you run into any of the errors that I did. I got a 500 internal server error. If you get a 500 error, the php versions might not be matching up. Particularly important is to change any references to php 7.0 to php 7.2. Laravel 5.6 only works with PHP versions greater than 7.1.3. You can also echo out PHP details by editing the index.php file in the public folder. cd /vagrant/html/test/public sudo vi index.php Add the following the very top of the file. phpinfo(); die(); If the version is 7.0, you need to update your Nginx blocks. cd /etc/nginx/sites-available sudo vi default Old: fastcgi_pass unix:/run/php/php7.0-fpm.sock; New: fastcgi_pass unix:/run/php/php7.2-fpm.sock; My Laravel installation would timeout. Running the following command fixed it. export COMPOSER_PROCESS_TIMEOUT=600 Upgrade to php 7.2 If routes aren’t working and return a 404, change try_files $uri $uri/ =404; to try_files $uri $uri/ /index.php;       I can visit testlar.test, but it goes to the default NGINX page (/usr/share/nginx/html). I had to change the server_name from localhost to server_name testlar.test. Here is the simple configuration for my Vagrantfile.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "ubuntu/trusty64"

  config.vm.provision :shell, path: "" :forwarded_port, guest: 8080, host: 80 "private_network", ip: ""

  config.vm.provider "virtualbox" do |vb|

    vb.memory = "2000"


I was then able to visit http://testlar.test/ in the browser.

Building a Web App with ReactJS and Laravel

I recently had the opportunity to build a web app using ReactJS and the PHP framework called Laravel. I was the front and back end web developer, the development operations manager, and the web designer. Somehow, it turned out okay. Note that this is not a tutorial, but that doesn’t mean you won’t be able to glean any useful information from it.

Install All the Packages

Development operations had me pulling my hair out, but the web development side of things (front end and back end) was more manageable. When I installed something, it would work… for the most part. Here’s a list of all the React and Laravel packages I had to install.

  • A Laravel package to manage images
  • A React package (which was broken) for managing pagination
  • A React package for letting users share their entries on social media.
  • A React package for using Stripe.
  • A React package (which was also broken) that created a popup to let users choose an image from facebook.
  • A vanilla JS package for managing cookies.

I’m sure there were many more packages, but those are the ones that come to mind.

The Confusions of React Router V4

Besides taking a few React courses on, I had never used React for a professional web application. I didn’t quite understand how to use it, but I was able to use it to build the web application. Getting it set up was very confusing though. React had just recently switched over to React Router V4. I never really understood what React Router V4 actually was the whole time I was building the app,. Basically, React Router V4 is a library for conditionally adding and removing (not just hiding) React components based on the URL/path of the site. Don’t try to equate React Router V4 with any routes that you normally use. It won’t work. I was equating React Router with Laravel routes, and I thought of  components as Laravel pages. That was definitely not the right way to think about them. They are a lot different. You can wrap a little button component in a route and only display that button on a page with the URL You can put that button (<Route path=”/page-with-extra-button”><MyButton /></Route>) anywhere you want. It can be in a menu, in the footer, in a random component in the middle of another component. It can appear anywhere. You definitely can’t do that with a Laravel route. It is a very strange way of thinking about routes.

The Laravel Back End

There’s not too much to say about the back-end. I set up a couple models in Laravel and their corresponding database tables. Nothing really blew me away or totally confused me. Routes acted like routes. I still don’t quite understand Models, but I sure took advantage of Controller classes and functions.

For the most part, Laravel just acted as an API for React JS, and it acted as a very good API at that.

Development Operations (Launching the React/Laravel App)

I deployed the development project to the live server using git. I set up the app (the website) on a LEMP Digital Ocean droplet. Installing the Laravel dependencies was a bit of a doozy. I remember one composer package needed PHP 7.2 (gotta stay current, right?), and I had to uninstall the previous PHP version and install the new one. That caused some issues. I also had trouble (errors) setting up the MySQL database. Honestly, each of these errors seemed to be like a brick wall, but with enough troubleshooting, I was able to get through each one. In addition to actually building the app (development), I was also in charge of development operations (setting up the server for the site and deploying it) and web design. That’s usually how it goes in small companies. Since I’m not a designer, I got most of my inspiration from other websites.

A Good Result

There was so much stuff to do, but it turned out pretty good. It’s amazing to see everything working together in unison (and not crashing and burning).  One big issue is that the live site only updates every three hours. I think it’s a JS caching issue that I haven’t been able to figure out, but it may also be a Laravel template issue. It could also be both. EDIT: The issue was indeed a JavaScript caching issue. Each time I pushed the dev server to the live server, I’d have to change the version of the JavaScript file.

Because of time constraints, I had to really, really rely heavily on React and Laravel to work in development, and they both performed wonderfully. Would I use React and Laravel to build another web application? The answer is a definite yes.

If you want to read more about my experience with React, check out my article named My Biggest Takeaways from Using React JS.