[ubuntu] php-fpm+apache, sites als eigen user draaien*

Pagina: 1
Acties:

Vraag


Acties:
  • 0 Henk 'm!

  • Boudewijn
  • Registratie: Februari 2004
  • Niet online

Boudewijn

omdat het kan

Topicstarter
Hoi

Ik heb een webservertje opgezet met php5-fpm en apache2.4 op Ubuntu. Ik gebruikte altijd mod_php en heb wat issues met permissies. Het gaat hier om wat wordpress websites en die kunnen nu niet naar hun webroot schrijven, wat ivm plugin-updates wel de bedoeling is:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# cat /etc/apache2/sites-available/foo.nl.conf
<VirtualHost *:80>
    ServerAdmin webmaster@foo.nl
    ServerName foo.nl
    ServerAlias www.foo.nl
    DocumentRoot /var/www/www.foo.nl/htdocs
    ErrorLog /var/log/apache/www.foo.nl.error.log
    CustomLog /var/log/apache/www.foo.nl.access.log combined

    <IfModule mod_fastcgi.c>
        AddType application/x-httpd-fastphp5 .php
        Action application/x-httpd-fastphp5 /php5-fcgi
        Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi

        FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi_foo -socket /var/run/php5-fpm_foo.sock -pass-header Authorization
    </IfModule>

</VirtualHost>


code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# cat /etc/php5/fpm/pool.d/foo.nl.conf  | grep -v "^;"  | grep -v "^$"
[foo]
user = foo
group = foo
listen = /var/run/php5-fpm_foo.sock
listen.owner = www-data
listen.group = www-data

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

chdir = /



Nu heb ik de rechten goed gezet (zou niet uit moeten mogen maken...).
root@ip-172-31-15-76:/var/www# chown foo:foo www.foo.nl/ -R
root@ip-172-31-15-76:/var/www# chmod ug+rw www.foo.nl/ -R



Echter blijft de php-code uitgevoerd worden als www-data, wat niet zo zou moeten zijn... blijkens:
PHP:
1
2
3
4
<?php
$processUser = posix_getpwuid( posix_geteuid() );
print_r ($processUser);
?>

Dit levert www-data op.... de user van apache.

Weet iemand waar dit fout gaat? Uiteraard heb ik manuals zoals https://www.linode.com/do...m-on-debian-7-with-apache gelezen.


Het gekke is dat het php-fpm proces wel als foo draait:
code:
1
2
3
4
root@ip-172-31-15-76:/var/www# ps aux | grep php
*knip*
foo      9435  0.0  0.4 221464  4492 ?        S    18:31   0:00 php-fpm: pool foo
foo      9436  0.0  0.4 221464  4492 ?        S    18:31   0:00 php-fpm: pool foo

[ Voor 11% gewijzigd door Boudewijn op 28-05-2016 20:40 ]

i3 + moederbord + geheugen kopen?

Alle reacties


Acties:
  • 0 Henk 'm!

  • Boudewijn
  • Registratie: Februari 2004
  • Niet online

Boudewijn

omdat het kan

Topicstarter
Het lijkt te komen doordat deze:
code:
1
 FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi_foo

Niet bestaat, ondanks dat ik braaf de manual volg.

Eens verder kijken :).
/usr/lib/cgi-bin/php5-fcgi bestaat ook niet...


Ik gebruik weldegelijk sockets:
code:
1
2
3
4
5
6
7
8
root@ip-172-31-15-76:/etc/apache2/sites-available# lsof  -U | grep php
php5-fpm   9720             root    5u  unix 0xffff88003c724600      0t0 54840 socket
php5-fpm   9720             root    6u  unix 0xffff88003c726200      0t0 54841 socket
php5-fpm   9720             root    7u  unix 0xffff88003c727380      0t0 54842 /var/run/php5-fpm_foo1.sock
php5-fpm   9720             root    8u  unix 0xffff88003c722d80      0t0 54845 /var/run/php5-fpm_foo.sock
php5-fpm   9720             root    9u  unix 0xffff88003c726900      0t0 54848 /var/run/php5-fpm.sock
php5-fpm   9720             root   10u  unix 0xffff88003c725080      0t0 54851 /var/run/php5-fpm_foo3.sock
php5-fpm   9720             root   11u  unix 0xffff88003c727700      0t0 54854 /var/run/php5-fpm_foo4.sock

