DEV Community

Dênis Mendes
Dênis Mendes

Posted on

Running the command Heroku local with PHP 8, nginx and php-fpm on macOS

Hi there!

I was trying to get the heroku local command running in my macOS Monterey but I stumbled in some issues. Then I'd like to share with you my process to get that working.

First things first, check if you have your require-dev section into your composer with that library:

    "require-dev": {
        "heroku/heroku-buildpack-php" : "*",
Enter fullscreen mode Exit fullscreen mode

After that, add this tap to homebrew:

brew tap shivammathur/php

Right after, run these commands:

brew install shivammathur/php/php@8.0

brew link --overwrite --force shivammathur/php/php@8.0

Sometimes you need to restart your terminal to see php running and available to use. So if you run: php -v you're going to see current php version installed on macOS.

Now try to run heroku local and whether it works we don't need to change anything but if doesn't and you're seeing messages telling you something like these:

  • php command not found
  • php-fpm command not found

So I can help you, it happens because you need to add right folder with binaries from php8, what I did was:

echo 'export PATH="/usr/local/Cellar/php@8.0/8.0.14/sbin:$PATH"' >> ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Restart you terminal after that command and now you can type for instance: php-fpm and it's there!

Now heroku local should work!

Top comments (1)

Collapse
 
naizhao profile image
Sam Ng

If you are using macOS, there's a new option you can try: servbay.dev, a great alternative to MAMP. It includes all versions of PHP, MariaDB, and PostgreSQL, as well as redis and memcached. You can run multiple versions of PHP instances at the same time and it's easy to switch between them for debugging/testing. With just a few clicks, you can enjoy your PHP development environment.