Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uruloke's avatar

Valet, Custom driver with other PHP version

Hello, I just got started on Valet and I wanted to setup a custom driver where it uses PHP5.6 instead of PHP7.0. I looked through the docs, but couldn't find anything about shifting PHP version, is this possible to do as a custom driver? And is it even possible at all to shift the PHP version of Valet?

0 likes
14 replies
robgeorgeuk's avatar

I'd really like to know about this as well. It feels like it should be possible if you have PHP7 and PHP5.6 installed and add an entry into ~.valet/Caddyfile that uses the PHP5.6 version fastcgi or something.

Anyone else have any ideas?

willvincent's avatar

it already supports 5.5.9+

It'll use whatever version you have installed.. so if you want 5.6, uninstall php7 and install php56 with homebrew.

uruloke's avatar

@willvincent, that is not what I desire. I have some drivers which I wanna run with php7. 0 and some with php5. 6 at the same time.

willvincent's avatar

That doesn't appear to be doable, at least not without changing some of the valet classes, notably PhpFpm and Brew classes. There isn't any mechanism in place to dynamically change between different php versions -- other than unlinking a given brew version and linking a different one.

That said though.. there's nothing stopping you from having php56 and php70 both installed via homebrew, and then doing this:

# Change from php7 to php5.6
brew unlink php70 && brew link php56 && valet restart

# Change from php5.6 to php7
brew unlink php56 && brew link php70 && valet restart

You would only have one version active at a time, but could switch between them relatively painlessly. You could even make aliases for those so you could just type something like php7to5 to switch from 7 to 5 and restart valet..

Do you really need to actively run and use different drivers and different versions of php simultaneously?

brew link/unlink just adds or removes the symlinks, so it doesn't have to download every time or anything like that, so.. changing between versions would be pretty painless really.

1 like
robgeorgeuk's avatar

I don't mind not running two versions simultaneously but I am actually trying to run PHP5.3 for some ancient projects so perhaps I better look for another way :-(

uruloke's avatar

Thanks for an solution. Was looking for an easy solution, without having to run a command each time.

I will try looking into the PhpFPM and Brew file.

willvincent's avatar

@robgeorgeuk valet doesn't support php5.3, so.. yeah you'll need another option for that. Best bet probably would be to use a virtual machine.

robgeorgeuk's avatar
Level 14

Ok I think I've got this working so here's how I did it. Most of the credit goes to to Jani Tarvainen for this post: http://share.ez.no/blogs/ez/how-to-run-both-php-5.6-and-php-7.0-with-homebrew-on-os-x-with-php-fpm

My examples are for PHP 5.3 so I'm fairly sure it would work for 5.4, 5.5 and 5.6. Just change 53 to 56 or whatever version you are using.

I'm assuming you have Valet and PHP 7.0 installed and working ok.

Install another version of PHP

PHP 5.3 will be installed but PHP 7.0 remains the default.

brew unlink php70
brew install php53
brew unlink php53
brew link php70

Configure an additional PHP-FPM on a different port to listen for PHP5.3 requests

Edit File

/usr/local/etc/php/5.3/php-fpm.conf

Change

listen = 127.0.0.1:9000

to

listen = 127.0.0.1:9053

Start both PHP-FPMs on startup

cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
cp /usr/local/opt/php53/homebrew.mxcl.php53.plist ~/Library/LaunchAgents/

Start both PHP-FPMs now

Only required this time, they will start automatically on next boot up.

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php53.plist

Configure Caddy

Caddy is the underlying web server that Valet uses. We can make it use site specific config that only applies to the PHP5.3 site. Other sites will continue to be served by PHP7. You will need to tweak this file to suit your needs so check the Caddy docs. https://caddyserver.com/docs

Create a file called

~/.valet/Caddy/MyOldProject.conf

Add the below

oldproject.dev:80 {

    root /Users/rob/Code/oldproject
    fastcgi / 127.0.0.1:9053 php

    rewrite {
        to {path} {path}/ /index.php?{query}
    }

    log /Users/rob/.valet/Log/access.log {
        rotate {
            size 10
            age 3
            keep 1
        }
    }

    errors {
        log /Users/rob/.valet/Log/error.log {
            size 10
            age 3
            keep 1
         }
    }
}

Restart Valet and test

valet restart

Note If you edit the PHP5.3 ini file (/usr/local/etc/php/5.3/php.ini) then I think you will need to restart PHP with:

brew services restart php53
3 likes
SingularGroup's avatar

Great article. Tnx. For those who use Valet 2.0. There is Nginx instead of Caddy. So you can edit ~.valet/Nginx/example.dev file and find line fastcgi_pass ..., change it with: fastcgi_pass 127.0.0.1:9053

1 like
marvanni's avatar

Did you got this working in nginx?

It seems that valet is ignoring the nginx config files in ~.valet/Nginx/

I only got the default php version working

pilat's avatar

@willvincent I like your idea of switching between installed phps, but it doesn't work for some reason…

Here's my aliases:

# PHP versions
alias use56="brew unlink [email protected] && brew unlink php && brew link --force [email protected] && valet restart"
alias use70="brew unlink [email protected] && brew unlink php && brew link --force [email protected] && valet restart"
alias use72="brew unlink [email protected] && brew unlink [email protected] && brew link php && valet restart"

And here's the result of using one of them:

✗ use56
Unlinking /usr/local/Cellar/[email protected]/7.0.30_1... 0 symlinks removed
Unlinking /usr/local/Cellar/php/7.2.7... 0 symlinks removed
Warning: [email protected] is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshrc

In Brew.php line 182:

  Unable to determine linked PHP.


restart

Could you help me to get this working?

Please or to participate in this conversation.