sudo a2enmod php5.6,php -v仍显示php 7.01冲突

时间:2021-05-20 23:38:58

I'm trying to switch php versions, get following response. I tried dismounting mpm_prefork and mpm_worker still no joy, any ideas please.

我正在尝试切换php版本,得到以下响应。我试过拆卸mpm_prefork和mpm_worker仍然没有快乐,请任何想法。

on Ubuntu 16.04

在Ubuntu 16.04上

sudo a2enmod php5.6

 Considering dependency mpm_prefork for php5.6:
 Considering conflict mpm_event for mpm_prefork:
 Considering conflict mpm_worker for mpm_prefork:
 Enabling module mpm_prefork.
 Considering conflict php5 for php5.6:
 Enabling module php5.6.
 To activate the new configuration, you need to run:
 service apache2 restart

4 个解决方案

#1


17  

Your commands looks correct. Did you restart apache before testing?

您的命令看起来正确。你在测试之前重启了apache吗?

sudo service apache2 restart

The PHP module php5.6 made by Ondřej Surý can only be enabled by:

由OndřejSurý制作的PHP模块php5.6只能通过以下方式启用:

sudo a2dismod php7.0
sudo a2dismod php7.1
sudo a2dismod php7.2
sudo a2enmod php5.6
sudo update-alternatives --set php /usr/bin/php5.6
sudo service apache2 restart

I have found that this setup isn't compatible with any other MPM modules other that PREFORK. You have to make sure you disable ALL other MPM modules first, before enabling the php5.6 mod.

我发现这个设置与PREFORK以外的任何其他MPM模块都不兼容。在启用php5.6 mod之前,您必须首先确保禁用所有其他MPM模块。

If the mod won't enable you might have to try to disable the other MPM's.

如果mod无法启用,则可能必须尝试禁用其他MPM。

sudo a2dismod mpm_prefork
sudo a2dismod mpm_worker
sudo a2dismod mpm_event

Then try to enable the mod again as it should auto enable the correct MPM.

然后尝试再次启用mod,因为它应该自动启用正确的MPM。

$ sudo a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php5.6:
Enabling module php5.6.
To activate the new configuration, you need to run:
  service apache2 restart

FYI, I like to put these commands into my '.bash_aliases' so I always have them handy for DEV work.

仅供参考,我喜欢将这些命令放入我的'.bash_aliases'中,因此我总是将它们放在DEV工作中。

# Aliases - PHP
alias php.info='php -i'
alias php5.6='sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2enmod php5.6 && sudo update-alternatives --set php /usr/bin/php5.6 && sudo service apache2 restart'
alias php7.0='sudo a2dismod php5.6 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2enmod php7.0 && sudo update-alternatives --set php /usr/bin/php7.0 && sudo service apache2 restart'
alias php7.1='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.2 && sudo a2enmod php7.1 && sudo update-alternatives --set php /usr/bin/php7.1 && sudo service apache2 restart'
alias php7.2='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2enmod php7.2 && sudo update-alternatives --set php /usr/bin/php7.2 && sudo service apache2 restart'

GIST: https://gist.github.com/djravine/376e81a018ba2b980750a5578deb3935

GIST:https://gist.github.com/djravine/376​​e81a018ba2b980750a5578deb3935

#2


7  

php -v (default PHP version)

php -v(默认PHP版)

From PHP 7.0 to PHP 5.6:

从PHP 7.0到PHP 5.6:

sudo a2dismod php7.0

sudo a2enmod php5.6

sudo update-alternatives --set php /usr/bin/php5.6

sudo service apache2 restart

From PHP 5.6 to PHP 7.0:

从PHP 5.6到PHP 7.0:

sudo a2dismod php5.6

sudo a2enmod php7.0

sudo update-alternatives --set php /usr/bin/php7.0

sudo service apache2 restart

#3


3  

To configure php7 to run with your server you need to do some configuration: 1. Make sure you remove any traces of php/php5 Open a terminal and:

要配置php7以与您的服务器一起运行,您需要进行一些配置:1。确保删除任何php / php5的痕迹打开终端并:

cd /etc/apache2/mods-enabled
ls -la

The output should not contain any php5.conf or php5.load, but if it does, do the following:

输出不应包含任何php5.conf或php5.load,但如果包含,请执行以下操作:

# this is the proper way of disabling modules
sudo a2dismod php5

# run this only if the above command didn't remove the php5 sym-links
sudo rm php5.load
sudo rm php5.con