[ Voor 76% gewijzigd door Boudewijn op 28-05-2016 21:25 ]

i3 + moederbord + geheugen kopen?


Acties:
  • 0 Henk 'm!

  • McKaamos
  • Registratie: Maart 2002
  • Niet online

McKaamos

Master of the Edit-button

in Apache wel de ingebouwde PHP module uit gezet? c.q. mod_php.so uitgecomment in de configuratie?
En moet je bij FastCgiExternalServer niet het socket invullen? dus /var/run/php5-fpm.sock (of een van de andere uit je lijstje)

Iemand een Tina2 in de aanbieding?


Acties:
  • 0 Henk 'm!

  • Boudewijn
  • Registratie: Februari 2004
  • Niet online

Boudewijn

omdat het kan

Topicstarter
McKaamos schreef op zaterdag 28 mei 2016 @ 21:38:
in Apache wel de ingebouwde PHP module uit gezet? c.q. mod_php.so uitgecomment in de configuratie?
Dank dat je meekijkt! :)


code:
1
2
3
4
root@ip-172-31-15-76:/etc/apache2/mods-enabled# ls
access_compat.load  alias.conf       authn_core.load  authz_host.load  autoindex.load  dir.conf  fastcgi.conf  mime.conf       mpm_event.load    rewrite.load   status.conf
actions.conf        alias.load       authn_file.load  authz_user.load  deflate.conf    dir.load  fastcgi.load  mime.load       negotiation.conf  setenvif.conf  status.load
actions.load        auth_basic.load  authz_core.load  autoindex.conf   deflate.load    env.load  filter.load   mpm_event.conf  negotiation.load  setenvif.load


Staat dus uit. Net ook even gegrept om te checken of het niet elders gebeurt, mod_php is overigens afaik ook niet geinstalleerd.
root@ip-172-31-15-76:/etc/apache2# dpkg --get-selections   | grep php
php5-common					install
php5-fpm					install
php5-json					install
php5-mysql					install
root@ip-172-31-15-76:/etc/apache2# grep php * -rin
mods-available/dir.conf:2:	DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
mods-available/fastcgi.conf:10: AddType application/x-httpd-fastphp5 .php
mods-available/fastcgi.conf:11: Action application/x-httpd-fastphp5 /php5-fcgi
mods-available/fastcgi.conf:12: Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
mods-available/fastcgi.conf:13: FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization
sites-available/foo.nl.conf:10:        AddType application/x-httpd-fastphp5 .php
sites-available/foo.nl.conf:11:        Action application/x-httpd-fastphp5 /php5-fcgi
sites-available/foo.nl.conf:12:	Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
sites-available/foo.nl.conf:13:        FastCgiExternalServer /var/run/php5-fpm_foo.sock  -socket /var/run/php5-fpm_foo.sock -pass-header Authorization
sites-available/default-ssl.conf:96:		<FilesMatch "\.(cgi|shtml|phtml|php)$">
En moet je bij FastCgiExternalServer niet het socket invullen? dus /var/run/php5-fpm.sock (of een van de andere uit je lijstje)
Nou dat weet ik dus eerlijk gezegd niet. Zit er al even mee te pielen en heb het idee dat het heel simpel is, maar toch...

Ik heb nu deze regel ingevuld, maar dat lijkt me tamelijk raar....
code:
1
        FastCgiExternalServer /var/run/php5-fpm_foo.sock  -socket /var/run/php5-fpm_foo.sock -pass-header Authorization


Voor mijn gevoel wordt inderdaad die hele fcgi spullenboel niet gebruikt oid.

[ Voor 46% gewijzigd door Boudewijn op 28-05-2016 22:25 ]

i3 + moederbord + geheugen kopen?


Acties:
  • 0 Henk 'm!

  • Thralas
  • Registratie: December 2002
  • Laatst online: 30-09 08:10
Het feit dat je www-data ziet zal een gevolg zijn van het feit dat PHP door mod_cgi wordt invoked oid - check desnoods phpinfo(), daar kun je de gebruikte handler zien.

