D
D
Denis Popov2016-03-19 14:34:23
PHP
Denis Popov, 2016-03-19 14:34:23

How to switch php versions?

Please help me to configure correctly to use different versions of php for different hosts. To switch either in htaccess or in the hosts settings. On the Internet, what I found requires suphp, but it is not in debian stretch and is not built from source on the cubieboard. In general, there are apache 2.4 with the fastcgi module, php5.6-fpm, php7-fpm, it remains only to configure it correctly so that everything works.
now I have this:
/etc/apache2/mods-enabled/fastcgi.conf

<IfModule mod_fastcgi.c>
 AddType application/x-httpd-fastphp .php
 Action application/x-httpd-fastphp /php-fcgi
 
# PHP5
# Alias /php-fcgi /usr/lib/cgi-bin/php5-fcgi
# FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -appConnTimeout 10 -idle-timeout 250 -socket /var/run/php5-fpm.sock -pass-header Authorization
 
# PHP7
Alias /php-fcgi /usr/lib/cgi-bin/php
FastCgiExternalServer /usr/lib/cgi-bin/php -appConnTimeout 10 -idle-timeout 250 -socket /run/php/php7.0-fpm.sock -pass-header Authorization
 
# Apache 2.4+
 <Directory /usr/lib/cgi-bin>
  Require all granted
 </Directory>
#

for example, if I add to the config of some host
Alias /php-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -appConnTimeout 10 -idle-timeout 250 -socket /var/run/php5-fpm.sock -pass-header Authorization

That is 5.6 on this host, 7 on the rest. But if you add this to the second host, Apache will not start ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Popov, 2016-03-19
@DenisDangerous

In general, I solved the problem myself
/etc/apache2/mods-enabled/fastcgi.conf

<IfModule mod_fastcgi.c>
 AddType application/x-httpd-php5 .php
 Action application/x-httpd-php5 /php-fcgi5
 AddType application/x-httpd-php7 .php
 Action application/x-httpd-php7 /php-fcgi7


# PHP5
 Alias /php-fcgi5 /usr/lib/cgi-bin/php5-fcgi
 FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -appConnTimeout 10 -idle-timeout 250 -socket /var/run/php5-fpm.s$

# PHP7
 Alias /php-fcgi7 /usr/lib/cgi-bin/php
 FastCgiExternalServer /usr/lib/cgi-bin/php -appConnTimeout 10 -idle-timeout 250 -socket /run/php/php7.0-fpm.sock $

# Apache 2.4+
 <Directory /usr/lib/cgi-bin>
  Require all granted
 </Directory>
#
</IfModule>

and then in the host settings or in htaccess we write
<FilesMatch "\.php">
SetHandler application/x-httpd-php5
</FilesMatch>

or
<FilesMatch "\.php">
SetHandler application/x-httpd-php7
</FilesMatch>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question