Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-04-02 Thread Alexander Farber
Yes, Simone, I will try to test it, but that will take me few days :-)

On Wed, Apr 1, 2020 at 3:03 PM Simone Bordet  wrote:

>
> Implementing #4375 was trivial and I tested it.
> Would you be able to test it on your configuration by building Jetty
> yourself?
>
>
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-04-01 Thread Simone Bordet
Hi,

On Wed, Apr 1, 2020 at 11:59 AM Alexander Farber
 wrote:
> Thank you - I have created 
> https://github.com/eclipse/jetty.project/issues/4735
>
> Your suggestion for creating a custom FarberFCGIServlet  - is it to set 
> $_SERVER['COUNTRY'] inside the PHP scripts?

Correct. The FarberFCGIServlet will read an environment variable from
the Jetty process and add it to every request sent to the PHP process.
The PHP process can then use $_SERVER[name] to retrieve that value.

> And also - how to add the custom FarberFCGIServlet  to the Jetty instances, 
> which are currently being run by the command below?
>
> ExecStart=/usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar 
> /usr/share/java/jetty-distribution-9.4.27.v20200227/start.jar 
> jetty.home=/usr/share/java/jetty-distribution-9.4.27.v20200227 
> jetty.base=/var/www/jetty-base-en jetty.http.host=127.0.0.1 
> jetty.http.port=8082

You have to replace the FastCGIProxyServlet you have in your
wordsbyfarber.com.xml with FarberFCGIServlet.
And you have to put the jar containing FarberFCGIServlet in $JETTY_HOME/lib.

Implementing #4375 was trivial and I tested it.
Would you be able to test it on your configuration by building Jetty yourself?

-- 
Simone Bordet

http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-04-01 Thread Alexander Farber
Hello Simone -


On Tue, Mar 31, 2020 at 11:51 PM Simone Bordet  wrote:

> What you can do right now is to override this:
>
> class FarberFCGIServlet extends FastCGIProxyServlet {
>   protected void customizeFastCGIHeaders(Request proxyRequest,
> HttpFields fastCGIHeaders) {
> super.customizeFastCGIHeaders(proxyRequest, fastCGIHeaders);
> fastCGIHeaders.put("COUNTRY", System.getenv("COUNTRY"));
> ...
>   }
> }


Thank you - I have created
https://github.com/eclipse/jetty.project/issues/4735

Your suggestion for creating a custom FarberFCGIServlet  - is it to set
$_SERVER['COUNTRY'] inside the PHP scripts? Because currently that variable
is not there. Or how would I be able to retrieve the fastCGIHeaders from
PHP?

And also - how to add the custom FarberFCGIServlet  to the Jetty instances,
which are currently being run by the command below?

ExecStart=/usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar
/usr/share/java/jetty-distribution-9.4.27.v20200227/start.jar
jetty.home=/usr/share/java/jetty-distribution-9.4.27.v20200227
jetty.base=/var/www/jetty-base-en jetty.http.host=127.0.0.1
jetty.http.port=8082

Best regards
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-03-31 Thread Simone Bordet
Hi,

On Tue, Mar 31, 2020 at 9:34 PM Alexander Farber
 wrote:
> The above stuff works well, but now I am also trying to pass some 
> configuration information to the few PHP scripts I am also running - and 
> unfortunately this does not work - when I print($_ENV['COUNTRY'); in the PHP 
> scripts, the env. variable is not there.

This is not possible since they belong to 2 different processes.
The one that has the env variables set is a Java process (Jetty), the
one that runs PHP is php-fpm.

> Is there please a way to pass the env. vars from Jetty process to the PHP 
> scripts run through FastCGI?

This is currently not possible out of the box.

It is common, however, to pass FastCGI variables along with the
request, and these can be retrieved in PHP via e.g.
$_SERVER['COUNTRY'] or getenv('COUNTRY') but *not* $_ENV['COUNTRY'].

What we can do is to allow to configure init-param names in
FastCGIProxyServlet, and then we can read those names and forward them
to PHP.
Please file an issue at https://github.com/eclipse/jetty.project/issues.

Something like:


  envNames
  COUNTRY, DOMAIN, ...


and we call System.getenv("COUNTRY"), etc.

What you can do right now is to override this:

class FarberFCGIServlet extends FastCGIProxyServlet {
  protected void customizeFastCGIHeaders(Request proxyRequest,
HttpFields fastCGIHeaders) {
super.customizeFastCGIHeaders(proxyRequest, fastCGIHeaders);
fastCGIHeaders.put("COUNTRY", System.getenv("COUNTRY"));
...
  }
}

-- 
Simone Bordet

http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


[jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

2020-03-31 Thread Alexander Farber
Hello and good evening,

on a CentOS Linux server I run 3 instances of Jetty on 3 different IP
addresses, serving a servlet and  Wordpress in 3 different languages:
English, German, Russian.

The Wordpress installations are configured exactly as described at
https://www.eclipse.org/jetty/documentation/current/configuring-fastcgi.html

And the Jetty instances are started by /etc/systemd/system/jetty-en.service
(and jetty-de.service at port 8081, jetty-ru.service at 8080):

[Unit]
Description=Jetty
After=network-online.target

[Service]
Environment=COUNTRY=en
Environment=DOMAIN=wordsbyfarber.com
Environment=DATABASE_URL=jdbc:postgresql://
127.0.0.1:6432/my_database_en?user=my_user_en=my_user_password
Environment=FCM_SECRET=
Environment=AMAZON_ID=
Environment=AMAZON_SECRET=
Environment=FACEBOOK_ID=
Environment=FACEBOOK_SECRET=
Type=simple
User=jetty
Group=jetty
ExecStart=/usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar
/usr/share/java/jetty-distribution-9.4.27.v20200227/start.jar
jetty.home=/usr/share/java/jetty-distribution-9.4.27.v20200227
jetty.base=/var/www/jetty-base-en jetty.http.host=127.0.0.1
jetty.http.port=8082
SuccessExitStatus=143
Restart=always
RestartSec=180
PrivateTmp=true

[Install]
WantedBy=multi-user.target

As you can see above I pass some information through the env. variables to
the custom Java servlet of my word game.

The above stuff works well, but now I am also trying to pass some
configuration information to the few PHP scripts I am also running - and
unfortunately this does not work - when I print($_ENV['COUNTRY'); in the
PHP scripts, the env. variable is not there.

Is there please a way to pass the env. vars from Jetty process to the PHP
scripts run through FastCGI?

The reason why I am asking is that I am trying to reuse as much source code
(Java, PHP, Javascript) while serving my word game in 3 different languages.

Thank you
Alex

PS: Below is my Jetty config xml file:

# cat /var/www/jetty-base-en/webapps/wordsbyfarber.com.xml


http://www.eclipse.org/jetty/configure_9_3.dtd;>



/var/www/html/wordsbyfarber.com


/





wordsbyfarber.com
www.wordsbyfarber.com





index.php
index.html




org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter
/*






files
$path /index.php?p=$path






default


org.eclipse.jetty.servlet.DefaultServlet



dirAllowed
false


gzip
true



/



org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet
*.php

proxyTo
http://localhost:9000


prefix
/


scriptRoot



scriptPattern
(.+?\\.php)



___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users