Home  >  Article  >  Backend Development  >  How to switch versions of php?

How to switch versions of php?

little bottle
little bottleOriginal
2019-05-11 13:42:3615101browse

Sometimes, PHP programmers may encounter the need to switch PHP versions at work. Of course, veterans don’t have to think too much. The operation is as fast as a tiger, but novices will encounter difficulties when they encounter the need to change versions. , below I will tell you how to make multiple PHP versions coexist and switch PHP versions.

There are three ways to switch php versions:

1. Specify the path when compiling PHP

./configure --prefix=/opt/php/php-5.6
make && make install

This way, the PHP version can be installed to a special path instead of being installed under /usr/local/. Multiple versions of PHP are stored in their own directories, and different PHPs are started according to the needs of the program.

/usr/local/php/php-5.6/bin/php  server.php

2. Use soft links

ln -s /usr/local/php/php-5.6/bin/php /usr/local/bin/php
# 或
ln -s /usr/local/php/php-5.4/bin/php /usr/local/bin/php
php -v

If you want to switch the default PHP version, you only need to rebuild the soft link.

3. Write a script to automatically switch versions:

to_php56.sh, switch to the default PHP to version 5.6

rm /usr/local/bin/php
rm /usr/local/bin/phpize
rm /usr/local/bin/php-config
ln -s /usr/local/php/php-5.6/bin/php /usr/local/bin/php
ln -s /usr/local/php/php-5.6/bin/phpize /usr/local/bin/phpize
ln -s /usr/local/php/php-5.6/bin/php-config /usr/local/bin/php-config
echo "to php5.6 done"

to_php70.sh, switch to the default PHP version 7.0

rm /usr/local/bin/php
rm /usr/local/bin/phpize
rm /usr/local/bin/php-config
ln -s /usr/local/php/php-7.0/bin/php /usr/local/bin/php
ln -s /usr/local/php/php-7.0/bin/phpize /usr/local/bin/phpize
ln -s /usr/local/php/php-7.0/bin/php-config /usr/local/bin/php-config
echo "to php 7.0 done"

Note:

1. Remove the .bash_profile file and change the PHP path Configuration (Attachment: Modify environment variables for Mac Pro);

2. Delete the /usr/bin/php file;

3. On Mac computers, the PHP that comes with the system cannot be deleted. -5.6.25 (no permissions, nor sudo), the file path is /usr/bin/php. The solution is to modify the .bash_profile file.

The above is the detailed content of How to switch versions of php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn