MAC configure multiple versions of PHP environment

sequence

There are pre-installed in mac php and apache, I books pre-installed php7.1, and now I want to configure a php7.2 and php7.3 plus nginx or apache + php7.1 + 7.2 + 7.3

A configuration system preinstalled php7.1 + apache2.4 environment (if no apache server is skipped)

Start, stop and restart apache

sudo apachectl start 
sudo apachectl stop
sudo apachectl restart

sudo apachectl startAfter starting the apache entered in the browser HTTP: // localhost , appears It works! The page
at this time already spent apache
and then enter the command to open the configuration file
sudo vim /private/etc/apache2/httpd.conf
find the code in the following figure in front of the # removed, finished modifying the configuration remember to restart apache
Here Insert Picture Description
Well, now we enter /Library/WebServer/Documents/a new index.php

<?php
    phpinfo();

At this point you should be able to print out the information in the php. Configure the virtual domain name what is not explained in detail in this, you do not know can comment Guest Book

Second, the installation php7.2 + php7.3 + nginx

mac install the software had to say an artifact homebrew
installation flies skip, run the following command is not installed on the line

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
1、nginx

Installed homebrew, we use the following command to install nginx to configure the system pre-installed php7.1

brew install nginx

If you are prompted to install xcode-select on the point of installation
After installing nginx we first started it

brew services start nginx
// 或者
sudo nginx -s reload | stop | reopen

Nginx's start time may be prompted to find nginx.pid

nginx: [error] open() "/usr/local/Cellar/nginx/1.15.8/logs/nginx.pid" failed (2: No such file or directory)

Workaround: Perform the following command and then re-execute the command to start

nginx -c /usr/local/etc/nginx/nginx.conf 

Then enter the browser localhostcan show welcome page like nginx
Here Insert Picture Description

After installing nginx configuration of the system pre-installed php7.1

Run the following commands generate copies php-fpm.conf

sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf

Php-fpm.conf is modified error_log, the following modification is

error_log = /usr/local/var/log/php-fpm.log

Do not modify will complain when you start php-fpm:

ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)

Php-fpm.conf remove bottom profile include=/private/etc/php-fpm.d/*.confin front of the following comments execute command

sudo cp /private/etc/php-fpm.d/www.conf.default /private/etc/php-fpm.d/www.conf

Well, remember modification after modification nginx.conf

sudo vim /usr/local/etc/nginx/nginx.conf

Plus default index.php executed and removed the following circled notes (Oh, forgot to say, listen 8080remember to change 80, 8080 if you like to use do not change)

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

Changed

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

Here Insert Picture Description
These finished restart nginx php-fpm and then start on the line
sudo php-fpmcommand can start php-fpm, said the following command to stop.
Now nginx and php-fpm has already started, in /usr/local/var/wwwNewindex.php

<?php
    phpinfo();

Enter the browser localhostto print information php

2、php7.2

Execute the following command to install php7.2

brew install [email protected]

After the installation is complete input php -vis still version 7.1 or show, do not worry, we first joined the newly installed php environment variable

sudo vim ~/.bash_profile

# 下面两段添加进去
export PATH="/usr/local/Cellar/[email protected]/7.2.15/bin:$PATH"
export PATH="/usr/local/Cellar/[email protected]/7.2.15/sbin:$PATH"

# 保存文件后,source下这个文件,使刚刚添加的环境变量生效
source ~/.bash_profile

This time you execute php -v will show you the version 7.2
but this is not what we want, because php7.1 to be covered
as long as we revise down
/usr/local/Cellar/[email protected]/7.2.15/binphp directory renamed php72
/usr/local/Cellar/[email protected]/7.2.15/sbinphp-FPM directory renamed php- fpm72
then view the terminal follows
Here Insert Picture Description
what is now nginx php switch in two versions of it?
Very simple.
Started just need to get rid of php-fpm start php-fpm72 on the line, get rid of php-fpm command is as follows

# 开启和关闭 php-fpm
sudo php-fpm
sudo killall php-fpm
# 开启和关闭 php-fpm72
sudo php-fpm72 -D
sudo killall php-fpm72
# ps:-D 是以守护进程开启

php7.3 version Installation repeated installation method php7.2

At last

If there are two items need to run both versions at the same time, then only need to modify a php start port number into 9001 on the line, nginx configuration virtual domain name have to be changed when I remember, I will not Screenshot taught step by step, because I myself no change

then modified version of php apache switching /private/etc/apache2/httpd.confconfiguration

LoadModule php7_module libexec/apache2/libphp7.so 
#后面的路径改掉成
/usr/local/Cellar/[email protected]/7.2.15/lib/httpd/modules/libphp7.so

Then restart apache on it

Published 41 original articles · won praise 21 · views 70000 +

Guess you like

Origin blog.csdn.net/u010324331/article/details/87377128