logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: CGI and conditional execute index only (php)
Author
gmini



Joined: 22 Dec 2017
Posts: 3
Location: France

PostPosted: Fri 22 Dec '17 12:22    Post subject: CGI and conditional execute index only (php) Reply with quote

Hi,
I try to connect severals PHP versions by mod_proxy.
In Apache 2.4 (Ubuntu) i use a conditional to launch each version (<If>).
The problem, when i run a script - not the INDEX (.php) - it's return php codes...
In this case, all indexes (~/) run with PHP, not the others scripts (beta.php, funct.php, ...).
When i remove the conditional (<If></If>), for all php scripts works.
What's i missed ? Apache make me crazy.. My script :

Code:
#PHP default version :
SetEnv PHP_VERSION 5

<IfModule proxy_fcgi_module>

   ProxyErrorOverride on

   <FilesMatch "\.ph(p[2-6]?|tml)$">

      <If "env('PHP_VERSION') == '5'">      
         SetHandler 'proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost'
      </If>

      <If "env('PHP_VERSION') == '7'">      
         SetHandler 'proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost'
      </If>

   </FilesMatch>

</IfModule>


I try with (and others regex) nothing works :
Code:
<FilesMatch "\.php$">

Any solutions ?
Thank's, G.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Fri 22 Dec '17 17:38    Post subject: Reply with quote

I wasn't successful with sockets.

My simple solution was to go directly to the fpm process via tcp

Code:
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
Back to top
gmini



Joined: 22 Dec 2017
Posts: 3
Location: France

PostPosted: Sat 23 Dec '17 7:36    Post subject: Reply with quote

Hi,
It could be a great alternative, but here was the same problem :

Code:
#(...)
<If "env('PHP_VERSION') == '7'">
ProxyPassMatch ^/(.*\.php)$ fcgi://localhost:9055/var/www/html/$1
</If>

In systemctl status :
ubuntu apache2[17774]:ProxyPassMatch cannot occur within <If> section
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Sat 23 Dec '17 13:12    Post subject: Reply with quote

I wasn't able to test the socket, but this give no syntax warning.

Code:

<VirtualHost *:443>
    SetEnv PHP_VERSION 7
    DocumentRoot /home/mario/jblond
    ServerName jblond.example.com
    <Directory /home/mario/jblond>
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php [QSA]

        Options Indexes FollowSymlinks Multiviews
        AllowOverride None
         Require all granted
        AddHandler lua-script .lua
        <If "env('PHP_VERSION') == '7'">
        <Files ~ "\.php$">
            SetHandler 'proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost'
        </Files>
        </If>
    </Directory>

    ErrorLog /opt/apache2/logs/jblond_error.log
    TransferLog /opt/apache2/logs/jblond_access.log

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/jblond.example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/jblond.example.com/privkey.pem

    <Files ~"\.(cgi|shtml|phtml|php|htm|html?)$>
        SSLOptions +StdEnvVars
    </Files>
</VirtualHost>

Back to top
gmini



Joined: 22 Dec 2017
Posts: 3
Location: France

PostPosted: Sat 23 Dec '17 18:14    Post subject: Reply with quote

You can really have PHP connect in this syntax ?

Code:
        <If "env('PHP_VERSION') == '7'">
        <Files ~ "\.php$">
            SetHandler 'proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost'
        </Files>
        </If>

Sorry i don't see anything works in this case.
I must inverse tags and the problem become the same (ssl or not). No change :

Code:
        <Files ~ "\.php$">
        <If "env('PHP_VERSION') == '7'">
            SetHandler 'proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost'
        </If>
        </Files>

May be, do you now an other working method to connect several PHP versions from setenv declaration ?
In all cases, thanks JB for trying to help me.
G.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Sat 23 Dec '17 19:11    Post subject: Reply with quote

Well I didn't get php-fpm running today in my VM. Normally I use mod_fcgid ( on windows and linux)

with that is is easier to have multiple php versions running at the same time. And that will work in <If too.

Global fcgid settings

Code:

FcgidMaxProcesses 50
FcgidFixPathinfo 1
FcgidProcessLifeTime 0
FcgidTimeScore 3
FcgidZombieScanInterval 20
FcgidMaxRequestsPerProcess 0
FcgidMaxRequestLen 33554432
FcgidIOTimeout 120


host A
Code:

        AddHandler fcgid-script .php
        FCGIWrapper /usr/bin/php-cgi7.1 .php


Host B
Code:

        AddHandler fcgid-script .php
        FCGIWrapper /usr/bin/php-cgi7.0 .php
Back to top


Reply to topic   Topic: CGI and conditional execute index only (php) View previous topic :: View next topic
Post new topic   Forum Index -> Apache