zwei php-Versionen auf einem Server

mattirautiainen

New Member
Hi

auf unserem Server brauche ich simultan php5 und php7.
Auf dem Server ist ein Ubuntu 16.04. Apache - Module
kann ich über a2enmod / a2dismod aktivieren bzw.
deaktivieren. Per default wir php7 gesetzt.
Ich kann aber genauso gut über obige Befehle php7
deaktivieren und serverweit php5 „einschalten“.

Ich habe jetzt über einen VirtualHost einen
Webauftritt in eine Subdomain gelegt. Meine
„conf“ sie ähnlich aus wie:
<VirtualHost *:80>


ServerName subdomain.myserver.com
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/subdomain

Genau für diese Subdomain würde ich gerne exklusiv php5
setzen. Daher habe ich im selben virtual host folgendes
geschrieben
<IfModule php5_module>

AddHandler php5-script .php

AddType text / html .php

Directory index.php

</IfModule>


Nun gibt es damit natürlich noch kein php5 im gleichen
Verzeichnis. Dazu müßte php5 nach meiner Meinung geladen sein.
Wenn man jetzt aber php5 und und php7 gleichzeitig startet,
läßt sich der Apache nicht mehr starten.

Könnt ihr mir grad sagen, wie man php5 und php7
gleichzeitig in diesem setup fährt ?

Vielen Dank für eure Hilfe ?

VG
Thor
 
Als Apache-Modul kannst du nur eine PHP-Version einbinden. Du brauchst eine Lösung, in der das PHP eine vom Webserver unabhängige Anwendung ist, z.B. PHP-FPM unter FastCGI.
 
Hallo Thomas,

vielen Dank für deine Lösung.

das scheint alles so zu laufen, wie von dir beschrieben. Aber
krieg trotzdem noch kein php5 hin.

Grundsätzlich läufts:
Code:
root@moodle:/etc/apache2/sites-available# systemctl status php5.6-fpm
● php5.6-fpm.service - The PHP 5.6 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php5.6-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Di 2016-09-27 15:19:08 CEST; 1h 3min ago
     Docs: man:php-fpm5.6(8)
 Main PID: 16070 (php-fpm5.6)
   Status: "Processes active: 0, idle: 3, Requests: 219, slow: 0, Traffic: 0req/sec"
    Tasks: 4
   Memory: 16.3M
      CPU: 434ms
   CGroup: /system.slice/php5.6-fpm.service
           ├─16070 php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)                      
           ├─16074 php-fpm: pool www                                                            
           ├─16075 php-fpm: pool www                                                            
           └─16528 php-fpm: pool www                                                            

Sep 27 15:19:08 moodle systemd[1]: Stopped The PHP 5.6 FastCGI Process Manager.
Sep 27 15:19:08 moodle systemd[1]: Starting The PHP 5.6 FastCGI Process Manager...
Sep 27 15:19:08 moodle systemd[1]: Started The PHP 5.6 FastCGI Process Manager.
root@moodle:/etc/apache2/sites-available#


Ich habe dann wie in deiner Anleitung
Code:
<IfModule mod_fastcgi.c>
  AddHandler php56-fcgi-www .php
  Action php56-fcgi-www /php56-fcgi-www
  Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www
  FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -pass-header Authorization

  <Directory "/usr/lib/cgi-bin">
     Require all granted
  </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   AddHandler php70-fcgi-www .php
   Action php70-fcgi-www /php70-fcgi-www
   Alias /php70-fcgi-www /usr/lib/cgi-bin/php70-fcgi-www
   FastCgiExternalServer /usr/lib/cgi-bin/php70-fcgi-www -socket /run/php/php7.0-fpm.sock -pass-header Authorization

   <Directory "/usr/lib/cgi-bin">
      Require all granted
   </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php70-fcgi-www
   </FilesMatch>
</IfModule>

An den Anfang von "/etc/apache2/sites-available" geschrieben.
Also nicht in sites-enabled. Da stehen bei mir nur Softlinks.

Dann habe ich
Code:
SetHandler php56-fcgi-www

