Author Archives: syewell

Zero Downtime Laravel Deploy Script

At Purpose Built, we use Laravel Forge to manage our servers and auto-deploy code to projects. Forge is great, and really simplifies these things.

Forge provides a basic deploy script to do all the things that need to happen to deploy the application, things like:

  • Pull the most recent code
  • Update composer libraries
  • Update JS libraries
  • Compile JS code
  • Run database migrations
  • Restart PHP-FPM

This process usually takes about a minute to run. While this deploy script us running, a user might happen to interact with the application, and it’s hard to say what they are going to see.

Continue reading

Little Free Pibrary

I realized a dream today.

When I was a kid, maybe 8 years old, I would go to the flea market with my parents a couple of times a year.  I had a small allowance at the time and would walk around looking for cool things.  One time I saw a broken VCR for sale for $5.  It was so cool!  I asked my mom if I could buy it to take it apart, and soon I was the happy owner of a broken VCR.

When I got home I couldn’t wait to go at it.  I sat in the garage with a couple screwdrivers and did my best to dis-assemble the whole thing.  I wanted to know how it worked, and what was inside the box.

Continue reading

Environment Variables with Laravel Forge

laravel-four-icon1For our latest Laravel application, we decided to try the Laravel Forge service to configure and manage the staging and production sites for the app. If you haven’t heard about Laravel Forge, check out the free screencast series by Jefferey Way over at Laracasts.

The Forge UI is great, and takes away a ton of the pain of server and application configuration. Following best practices, we use environment variables to manage environment specific settings like the database name and credentials. One of the features Forge provides is the ability to automate deployment from your github / bitbucket repo upon a post to a specific branch.

The problem we were having was that our migrations would not run. The error was:

{"error":{"type":"ErrorException","message":"Undefined index: DB_HOST","file":"\/home\/forge\[ourbasedir]\/laravel\/app\/config\/database.php","line":51}}

In our case, we are using a non-standard repo directory structure where instead of the typical Laravel app directory structure:

---app
|-bootstrap
|-public
|-vendor

we have another layer above:

---docs
|-laravel
| |-app
| |-bootstrap
| |-public
|-html-templates

Upon inspection of the directory on the server, we found the “.env.php” file was in the base directory. The problem with this was that artisan, the application responsible for Laravel migrations, could not see the environment variables, and so the database configuration was wrong. The solution was simply to move .env.php file into our “laravel” directory so that artisan had access to it.

Setting up Vagrant with SSH Forwarding

Thanks to stackoverflow and github, I finally got Vagrant set up so I can ssh into vagrant and pull in my dotfiles from github without futzing with my ssh keys. Here’s the steps:

1) Make sure the ssh key you use for github is registered with your local ssh agent. You can check with ssh-add -L, if it’s not listed add it with ssh-add ~/.ssh/id_rsa. Credit: http://stackoverflow.com/questions/11955525/how-to-use-ssh-agent-forwarding-with-vagrant-ssh

2) Make sure ssh forwarding is enabled in the VM. Include `config.ssh.forward_agent = true` in your Vagrantfile.

3) Test: ssh -T git@github.com. If it’s not working, check out this link for more troubleshooting: https://help.github.com/articles/using-ssh-agent-forwarding

Email addresses as usernames in WordPress Multisite

wordpress-errorIn a recent project I was trying to create new users with just their email addresses in an instance of WordPress Multisite.  To do this, I planned to use the email address as the new user’s username.  But I kept getting this error:

“only lowercase letters (a-z) and numbers are allowed”

In case you run into this problem to, there is a solution: the Network Username Restrictions Override plugin. There’s a setting in the plug to allow email addresses for usernames.  Click that and you should be good to go.

Here’s another way to solve the same problem that overrides the error that pops up if you try to use an email address as a username in WordPress Multisite.  It attaches a custom filter to the the ‘wpmu_validate_user_signup’ hook that unsets the email address error.

On Quitting.

SocialClassChoice“I’m glad you came to talk to me, it’s a relief really”, my coach said.

I was sitting on the couch in the Cornell wrestling coach’s room.

I had walked on to the Cornell wrestling team two years back, a freshman nobody had heard of from California.  I wrestled three years in high school, was team MVP for three years, team captain for two, first in my league for two years, most wins in the high school history, so I figured I could do something like that in college too. Continue reading

Make reversible database migrations

bidirectionalRecently, I added a new feature that significantly changes one of the database tables in my application.  I ran into problems when I created a non-reversible database migration, and realized that other branches I am developing on still require the older database scheme.  In the end I had to end up dropping the DB, deleting the offending migration, rebuilding the DB, and figuring out a smarter way to migrate.  Not fun, and time wasted. Continue reading

Are you living with the most critical person in the world?

Fisheye Scorn - You're in Deep TroubleNo, not your husband / wife… Nope, not mom. Not your brother or sister.  Of course, not your cat.  I’m talking about that stupid a-hole in your head that sees the other side to everything you do.  I recently went through a period about a week-long where everything was annoying, and that voice was loud.  I got upset a lot, was easily offended by others, spent a lot of time counting to 10, recognizing that the outside world had not changed that much, but something was going on in my head. Continue reading

Start somewhere… ANYWHERE!

IMG_1524Ever feel like you want to do something new, but a little voice in your head says “oh… but you can’t”. Maybe you think about it again, and another voice asks “What if you don’t finish?”.  And then another voice pops up and says “they’ll think your dumb for not being good at that already…”

Maybe you want to build a website. Or learn to code. Or learn to dance. Or start a company. Or become a great cook. Whatever.

So instead you stop thinking about that new thing you could be doing because it feels bad. It’s like a tease, it excites you and you become vulnerable to the potential, and then those voices come in and cut you down, leaving you feeling silly and impotent. And the world is worse off for it.  And you are worse off for it.  Continue reading

Viewing your experiences through a PID Controller

PID

Heading into work today I was thinking about how we are the sum of the experiences we’ve had.  Our brains have been trained to recognize patterns in people and events and we use these patterns to “expect” what will happen next. Sometimes things don’t go the way we expected them and this makes us distraught, stressed, or upset.  And then the image of a PID controller popped into my head, as I’m sure it would have in yours. Continue reading