Switch php versions on commandline ubuntu 16.04

前端 未结 16 1236
别那么骄傲
别那么骄傲 2020-11-30 16:53

I have installed php 5.6 and and php 7.1 on my Ubuntu 16.04

I know with Apache as my web server, I can do

a2enmod php5.6 #to enable php5
a2enmod php7.1         


        
16条回答
  •  星月不相逢
    2020-11-30 17:28

    You can create a script to switch from versions: sudo nano switch_php then type this:

    #!/bin/sh
    #!/bin/bash
    echo "Switching to PHP$1..."
    case $1 in
        "7")
            sudo a2dismod php5.6
            sudo a2enmod php7.0
            sudo service apache2 restart
            sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php;;
        "5.6")
            sudo a2dismod php7.0
            sudo a2enmod php5.6
            sudo service apache2 restart
            sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php;;
    esac
    echo "Current version: $( php -v | head -n 1 | cut -c-7 )"
    

    exit and save make it executable: sudo chmod +x switch_php

    To execute the script just type ./switch_php [VERSION_NUMBER] where the parameter is 7 or 5.6

    That's it you can now easily switch form PHP7 to PHP 5.6!

提交回复
热议问题