Now add the php7.0.conf and php7.0.load instead:

现在添加php7.0.conf和php7.0.load:

# this is the proper way of enabling modules
sudo a2enmod php7.0

# run this only if the above command didn't create the php7.0 sym-links
sudo ln -s php7.0.conf ../mods-available/php7.0.conf
sudo ln -s php7.0.load ../mods-available/php7.0.load

The output of ls -la php* should look like this:

ls -la php *的输出应该如下所示:

lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.load -> ../mods-available/php7.0.load

After dealing with the modules we now come to the /etc/apache2/conf-enabled directory. Remove any traces of php/php5 here as well by sudo rm

在处理模块后,我们现在进入/ etc / apache2 / conf-enabled目录。在这里删除任何php / php5的痕迹以及sudo rm

Then, if needed do:

然后,如果需要的话:

# the proper way of enabling configs
sudo a2enconf php7.0-cgi
sudo a2enconf php7.0-fpm

# do those commands only if the above didn't work out
sudo ln -s php7.0-cgi.conf ../conf-available/php7.0-cgi.conf
sudo ln -s php7.0-fpm.conf ../conf-available/php7.0-fpm.conf

The output of ls -la php* should look like this:

ls -la php *的输出应该如下所示:

lrwxrwxrwx 1 root root 33 Apr 21 17:00 php7.0-cgi.conf -> ../conf-available/php7.0-cgi.conf
lrwxrwxrwx 1 root root 33 Apr 21 17:01 php7.0-fpm.conf -> ../conf-available/php7.0

And restart apache.

并重启apache。

I have just resolved by following these steps.

我刚刚通过以下步骤解决了问题。

#4


-1  

a2enmod is a command related to apache2 while php -v is a command which is related to php itself .

a2enmod是一个与apache2相关的命令,而php -v是一个与php本身相关的命令。

when you are running the following command

当您运行以下命令时

sudo a2enmod php5.6

you are then talking to apache2 not to php [ hey apache , enable php5 module for me instead of php7.0 ] so to speak .

你正在谈论apache2而不是php [嘿apache,为我启用php5模块而不是php7.0]可以这么说。

to enable php5 in your server , you will have to :-

1) remove the current php version which is 7 , and then download your desired version of php .

1)删除当前的7个PHP版本,然后下载所需的php版本。

or

要么

2) download php 5 along side php 7

2)沿着php 7下载php 5

i think that php-version will be a great starting point to do some thing like that .

我认为php-version将是一个很好的起点,做一些这样的事情。

#1


17  

Your commands looks correct. Did you restart apache before testing?

您的命令看起来正确。你在测试之前重启了apache吗?

sudo service apache2 restart

The PHP module php5.6 made by Ondřej Surý can only be enabled by:

由OndřejSurý制作的PHP模块php5.6只能通过以下方式启用:

sudo a2dismod php7.0
sudo a2dismod php7.1
sudo a2dismod php7.2
sudo a2enmod php5.6
sudo update-alternatives --set php /usr/bin/php5.6
sudo service apache2 restart

I have found that this setup isn't compatible with any other MPM modules other that PREFORK. You have to make sure you disable ALL other MPM modules first, before enabling the php5.6 mod.

我发现这个设置与PREFORK以外的任何其他MPM模块都不兼容。在启用php5.6 mod之前,您必须首先确保禁用所有其他MPM模块。

If the mod won't enable you might have to try to disable the other MPM's.

如果mod无法启用,则可能必须尝试禁用其他MPM。

sudo a2dismod mpm_prefork
sudo a2dismod mpm_worker
sudo a2dismod mpm_event

Then try to enable the mod again as it should auto enable the correct MPM.

然后尝试再次启用mod,因为它应该自动启用正确的MPM。

$ sudo a2enmod php5.6
Considering dependency mpm_prefork for php5.6:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php5.6:
Enabling module php5.6.
To activate the new configuration, you need to run:
  service apache2 restart

FYI, I like to put these commands into my '.bash_aliases' so I always have them handy for DEV work.

仅供参考,我喜欢将这些命令放入我的'.bash_aliases'中,因此我总是将它们放在DEV工作中。

