Switch php versions on commandline ubuntu 16.04

前端 未结 16 1131
别那么骄傲
别那么骄傲 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!

    0 讨论(0)
  • 2020-11-30 17:29

    Type given command in your terminal..

    For disable the selected PHP version...

      • sudo a2dismod php5
      • sudo service apache2 restart
    1. For enable other PHP version....

      • sudo a2enmod php5.6
      • sudo service apache2 restart

    It will upgrade Php version, same thing reverse if you want version downgrade, you can see it by PHP_INFO();

    0 讨论(0)
  • 2020-11-30 17:34

    Switch from PHP 5.6 to PHP 7.2 using:

    sudo a2dismod php5.6 && sudo a2enmod php7.2 && sudo service apache2 restart
    

    Switch from PHP 7.2 to PHP 5.6 using:

    sudo a2dismod php7.2 && sudo a2enmod php5.6 && sudo service apache2 restart
    
    0 讨论(0)
  • 2020-11-30 17:34

    You could use these open source PHP Switch Scripts, which were designed specifically for use in Ubuntu 16.04 LTS.

    https://github.com/rapidwebltd/php-switch-scripts

    There is a setup.sh script which installs all required dependencies for PHP 5.6, 7.0, 7.1 & 7.2. Once this is complete, you can just run one of the following switch scripts to change the PHP CLI and Apache 2 module version.

    ./switch-to-php-5.6.sh
    ./switch-to-php-7.0.sh
    ./switch-to-php-7.1.sh
    ./switch-to-php-7.2.sh
    
    0 讨论(0)
  • 2020-11-30 17:35

    From PHP 5.6 => PHP 7.1

    $ sudo a2dismod php5.6
    $ sudo a2enmod php7.1
    

    for old linux versions

     $ sudo service apache2 restart
    

    for more recent version

    $ systemctl restart apache2
    
    0 讨论(0)
  • 2020-11-30 17:38

    To list all available versions and choose from them :

    sudo update-alternatives --config php
    

    Or do manually

    sudo a2dismod php7.1 // disable
    sudo a2enmod php5.6  // enable
    
    0 讨论(0)
提交回复
热议问题