These past few days I have been re-acquainting myself with the “L” in my LAMP stack of development tools. My Linux distribution of choice is Ubuntu because it serves my needs as both a desktop OS that runs all of the open source tools that I use. After a few false starts I managed to get the Laravel framework installed on my desktop Linux/Ubuntu 18.04 PC.
I am using the Laravel Homestead Vagrant box in a multi site environment from a main Vagrant/Homestead install. Just understanding this took me a minute since there seems to be 3 main ways to install and use Laravel as a developer:
1) Directly on a LAMP server, either on your actual workstation or in a traditional client/server network setup.
2) Using a VM setup with Homestead/Vagrant/Virtualbox (all opensource) with one install of Homestead running multi sites.
3) Using a VM setup with Homestead/Vagrant/Virtualbox with Homestead installed on a per project basis.
For my current development needs I am using option 2 as this gives me the ability to run more than one project at at time. The #3 option will it will only allow you to run one server at a time, however, it gives you the ability to package up your site in an independent environment. This is important to create consistent development environments for development teams and archival purposes.
Step 0: Completed a fresh upgrade to Ubuntu 18.04 from 16.04 and installed/updated all necessary components (as of 9/2018):
- Virtualbox 5.2
- Vagrant 2.1.5
- Composer 1.7.2
Step 1: Cloned Homestead into my main Homestead install directory, in my case /home/tracy/Homestead
git clone https://github.com/laravel/homestead.git ~/Homestead
Per Laravel official instructions I tagged my git repo to the latest stable release: v7.17.0
git checkout v7.17.0
Step 2: Run bash script init.sh in the Homestead directory in order to initialize project and create main Homestead.yaml file for configuration.
You should see the message “Homestead initialized!” returned at the command prompt.
Step 3: Configure the Homestead.yaml file.
Since I already had my ssh key generated in the directory specified by default in Homestead.yaml, I didn’t need to change anything or configure anything on my system.
Here is my folder and site setup for my local development configuration, this is just one project but I can easily add more sites by just adding to the sites area of the config file.
- map: ~/Sites
- map: firstapp.test
Add an entry in /etc/hosts for this new app:
sudo vi /etc/hosts
Step 4: Clone a copy of Homestead into the new site dirctory, in this case /home/tracy/Sites/firstapp_app. I did this using composer, but I could have used git again to clone into this directory, not sure if there is a difference between these methods?
composer create-project laravel/laravel firstapp_app --prefer-dist
Step 4: Start Vagrant box, using new configuration;
vagrant up provision
From the browser go to this url: https://firstapp.test You should now see the newly installed Laravel site.
Note: Although the documention for Laravel sites often uses the *.dev or *.app extension, these extensions no longer work since Google and Firefox now require https security for all sites. However, *.test extensions work in Laravel for these sites. If you try to create a site with an *.app extension you will get a security error in the browser and the site will not open.
Next up: add phpmyadmin as a site in my Laravel install.