DEV Community

Renzo Castillo
Renzo Castillo

Posted on

Simple handy bash script to update your PHP versions in cli and fpm with valet Linux

Please consider that this script assumes that you already have php and valet Linux installed.

Just add this to your bash script

load_php() {
    version=$1
    case $version in
        7.4)
            sudo update-alternatives --set php /usr/bin/php7.4
            valet use 7.4
            valet restart
            ;;
        8.1)
            sudo update-alternatives --set php /usr/bin/php8.1
            valet use 8.1
            valet restart
            ;;
        8.2)
            sudo update-alternatives --set php /usr/bin/php8.2
            valet use 8.2
            valet restart
            ;;
        *)
            echo "Invalid PHP version: $version"
            ;;
    esac
}

phpvm() {
    if [ "$1" == "use" ]; then
        shift
        load_php "$1"
    else
        echo "Usage: phpvm use <php_version>"
    fi
}
Enter fullscreen mode Exit fullscreen mode

Now you can do something like phpvm use 7.4 and you will get your php version 7.4 set at your cli and at your php-fpm service.

Credits to Kenmutesh's post

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more