# Aliases - PHP
alias php.info='php -i'
alias php5.6='sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2enmod php5.6 && sudo update-alternatives --set php /usr/bin/php5.6 && sudo service apache2 restart'
alias php7.0='sudo a2dismod php5.6 && sudo a2dismod php7.1 && sudo a2dismod php7.2 && sudo a2enmod php7.0 && sudo update-alternatives --set php /usr/bin/php7.0 && sudo service apache2 restart'
alias php7.1='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.2 && sudo a2enmod php7.1 && sudo update-alternatives --set php /usr/bin/php7.1 && sudo service apache2 restart'
alias php7.2='sudo a2dismod php5.6 && sudo a2dismod php7.0 && sudo a2dismod php7.1 && sudo a2enmod php7.2 && sudo update-alternatives --set php /usr/bin/php7.2 && sudo service apache2 restart'

GIST: https://gist.github.com/djravine/376e81a018ba2b980750a5578deb3935

GIST:https://gist.github.com/djravine/376​​e81a018ba2b980750a5578deb3935

#2


7  

php -v (default PHP version)

php -v(默认PHP版)

From PHP 7.0 to PHP 5.6:

从PHP 7.0到PHP 5.6:

sudo a2dismod php7.0

sudo a2enmod php5.6

sudo update-alternatives --set php /usr/bin/php5.6

sudo service apache2 restart

From PHP 5.6 to PHP 7.0:

从PHP 5.6到PHP 7.0:

sudo a2dismod php5.6

sudo a2enmod php7.0

sudo update-alternatives --set php /usr/bin/php7.0

sudo service apache2 restart

#3


3  

To configure php7 to run with your server you need to do some configuration: 1. Make sure you remove any traces of php/php5 Open a terminal and:

要配置php7以与您的服务器一起运行,您需要进行一些配置:1。确保删除任何php / php5的痕迹打开终端并:

cd /etc/apache2/mods-enabled
ls -la

The output should not contain any php5.conf or php5.load, but if it does, do the following:

输出不应包含任何php5.conf或php5.load,但如果包含,请执行以下操作:

# this is the proper way of disabling modules
sudo a2dismod php5

# run this only if the above command didn't remove the php5 sym-links
sudo rm php5.load
sudo rm php5.con

Now add the php7.0.conf and php7.0.load instead:

现在添加php7.0.conf和php7.0.load:

# this is the proper way of enabling modules
sudo a2enmod php7.0

# run this only if the above command didn't create the php7.0 sym-links
sudo ln -s php7.0.conf ../mods-available/php7.0.conf
sudo ln -s php7.0.load ../mods-available/php7.0.load

The output of ls -la php* should look like this:

ls -la php *的输出应该如下所示:

lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Apr 15 03:55 php7.0.load -> ../mods-available/php7.0.load

After dealing with the modules we now come to the /etc/apache2/conf-enabled directory. Remove any traces of php/php5 here as well by sudo rm

在处理模块后,我们现在进入/ etc / apache2 / conf-enabled目录。在这里删除任何php / php5的痕迹以及sudo rm

Then, if needed do:

然后,如果需要的话:

# the proper way of enabling configs
sudo a2enconf php7.0-cgi
sudo a2enconf php7.0-fpm

# do those commands only if the above didn't work out
sudo ln -s php7.0-cgi.conf ../conf-available/php7.0-cgi.conf
sudo ln -s php7.0-fpm.conf ../conf-available/php7.0-fpm.conf

The output of ls -la php* should look like this:

ls -la php *的输出应该如下所示:

lrwxrwxrwx 1 root root 33 Apr 21 17:00 php7.0-cgi.conf -> ../conf-available/php7.0-cgi.conf
lrwxrwxrwx 1 root root 33 Apr 21 17:01 php7.0-fpm.conf -> ../conf-available/php7.0

And restart apache.

并重启apache。

I have just resolved by following these steps.

我刚刚通过以下步骤解决了问题。

#4


-1  

a2enmod is a command related to apache2 while php -v is a command which is related to php itself .

a2enmod是一个与apache2相关的命令,而php -v是一个与php本身相关的命令。

when you are running the following command

当您运行以下命令时

sudo a2enmod php5.6

you are then talking to apache2 not to php [ hey apache , enable php5 module for me instead of php7.0 ] so to speak .

你正在谈论apache2而不是php [嘿apache,为我启用php5模块而不是php7.0]可以这么说。

to enable php5 in your server , you will have to :-

1) remove the current php version which is 7 , and then download your desired version of php .

1)删除当前的7个PHP版本,然后下载所需的php版本。

or

要么

2) download php 5 along side php 7

2)沿着php 7下载php 5

i think that php-version will be a great starting point to do some thing like that .

我认为php-version将是一个很好的起点,做一些这样的事情。