Stop running artisan on stale code
I had written an import script for one of my sites on Forge. Running it locally, tweaking, deploying, running it in production - over and over. It just wouldn’t pick up my changes. I was rewriting the script, adding debug output, questioning my sanity.
The tricky part was that I was working against two environments - local dev and production. They could behave differently for all kinds of legitimate reasons. So when prod didn’t match what I saw locally, I kept blaming the code instead of stepping back and asking why.
Most of my sites use regular deploys where none of this matters. You SSH in, deploy, and your shell is already in the
right place. But this site had zero-downtime deployment enabled. Each deploy creates a new release directory and moves
the current symlink. My terminal was still sitting in the old release. Every artisan command I ran was hitting stale
code.
Once I realized what was going on, I felt pretty stupid. But also - this is exactly the kind of thing muscle memory hides from you. You’ve been doing it the same way for years and it’s never been a problem. Until it is.
The fix
I’ve always had alias art="php artisan" on my servers. So I replaced that alias with a function that does the same
thing but always runs from the live release:
# Runs a command from a site's live release, wherever in the site
# you stand. A shell left in an old release otherwise runs old code
# against the live database. Outside a site it runs where you are.
_in_current() {
local here dir live
here=$(pwd -P 2>/dev/null) || here=$PWD
dir=$here
while [ "$dir" != "/" ] && [ ! -L "$dir/current" ]; do dir=$(dirname "$dir"); done
if [ ! -L "$dir/current" ]; then
"$@"
return
fi
live=$(readlink -f "$dir/current")
case "$here/" in
"$live"/*) ;;
"$dir"/releases/*) echo "Old release: running in the live one, but this shell is still in the old one (cd $dir/current)" >&2 ;;
esac
(cd "$live" && "$@")
}
art() { _in_current "${PHP:-php}" artisan "$@"; }
It walks up from where you stand until it finds the current symlink, then runs the command in the release that symlink
points to. If a deploy has happened since you cd’d in, you get the new code anyway, plus a line telling you your shell
got left behind. Outside a site it’s just php artisan where you are.
It’s two functions so you can wrap any other command that lives in the project the same way. And if a site needs another
PHP version than the server default: PHP=php8.4 art migrate.
Drop it in your .bashrc or .zshrc on the server and you’re good. Since I was already using art as an alias,
nothing changed about how I work. Same command, same muscle memory - it just protects me now.
The alternative is remembering to cd out and back into current after every deploy. That’s never going to happen.
I’ll forget, and three months from now I’ll be staring at logs again wondering why nothing makes sense. This way the
safety net is built into the habit I already have.
Hope it saves someone else the time I lost banging my head against the wall.
Update, November 2026: the first version of this function stopped and told you to cd instead, so you had to run
the command again. Now it just runs the right code and tells you. If you copied the old one, swap it for the one above.