in einen Virtualhosteintrag geschrieben:

Code:
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        SetHandler php56-fcgi-www
        ServerName meinedomain.de
        ServerAdmin webmaster@localhost
...
</VirtualHost>

Laut Prozeßtabelle luppts:

Code:
root@moodle:/etc/apache2/sites-available# ps awux | grep php
root     16013  0.0  1.8 406612 37380 ?        Ss   15:19   0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 16018  0.4  4.4 412900 90660 ?        S    15:19   0:21 php-fpm: pool www
root     16070  0.0  1.5 376044 30768 ?        Ss   15:19   0:00 php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)
www-data 16074  0.0  0.5 376176 11080 ?        S    15:19   0:00 php-fpm: pool www
www-data 16075  0.0  0.5 376176 11132 ?        S    15:19   0:00 php-fpm: pool www
www-data 16525  0.5  2.9 412396 60732 ?        S    15:40   0:17 php-fpm: pool www
www-data 16528  0.0  0.5 376176 11144 ?        S    15:40   0:00 php-fpm: pool www
www-data 16841  0.3  2.3 412084 48068 ?        S    16:08   0:04 php-fpm: pool www
root     17005  0.0  0.0  15800   976 pts/0    S+   16:32   0:00 grep --color=auto php
root@moodle:/etc/apache2/sites-available#

Nur leider kein php5 sondern php7 auf meinedomain.de

Könntest Du hier noch mal weiterhelfen ?
Wäre super nett

VG
Matti
 
Hallo Matti,

du musst in diesem Teil das SetHandler eintragen:
Code:
<IfModule mod_fastcgi.c>
   <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php70-fcgi-www
   </FilesMatch>
</IfModule>

Das ist in einer der Sites-Enabled einzutragen.
(Ja, das sind Softlinks, ruhig in einem der Softlinks eintragen).

Das heißt wenn du die Seite '/etc/apache2/sites-enabled/shop.conf' auf PHP7 haben will trägst du dort das ein:
Code:
<IfModule mod_fastcgi.c>
  AddHandler php56-fcgi-www .php
  Action php56-fcgi-www /php56-fcgi-www
  Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www
  FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -pass-header Authorization

  <Directory "/usr/lib/cgi-bin">
     Require all granted
  </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   AddHandler php70-fcgi-www .php
   Action php70-fcgi-www /php70-fcgi-www
   Alias /php70-fcgi-www /usr/lib/cgi-bin/php70-fcgi-www
   FastCgiExternalServer /usr/lib/cgi-bin/php70-fcgi-www -socket /run/php/php7.0-fpm.sock -pass-header Authorization

   <Directory "/usr/lib/cgi-bin">
      Require all granted
   </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php70-fcgi-www
   </FilesMatch>
</IfModule>

Möchtest du nun '/etc/apache2/sites-enabled/page.conf' auf PHP 5.6 haben trägst du das hier ein (es ändert sich nur die eine Zeile!)
Code:
<IfModule mod_fastcgi.c>
  AddHandler php56-fcgi-www .php
  Action php56-fcgi-www /php56-fcgi-www
  Alias /php56-fcgi-www /usr/lib/cgi-bin/php56-fcgi-www
  FastCgiExternalServer /usr/lib/cgi-bin/php56-fcgi-www -socket /run/php/php5.6-fpm.sock -pass-header Authorization

  <Directory "/usr/lib/cgi-bin">
     Require all granted
  </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   AddHandler php70-fcgi-www .php
   Action php70-fcgi-www /php70-fcgi-www
   Alias /php70-fcgi-www /usr/lib/cgi-bin/php70-fcgi-www
   FastCgiExternalServer /usr/lib/cgi-bin/php70-fcgi-www -socket /run/php/php7.0-fpm.sock -pass-header Authorization

   <Directory "/usr/lib/cgi-bin">
      Require all granted
   </Directory>
</IfModule>

<IfModule mod_fastcgi.c>
   <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php56-fcgi-www
   </FilesMatch>
</IfModule>
 
Back
Top