Switch php versions on commandline ubuntu 16.04

前端 未结 16 1130
别那么骄傲
别那么骄傲 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:39

    May be you might have an old PHP version like PHP 5.6 in your system and you installed PHP 7.2 too so thats multiple PHP in your machine. There are some applications which were developed when older PHP 5.6 was latest version, they are still live and you working on those applications, You might be working on Laravel simultaneously but Laravel requires PHP 7+ to get started. Getting the picture ?

    In that case you can switch between the PHP versions to suit your requirements.

    Switch From PHP 5.6 => PHP 7.2

    Apache:-

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

    Command Line:-

    sudo update-alternatives --set php /usr/bin/php7.2
    sudo update-alternatives --set phar /usr/bin/phar7.2
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
    sudo update-alternatives --set phpize /usr/bin/phpize7.2
    sudo update-alternatives --set php-config /usr/bin/php-config7.2
    

    And vice-versa, Switch From PHP 7.2 => PHP 5.6

    Apache:-

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

    Command Line:-

    sudo update-alternatives --set php /usr/bin/php5.6
    sudo update-alternatives --set phar /usr/bin/phar5.6
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
    sudo update-alternatives --set phpize /usr/bin/phpize5.6
    sudo update-alternatives --set php-config /usr/bin/php-config5.6
    
    0 讨论(0)
  • 2020-11-30 17:39

    please follow the steps :

    i.e : your current version is : current_version = 7.3 , and you want to change it to : new_version = 7.2
    
    1) sudo a2dismod php(current_version) 
    2) sudo a2enmod php(new_version)
    3) sudo update-alternatives --config php (here you need to select php version number) 
    4) restart apache through : 
      sudo /etc/init.d/apache2 restart OR
      sudo service apache2 restart
    
    0 讨论(0)
  • 2020-11-30 17:42

    I think you should try this

    From php5.6 to php7.1

    sudo a2dismod php5.6
    sudo a2enmod php7.1
    sudo service apache2 restart
    
    sudo update-alternatives --set php /usr/bin/php7.1
    sudo update-alternatives --set phar /usr/bin/phar7.1
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
    

    From php7.1 to php5.6

    sudo a2dismod php7.1
    sudo a2enmod php5.6
    sudo service apache2 restart
    
    sudo update-alternatives --set php /usr/bin/php5.6
    sudo update-alternatives --set phar /usr/bin/phar5.6
    sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
    
    0 讨论(0)
  • 2020-11-30 17:43

    When installing laravel on Ubuntu 18.04, be default PHP 7.3.0RC3 install selected, but laravel and symfony will not install properly complaining about missin php-xml and php-zip, even though they are installed. You need to switch to php 7.1, using the instructions above or,

     sudo update-alternatives --set php /usr/bin/php7.1
    

    now, running laravel new blog, will proceed correctly

    0 讨论(0)
提交回复
热议问题