Developers have their own way of working, and I’m no exception. With a half a dozen apps running at any given time to make my code structure, workflow, and deployments as smooth as possible, I depend on simple easy-to-use tools to get things done. However, the one thing that is constantly changing is the local work environment. This is all based on preference, personal tastes, and your job. I build websites on WordPress with Laravel Homestead.
My local development environment for this is Laravel Homestead. Homestead is free and runs in VirtualBox (or VMware), on Vagrant and includes, Ubuntu 16.04, Git, PHP 7.0, HHVM, Nginx, MySQL, MariaDB, Sqlite3, Postgres, Composer, Node (With PM2, Bower, Grunt, and Gulp), Redis, Memcached and Beanstalkd.
To start, let’s install VirtualBox or VMWare AND Vagrant. I prefer VirtualBox because it’s lightweight, comes with Vagrant out of the box, and most importantly, it’s free.
$ cd ~/home/vagrant/Code/wordpress-site
Next, we’re going to clone homestead into our root user directory and initialize Homestead to create our configuration file and define our provider–in my case, VirtualBox.
$ git clone https://github.com/laravel/homestead.git Homestead $ bash init.sh
After you’re set up, we can setup our configuration file and local file structure. I’ll base this on how I work, but generally, how you organize your files are up to you.
Open your Terminal.app and type
homestead edit which will open the homestead.yaml file in your favorite code editor.
--- ip: "192.168.15.15" memory: 2048 cpus: 1 provider: virtualbox authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: ~/Dropbox/Private/Working to: /home/vagrant/Code sites: - map: wordpress-site.dev to: /home/vagrant/Code/wordpress-site databases: - wp_1 variables: - key: APP_ENV value: local # blackfire: # - id: foo # token: bar # client-id: foo # client-token: bar # ports: # - send: 93000 # to: 9300 # - send: 7777 # to: 777 # protocol: udp
I’m not going to go over everything here, just the parts that make Homestead go. They’ve added some bells and whistles like ports, variables and Blackfire support—which makes it easy to test PHP performance—but you can Google those.
From the top:
ipis automatically pulled in from your machine – leave this alone.
memoryis set to 2048 by default.
keysreference your SSH keys. You can learn more about that here.
folderscontains two parts
mapis the relative location on your computer, in my case
~/Dropbox/Private/Working. I like having a good 24/7 backup of working files, hence Dropbox.
torefers to the default vagrant folder location. You can use the default location, I just find it easier and nicer to work out of the folders I want to work out of. Ya know control!
siteshere’s where the fun starts. These are my local WordPress installs.
databasesare the matching databases for each of your sites. Name them whatever you’d like.
portsdon’t need to be touched, but you can read more about those here.
Next thing you’ll want to do is map your new site URL to your
ip in your hosts file so that you can use your URL.
$ sudo vim /etc/hosts
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 192.168.15.15 wordpress-site.dev
Save and you’re good to go.
Now, unlike MAMP (see below), one thing that Homestead doesn’t have is a visual phpMyAdmin interface—everything is command-line. However, here is where I recommend SequelPro for accessing, editing, and maintaining your Homestead databases. Access is super simple by using the configuration below:
Database: (name optional)
From here, you can do anything you can do via ssh and command line with a simple GUI interface.
## Install WordPress
Easy as 1, 2, 3. I’ll do it with command-line, but you can just drag and drop files just the same.
$ cd ~/home/vagrant/Code/wordpress-site $ wp core download
? Boom–you’re ready to setup WordPress. Go to http://wordpress-site.dev (or whatever you’ve named your website) and follow the WordPress setup the way you normally would.
Note: If you’re building static sites, you can just drop files into your root and you’re ready to rock–no 1, 2, 3 needed.
Good for all databases:
memory in the
homestead.yaml files is set to 2048 by default, but I recommend 1024 to have a fast local machine without taking too many resources away from other tasks. On my Macbook Air 2011, I found that 2048 took too much away from other apps and slowed down my computer considerably if I was trying to use Adobe Photoshop or Chrome with ninety tabs side by side. 512 works just fine if you’re only running one or two sites.
Things I Learned Recently
I use Homestead for smaller projects, one-offs, and personal website tasks—it’s still much quicker for me than any other local environment setup.
Recently, however, I had to make a switch to MAMP for a project that was showing issues on my local environment. After all, Vagrant is notorious for being a tad buggy from time to time, so it made sense that the issue was caused locally. Despite resetting and spinning up a new local the problem persisted. Long story short the issue was in the code and not my local working environment, but by that time I’d made the switch to MAMP to ensure my local was the same as my coworkers.
Though I still swear by Homestead for simplicity and ease of use, I did notice a few things with MAMP to my surprise. MAMP v 4.0 upgrade was clean and easy to use. Most importantly, however, the CPU and memory load on my computer was almost half of what it was with Homestead running on Virtualbox. As a result, the little fans on my Macbook Air haven’t spun up once since I moved over to MAMP. I have a feeling that a more powerful computer might not have the same issues, but it was an interesting find considering my sordid past with MAMP 2.x.
My colleagues tend to recommend MAMP Pro v 4.0 as a solid local work environment. Having played with it a little recently, I agree that it’s worth checking out. It is a paid program, and a solid platform with easy-to-use GUI features and easy to maintain databases. It provides everything you need to keep frameworks up to date and running smoothly.
Some friends of mine use Wamp Server, which is something akin to MAMP’s free option. Not as robust certainly, but it gets the job done.
ScotchBox is more or less like Homestead. It runs on Vagrant, and VirtualBox, but limits you to only one virtual machine or WordPress install at a time (unless you want to get into configuring Ubuntu). That doesn’t work for me, since I work on multiple web projects at once and often have to spin up a new one quickly. The actual setup and configuration is a bit more complicated than is necessary, so it requires some additional effort. If you’re into trying new things, it’s worth checking out, but after my own exploration, I determined it’s just not for me.
I’ve even known a dev or two to use services like DigitalOcean to spin up a quick WordPress install and go to town. This isn’t technically a local install as you’re running off of their servers, but it’s private and available anywhere from any computer with the right credentials. The downside to DigitalOcean can be its intense learning curve if you’re not familiar with backend server setups. These self-maintained droplets can quickly fly off the shelf if permissions get altered, or if security precautions aren’t properly executed.
If you’re looking for a local dev environment that, after setup, is super quick to spin up and maintain, my vote is Homestead. What’s your favorite local setup?
3 thoughts on “My Local: Getting Started with Laravel Homestead”
I’ve been using AMPPS. I wanted something free that was cross-platform (MacOs, Windows, or UNIX/Linux). I like the ability to easily switch php versions, use phpMyAdmin & SQLiteManager and use other script languages such as PERL, Python & Ruby. The Softalicious installer also enables 1-click installs for WordPress.
sometimes after the program release, when i use the laravel in the engine-x webserver its not a compatible.. i not have skill for that.
I mostly use VVV since I do a heavy mix of WP Core, client, and personal dev work. I started trying out Pressmatic after it became Flywheel Local and have been really impressed so far.