Linux switching multiple versions of Php____linux

Source: Internet
Author: User
Tags fpm

Install the paths of each version of PHP plus the version number

such as--prefix=/usr/local/php-7.0.1

As below, I install the path

When installing, add each version of PHP-FPM to the service

Install-v-m755/php Source Path/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm (corresponding version number)

The easiest way to switch is to start a different service.

Turn off the corresponding T version of PHP-FPM first.

sudo service php-fpmxxxx stop

Turn on the version you want to switch

sudo service php-fpm7.0.5 start


The second way to use the script to switch

Copy a php-fpm startup script

sudo cp/etc/init.d/php-fpm7.0.5/etc/init.d/php-fpm

Use Vim to open, change prefix to prefix=/usr/local/php

The main thing here is to make a shortcut to the version of PHP that was launched.

Create a new script in the home directory switchphp.sh

#!/bin/zsh

version= ($ ls/usr/local | grep  php-| awk ' {printf '%s ', '} '))

echo $version
echo "Please enter the right version This number: "
i=1 for
ver in $version
does
    echo $i") "$ver
    i=$ (($i + 1))
done

Read num case

" $ Num "
	in [1234])
		echo the version you selected is: $version [$num]
		service php-fpm stop
		ln-sf/usr/local/$version [$num ]/usr/local/php
		If ["$?"!= 0]; then
			echo "has no permissions failed"
			exit 1
		fi
		service php-fpm start

		If ["$?"!= 0]; Then
			echo "No permissions Failed"
			exit 1
		fi

		echo "successfully switched"
	;;

	*
		Echo-n "The version number you entered is not correct. "
	;;

Esac

Version= ($ (ls/usr/local | grep  php-| awk ' {printf '%s ', $} ')
Pay attention to this sentence, according to the existing installation directory to modify

Modify the switchphp.sh into an executable file

sudo chmod 755 switchphp.sh

And then execute

sudo./switchphp.sh

The effect chart is as follows:













Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.