Waarom het niet werkt weet ik ook niet, maar als je Apache 2.4 draait, zou ik mod_fastcgi aan de kant gooien en mod_proxy_fcgi gebruiken. Die laatste is onderdeel van Apache en niet oud/unmaintained (de online documentation van mod_fastcgi lijkt zelfs verdwenen).

Acties:
  • 0 Henk 'm!

  • CAPSLOCK2000
  • Registratie: Februari 2003
  • Laatst online: 12:22

CAPSLOCK2000

zie teletekst pagina 888

Ik heb in het verleden wel met fastcgi gewerkt maar ben, zoals Thralas ook aangeeft, over aan het stappen naar proxy_fcgi voor Apache 2.4, dat lijkt het meeste toekomst te hebben.

        <Files *.php>
                Require all granted
                SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost/"
        </Files>

        <Proxy *>
                Require all granted
        </Proxy>


Om het extra hip te maken wordt die socket door systemd beheerd. PHP wordt pas gestart als er iemand gebruik van wil maken.

[ Voor 5% gewijzigd door CAPSLOCK2000 op 31-05-2016 21:55 ]

This post is warranted for the full amount you paid me for it.


Acties:
  • 0 Henk 'm!

  • Boudewijn
  • Registratie: Februari 2004
  • Niet online

Boudewijn

omdat het kan

Topicstarter
Hmmm dat is wellicht een leuke om eens naar te kijken, dank voor de tip beiden. Ik heb gisteren ook nog even naar apache+php-fpm gekeken, maar krijg niet helemaal helder wat hier fout gaat.

Twijfel nu sterk tussen nginx+php-fpm en apache+ mod_proxy_fcgi.


Op zich is nginx wel charmant, maar ik doe er niet gek veel meer mee en wil vooral even snel de boel weer aan de slag krijgen. Apache is wel weer bekend. Keuzes ... :P

offtopic:
Zonder htaccess kan ik denk ik wel leven ;)

i3 + moederbord + geheugen kopen?


Acties:
  • 0 Henk 'm!

  • Thc_Nbl
  • Registratie: Juli 2001
  • Laatst online: 21-05 22:24
Is mod ruid misschien niet iets waar je wat mee kan.
Deze zit standaard in ubuntu dacht ik. libapache2-mod-ruid2
Meer info hier. https://github.com/mind04/mod-ruid2

groetjes..

ehhh.. noppes


Acties:
  • 0 Henk 'm!

  • Priyantha Bleeker
  • Registratie: Mei 2000
  • Laatst online: 29-09 14:07

Priyantha Bleeker

Out and proud \o/ :D \o/

Ik zelf doe ook alles met PHP-FPM in combinatie met Apache dit op een Ubuntu 14.04 LTS machine.

Alleen maak ik gebruik van TCP sockets i.p.v. Unix sockets die voornamelijk voor de schaalbaarheid.

Zo ziet mijn vhost configuratie eruit:

code:
1
2
3
4
5
<Proxy fcgi://127.0.0.1:9001>
  ProxySet retry=0 timeout=1800
</Proxy>
        ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/var/www/VHOST_NAAM[/public_html/$1
        ProxyPassMatch ^/(fpm-status)$ fcgi://127.0.0.1:9001/fpm-status/$1


En mijn php-fpm pool config ziet er zo uit:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[POOLNAAM]
listen = 127.0.0.1:9001
listen.owner = GEBRUIKERSNAAM
listen.group = GROEPNAAM
user = GEBRUIKERSNAAM
group = GROEPNAAM
pm = dynamic
#pm.max_children = 70
#pm.start_servers = 20
#pm.min_spare_servers = 20
#pm.max_spare_servers = 50
#pm.max_requests = 1500
pm.max_children = 250
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 150
pm.max_requests = 500
listen.backlog = 65536
slowlog = /var/log/php5/fpm-$pool.log.slow
pm.status_path = /fpm-status
ping.path = /ping
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php5/$pool_error.log
php_admin_flag[log_errors] = on
request_slowlog_timeout = 5


Misschien kan je er iets mee ;)
Pagina: 1