3

I have read ten dozens of threads but can not find out what the problem. I need php5 and php7 on one machine and want the script in a folder to be interpreted by php7. I can not find the mistake in the configuration, so please have a look

Apache: Apache/2.4.23 (Debian)

OS: Debian Testing

Both PHP Version are installed:

/var/www/test# ls -l /usr/bin/php*

lrwxrwxrwx 1 root root      21 Okt  6  2015 /usr/bin/php -> /etc/alternatives/php
-rwxr-xr-x 1 root root 9065192 Jul 26 10:33 /usr/bin/php5
-rwxr-xr-x 1 root root 4422704 Sep 18 10:38 /usr/bin/php7.0
lrwxrwxrwx 1 root root      28 Okt  6  2015 /usr/bin/php-config -> /etc/alternatives/php-config
-rwxr-xr-x 1 root root    5237 Jul 26 10:33 /usr/bin/php-config5
lrwxrwxrwx 1 root root      24 Okt  6  2015 /usr/bin/phpize -> /etc/alternatives/phpize
-rwxr-xr-x 1 root root    4730 Jul 26 10:33 /usr/bin/phpize5

Right AddHandler is set for this folder

nano /var/www/test/.htaccess

AddHandler application/x-httpd-php7 .php

And AllowOverwrite is set

nano /etc/apache2/apache2.conf

...
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow 
# access here, or in any related virtual host.
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>
...

and php7 should be the default anway

update-alternatives php

  Auswahl      Pfad             Priorität Status
------------------------------------------------------------
* 0            /usr/bin/php7.0   70        automatischer Modus
  1            /usr/bin/php5     50        manueller Modus
  2            /usr/bin/php7.0   70        manueller Modus

That works in the command line

php -v

PHP 7.0.11-1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.11-1, Copyright (c) 1999-2016, by Zend Technologies

But not in the server context!

w3m http://localhost/test/info.php

PHP Version 5.6.24-0+deb8u1

System           Linux ber-eagle02vm 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64
Build Date       Jul 26 2016 08:17:13
Server API       Apache 2.0 Handler
Virtual
Directory        disabled
Support
Configuration
File (php.ini)   /etc/php5/apache2
Path
Loaded
Configuration    /etc/php5/apache2/php.ini
File
Scan this dir
for additional   /etc/php5/apache2/conf.d
...

Any ideas?

Paflow
  • 2,030
  • 3
  • 30
  • 50
  • 1
    Does /mods-enabled/php7.conf and /mods-enabled/php7.load exist in the apache config? – andre Sep 27 '16 at 13:14
  • That the sorce of error, thank you! Still, I can only enable one mod at one time, wich is kind of a problem (see below), but at least I know now what part was missing. – Paflow Sep 27 '16 at 13:27

1 Answers1

1

Looks like you are using mod_php (Server API => Apache 2.0 Handler), which means php is embedded in apache as a module. To answer the question, as far as I know, you cannot have multiple mod_php loaded at the same time, and that's why your php served through the webserver is always the version 5.

When you use php on the command line, it has nothing to do with the webserver and it uses php7 according to your update-alternatives. the php command goes to /usr/bin/php7.

A way would be to use cgi (fastcgi, php-fpm) for different php versions. I've also read about setting this up by using different virtual hosts, but never tried it myself, and this would be an other question I guess. Hope it helps!

Community
  • 1
  • 1
Zimmi
  • 1,599
  • 1
  • 10
  • 14