Multiple projects, and multiple PHP versions, I know it is stressful, and if you are using a Mac, and installed PHP with the help of Brew it's it adds to it.

I created this simple solution for PHP version management. I call it p



import os
import inquirer
from subprocess import check_output

def main():
    php_versions = (check_output("brew list | grep php", shell=True)).decode()

    questions = [
            message="Which PHP version do you want to use?",

    answers = inquirer.prompt(questions)

    current_php_version_major = float(check_output("php -r 'echo PHP_MAJOR_VERSION;'", shell=True).decode())
    current_php_version_minor = float(check_output("php -r 'echo PHP_MINOR_VERSION;'", shell=True).decode())

    current_php_version = current_php_version_major + (current_php_version_minor/10)

    check_output("brew unlink php@" + str(current_php_version), shell=True)
    check_output("brew link " + answers["php_version"], shell=True)

    print("PHP version changed to " + check_output("php -r 'echo PHP_VERSION;'", shell=True).decode())

if __name__ == "__main__": main()

All you have to do is copy the code above and paste it into your .local/bin. You can name the file whatever you want but I recommend using p.


> p

[?] Which PHP version do you want to use?: php
 > php
   [email protected]