Author |
|
gmini
Joined: 22 Dec 2017 Posts: 3 Location: France
|
Posted: Fri 22 Dec '17 12:22 Post subject: CGI and conditional execute index only (php) |
|
|
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
|
Posted: Fri 22 Dec '17 17:38 Post subject: |
|
|
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
|
Posted: Sat 23 Dec '17 7:36 Post subject: |
|
|
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
|
Posted: Sat 23 Dec '17 13:12 Post subject: |
|
|
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
|
Posted: Sat 23 Dec '17 18:14 Post subject: |
|
|
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
|
Posted: Sat 23 Dec '17 19:11 Post subject: |
|
|
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 |
|