In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve Mac PHP version switching", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to achieve Mac PHP version switching" bar!
In this article, you will learn the following
View the basic php environment
Understand the PHP operating mode
Basic use of brew-php-switcher
Understand bash_profile profile
Commands related to brew installation software
Before we start to perform PHP version-related operations, let's check the local environment after restarting Mac
Execute the following command
Brew services list
Above we can see that there are two php services, and the system or the command line will recognize one of them, and identifying which php environment is another thing, which will be described later.
Here is a basic knowledge of php operation.
The operation mode of PHP
There are four recognized operation modes of PHP in the industry.
1 CGI Universal Gateway Interface Mode
2 FAST-CGI mode
3 CLI command line mode
4-module mode
The first two involve protocol upgrade, that is, php-fpm, and the module mode involves the collocation of server and protocol, for example, Apache,nginxCLI command line mode is shell command line, php- v. Such commands understand this concept and help to determine which actual version of PHP is currently running.
And then understand the root cause of the difference between the result of php-v; and the execution result of web page phpinfo ().
Php-fpm-v
PHP 7.2.12 (fpm-fcgi) (built: Nov 9 2018 10:58:18) Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies
View related versions of PHP
First of all, check out the officially supported versions of php
Brew search php
What is brew-php-switcher?
Brew-php-switcher is a version switching tool for the php environment that switches between versions of php installed through brew.
Github address https://github.com/philcook/brew-php-switcher
As a php version switching management tool, brew-php-switcher has the same function as php version. Unfortunately, php version has been abandoned. For mac users, they can only choose brew-php-switcher as the version switching tool.
Brew no longer provides 5.6 installation source, so brew-php-switcher cannot switch between 5.6s.
Installation
Brew brew-php-switcher install
Basic use
Brew-php-switcher + version number
Brew-php-switcher
Usage: brew-php-switcher version [- s |-slots *] [- cations *]
Version one of: 7.0,7.1,7.2,7.3
-s skip change of mod_php on apache
-apache * skip change of mod_php on apache or valet restart i.e (apache | valet,apache | valet)
-centering * switch a specific config (apache | valet,apache | valet
For example, switch to version 7.2
Brew-php-switcher 7.2
Switching to php@7.2
Switching your shell
Unlinking / usr/local/Cellar/php@5.6/5.6.38... 25 symlinks removed
Unlinking / usr/local/Cellar/php@7.2/7.2.18... 0 symlinks removed
Unlinking / usr/local/Cellar/php/7.3.5... 0 symlinks removed
Linking / usr/local/Cellar/php@7.2/7.2.18... 25 symlinks created
If you need to have this software first in your PATH instead consider running:
Echo 'export PATH= "/ usr/local/opt/php@7.2/bin:$PATH" > > ~ / .bash_profile
Echo 'export PATH= "/ usr/local/opt/php@7.2/sbin:$PATH" > > ~ / .bash_profile
Follow the above prompts to modify the environment variable and
Source / .bash_profile
After it comes into effect
Execute php-v; console php command takes effect (cli)
Php-v
PHP 7.2.18 (cli) (built: May 22 2019 00:08:35) (NTS)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
With Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies
Execute php-fpm-v
Php-fpm-v
PHP 7.2.18 (fpm-fcgi) (built: May 22 2019 00:08:38)
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
With Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies
View soft connections
Cd / usr/local/opt/php@7.2/sbin/local/opt
Ls-l
Lrwxr-xr-x 1 admin 19 6 2 06:21 php->.. / Cellar/php/7.3.5
Lrwxr-xr-x 1 admin 32 3 20 16:07 php-code-sniffer->.. / Cellar/php-code-sniffer/3.4.1
Lrwxr-xr-x 1 admin 24 5 28 09:25 php@5.6->.. / Cellar/php@5.6/5.6.38
Lrwxr-xr-x 1 admin 24 6 2 05:54 php@7.2->.. / Cellar/php@7.2/7.2.18
Lrwxr-xr-x 1 admin 19 6 2 06:21 php@7.3->.. / Cellar/php/7.3.5
Identify PHP services
As mentioned above, brew services shows two php services. We can use the following command to shut down one by one to verify which version of PHP the web service recognizes.
Brew services stop php
Brew services stop php@7.2
Use phpinfo () to view the current running version, and when all php services are turned off, the web page will directly display 502.
Brew services restart php
View the process
Ps-ef | grep php-fpm
Brew services start php@7.2
If you need to have php@7.2 first in your PATH run:
Echo 'export PATH= "/ usr/local/opt/php@7.2/bin:$PATH" > > ~ / .bash_profile
Echo 'export PATH= "/ usr/local/opt/php@7.2/sbin:$PATH" > > ~ / .bash_profile
You can also run `php-- ini` inside terminal to see which files are used by PHP in CLI mode.
Preliminary understanding of bash_profile configuration file
In mac environment, custom installed software will be in the / usr/local/Cellar path. When the installation software conflicts with the original software of the system, such as Python2.7, python3.n,PHP5.6 and PHP7.n, you need to specify which version to use by default.
System profile
~ / .bash_profile
By modifying ~ / .bash_profile, the system recognizes that the default Python version is 3.7.
Alias python= "/ usr/local/Cellar/python/3.7.0/bin/python3.7"
The command takes effect source ~ / .bash_profile
PHP7 installs the mongodb extension
Which pecl
Sudo / usr/local/opt/php@7.2/bin/pecl install mongodb
Build process completed successfully
Installing'/ usr/local/Cellar/php@7.2/7.2.14/pecl/20170718/mongodb.so'
Install ok: channel://pecl.php.net/mongodb-1.5.3
Extension mongodb enabled in php.ini
YII2 MongoDb extension https://packagist.org/packages/yiisoft/yii2-mongodb"yiisoft/yii2-mongodb": "~ 2.1.0" 2.1.0 is a version node, previously using the old mogo driver
Php-m | grep mongodb
Finally, I checked the information and found that the installation tutorial under this URL is quite practical, and it still depends on pecl installation.
Https://www.runoob.com/mongodb/php7-mongdb-tutorial.html
PHP7 installs the redis extension
Sudo / usr/local/opt/php@7.2/bin/pecl install igbinary
Sudo / usr/local/opt/php@7.2/bin/pecl install redis
Build process completed successfully
Installing'/ usr/local/Cellar/php@7.2/7.2.14/pecl/20170718/redis.so'
Install ok: channel://pecl.php.net/redis-4.2.0
Extension redis enabled in php.ini
Supplement commonly used commands
View php ini profile path
Php-I | grep php.ini
Output
Configuration File (php.ini) Path = > / usr/local/etc/php/7.2
Loaded Configuration File = > / usr/local/etc/php/7.2/php.ini
View pecl path
Which pecl
Output
/ usr/local/opt/php@7.2/bin/pecl
View a list of services installed through brew
Brew services list
Thank you for your reading, the above is the content of "how to achieve Mac PHP version switching". After the study of this article, I believe you have a deeper understanding of how to achieve Mac PHP version switching, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.