Apache2: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
 
Zeile 1: Zeile 1:
[[Kategorie:ServerApplikation]]
[[Kategorie:ServerApplikation]]
== php5 und php7 gleichzeitig ==
[https://www.thomaschristlieb.de/mehrere-php-versionen-auf-einem-linux-server-mit-php-fpm/ Orginalartikel]
=== Installation ===
<pre>add-apt-repository ppa:ondrej/php
apt-get update
apt-get install libapache2-mod-fastcgi \
  php5.6-fpm php5.6 php5.6-mcrypt php5.6-mbstring php5.6-mysql php5.6-zip php5.6-gd php5.6-xml \
  php7.0-fpm libapache2-mod-fastcgi php7.0-fpm php7.0 php7.0-mcrypt php7.0-mbstring php7.0-mysql \
  php7.0-zip php7.0-gd php7.0-xml
# Test, ob alles läuft:
systemctl status php5.6-fpm
systemctl status php7.0-fpm
</pre>
=== Konfiguration ===
x.y steht für 5.6 bzw. 7.0:
* /var/log/phpx.y-fpm.log
* /etc/php/x.y/fpm/php-fpm.conf
* /etc/php/x.y/fpm/pool.d/www.conf
<pre>a2enmod actions
a2enmod fastcgi
</pre>
Datei /etc/apache2/sites-enabled/000-default.conf:
<pre><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>
</pre>
In der serverspezifischen Datei my.example.com:
<pre><IfModule mod_fastcgi.c>
  <FilesMatch ".+\.ph(p[345]?|t|tml)$">
      SetHandler php70-fcgi-www
  </FilesMatch>
</IfModule>
</pre>


== SSL-Unterstützung für Subdomains ==
== SSL-Unterstützung für Subdomains ==

Aktuelle Version vom 16. Mai 2017, 07:04 Uhr


php5 und php7 gleichzeitig[Bearbeiten]

Orginalartikel

Installation[Bearbeiten]

add-apt-repository ppa:ondrej/php
apt-get update
apt-get install libapache2-mod-fastcgi \
   php5.6-fpm php5.6 php5.6-mcrypt php5.6-mbstring php5.6-mysql php5.6-zip php5.6-gd php5.6-xml \
   php7.0-fpm libapache2-mod-fastcgi php7.0-fpm php7.0 php7.0-mcrypt php7.0-mbstring php7.0-mysql \
   php7.0-zip php7.0-gd php7.0-xml
# Test, ob alles läuft:
systemctl status php5.6-fpm
systemctl status php7.0-fpm

Konfiguration[Bearbeiten]

x.y steht für 5.6 bzw. 7.0:

  • /var/log/phpx.y-fpm.log
  • /etc/php/x.y/fpm/php-fpm.conf
  • /etc/php/x.y/fpm/pool.d/www.conf
a2enmod actions 
a2enmod fastcgi

Datei /etc/apache2/sites-enabled/000-default.conf:

<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>

In der serverspezifischen Datei my.example.com:

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


SSL-Unterstützung für Subdomains[Bearbeiten]

Problem[Bearbeiten]

Die SSL-Verbindung muss bereits aufgebaut werden, wenn der Header nicht bekannt ist. Daher kann es für verschiedene Virtual-Hosts nur ein Zertifikat geben: Der Virtual-Host steht ja im Header.

Es gibt allerdings "Wildcard-Zertifikate", die alle Subdomänen abdecken.

Zertifikat erstellen[Bearbeiten]

mkdir /etc/apache2/keys
cd /etc/apache2/keys
openssl genrsa -out apache.key 2048
openssl req -new -key apache.key -out apache.csr
openssl x509 -req -days 365 -in apache.csr -signkey apache.key -out apache.crt

Wichtig: Beim "Common Name" muss als Wert die Wildcard-Domäne angegeben werden, z.B. *.f-r-e-i.de

Konfiguration[Bearbeiten]

# /etc/apache2/sites-available/default-ssl
<IfModule mod_ssl.c>
NameVirtualHost *:443

<VirtualHost *:443>
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
        SSLCertificateFile      /etc/apache2/keys/apache.crt
        SSLCertificateKeyFile   /etc/apache2/keys/apache.key
        ServerAdmin admin@f-r-e-i.de
        ServerName      "f-r-e-i.de"
        DocumentRoot    "/home/www/frei"
         <directory /home/www/frei>
                Order allow,deny
                Allow from all
                Options Indexes MultiViews FollowSymLinks
        </directory>
</VirtualHost>
...
</IfModule>