How to switch versions of php?

little bottle
Release: 2023-04-06 15:48:02
Original
15186 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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"
Copy after login

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"
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template