This page looks best with JavaScript enabled

Apache Centos8/PHP7 multi-user

 ·  ☕ 12 min read

Depuis la version 7 de php, suphp ne fonctionne plus.
Pour info, suphp permettait de faire tourner php avec l’uid et le gid du propriĂ©taire du fichier php: IdĂ©al pour sĂ©curiser un hĂ©bergement mutualisĂ© avec plusieurs sites et propriĂ©taires diffĂ©rents.

Voici une mĂ©thode pour faire de mĂȘme avec php7 en php-fpm et les paquets rĂ©mi sous Centos 8 ou/et dĂ©rivĂ© de Redhat 8.

Chaque site est associé à un utilisateur qui publie ses fichiers php avec son uid et gid via un serveur sftp.

Pour chaque site, un groupe de process php-fpm est lancĂ© avec l’uid et gid correspondant Ă  l’utilisateur.

Ainsi un process php d’un site A ne peut pas accĂ©der au process et rĂ©pertoire disque d’un site B. Il en est de mĂȘme avec la publication sftp chrootĂ©.

Installation Centos 8

  • Selinux disabled
  • DĂ©pots tiers
d d d d n n n n f f f f i i c c n n o o s s n n t t f f a a i i l l g g l l - - m m e h a a p t n n e t a a l p g g - s e e r : r r e / l / e r - - a p s s s m e e e s t t . - - - r e e y e n n m a a i b b r l l e e e p d d o . P r n o e e w m t e i / r e T n o t o e l r s p r i s e / r e m i - r e l e a s e - 8 . r p m
  • Paquets php installĂ©s:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
php-common-e7.4.3-1.el8.remi.x86_64
php-fpm-7.4.3-1.el8.remi.x86_64
php-process-7.4.3-1.el8.remi.x86_64
php-pecl-zip-1.17.1-1.el8.remi.7.4.x86_64
php-json-7.4.3-1.el8.remi.x86_64
php-pdo-7.4.3-1.el8.remi.x86_64
php-cli-7.4.3-1.el8.remi.x86_64
php-gd-7.4.3-1.el8.remi.x86_64
php-mbstring-7.4.3-1.el8.remi.x86_64
php-soap-7.4.3-1.el8.remi.x86_64
php-xml-7.4.3-1.el8.remi.x86_64
php-pecl-mysql-1.0.0-0.23.20190415.d7643af.el8.remi.7.4.x86_64
php-mysqlnd-7.4.3-1.el8.remi.x86_64
php-intl-7.4.3-1.el8.remi.x86_64
php-tidy-7.4.3-1.el8.remi.x86_64
Paquets apache installés:
httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64
httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch
centos-logos-httpd-80.5-2.el8.noarch
httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64

Conf sftp only et chroot

Les utilisateurs dans le groupe groupchroot ne peuvent faire que du sftp dans leur répertoire (pas de shell, pas de ssh!)

  • Modification du fichier /etc/ssh/sshd_config
H H H S P A P C G G U X U P A A A A S # M C A X # H M X A C o o o y e u a h S S s 1 s r c c c c u a h l 1 - o a 1 l h s s s s r t s a S S e 1 e i c c c c b t r l 1 - s t 1 l r t t t l m h s l A A P F P n e e e e s c o o F - t c F o o K K K o i o w l P P A o r t p p p p y h o w o - b h o w o e e e g t r o e I I M r i M t t t t s t T r - a r T t y y y F R i r n A C w v o E E E E t G D C w - s G w c D a o z d g u l y a i t n n n n e r i P a - e r a p i / / / c o e A e t e e r l d v v v v m o r F r - d o r F r e e e i t d u R h a s d e u e o d - A u d o e t t t l L K t e e n i g n L L L X s p c r i - u p i r c c c c i o e h s n u n e o A C C M f t w n - t n w t / / / t g y e p t p g S N _ _ O t g o a g - h g g a o s s s y i s n o i C e G P I D p r r r - e r r r s s s n F t n c r y p A D I o y d n - n o n d y h h h A i i s a e e a L P E F i u i o - t u o i / / / U y l c e t d s r C E N I n p % n - i p n / s s s T e e a A i e a _ R T E t c h g - c c g h s s s H s t u o n t C I R e h - a h o h h h P . i t n t i T L F S r r n - t r n m _ _ _ R s o h i o Y C I n o o - i o o e h h h I s n e y a n P _ C a o - o o o o o V h n e l E N A l t - n t s s s / y t s s s A T - - t t t a e i a L M I s - y _ _ _ u s c n n C E O f - e r e e t a o d _ N t - s s c d h t b N L p - a d 2 o i o U C L - _ s 5 r o x M _ C - k a 5 i n E A _ - e _ 1 z R D A - y k 9 e n I D L e _ d o C R L y k _ E e k L S L y e C S A y _ N s T L G I C U M _ A E T G E E L L C E _ P C H O O L N L E A T L E C _ L M C E _ A M S O U N R E E T M A E R N Y T L C _ M E S S A G E S

CrĂ©ation d’un site monsite.fr associĂ© Ă  l’user moi

  • CrĂ©ation de l’user et ajout dans le groupe groupchroot pour le ssh
a u p d s a d e s u r s s m w e o d r d m m - o o G i i g r o u p c h r o o t m o i
  • Modification des droits et crĂ©ation lien symbolique
c m c c l h k h h n o d o m w i w o - n r n d s r m 7 / h o 5 h o o i 5 o t m : m : e r - e r o R / m o m o o t / o t i h i / - o / - p R m p R u e u b / / b / l h m l h i o o i o c m i c m _ e _ e h p h / t m u t m m o b m o l i l l i / i p c u _ v b h a l t r i m / c l w _ w h w t / m h l t m l / m o n s i t e . f r
  • CrĂ©ation du daemon php cloisonnĂ© pour cet user (un fichier par site web)

vi /etc/php-fpm.d/monsite.fr.conf

Exemple:

[ u g # l l l p p p p p # s p p p p p m s r # i i i m m m m m # l h h h h h o e o s s s . . . . o p p p p p n r u L t t t = m s m m T w _ _ _ _ _ s p a e e e a t i a U l a a v v v i = n n n o x a n x N o d d a a a t = s . . n _ r _ _ E g m m l l l e m o = a a d c t s s R i i u u u . o m c c l e h _ p p = n n e e e f i o k l l m i s a a l _ _ [ [ [ r i e v _ o a l e r r e v f s s s ] t a u w n d r e e v a l e e o r s e d r v _ _ l a l a s s a / e d e e s s o r u g s s p r r _ n r e e g / e [ i i . u s c s r r l [ l o o w n l = v v p o e o n n s / = i = e e o g r g . . d p e 5 r r u / r _ s s l h a n 0 3 s s r p o e a a _ p p t h r r v v c - a s = = l p _ r e e a f c e - l o _ _ c p h = 3 3 f o r h p h m e 5 s p g s a a e / , 1 i m ] ] n t _ m n 2 t / d h d o g 7 e w = = l ] i n i . w e = r s n 0 w o r ] i x . - v n ] t 0 s a v = e . l r = a . 1 o / r f w l f v r - o i l a . m g l i r s o / e b o n p s l c s h p i k i p h b t - p e f p . p s h f m e p r s / . m s w l o i s o n o d g s n l i c t a e c . h f e r - e r r o r - t o o . l o g
  • Reload du daemon php

systemctl reload php-fpm

  • Creation du VHOST Dans apache

vi /etc/httpd/conf.d/monsite.fr.conf

S < S D E C # < S # < O A R e V e o r u # F e / # D p l e / / t i r c r s # i t F # i t l q d V E r v u o t # l H i # r i o u i i n t e m r o e a l e o w i r r v u r e L m M s n e M c n O r e t I a N n o L E M d s E t s v e c u f l a t g o T a l M T o e t a N H m R g T t e a T r I r a o l o o e o l R c r t R y n r l r H C s o o l E h c E d i l y o a t m t g o " h e d > s s o s g I p > I v x e g t e * n / s C . r C a e r > : s m I p o I r s A a ^ 8 i a m h x / l n A 0 t r n o L p y L w F l t u > e s n A $ : E w o e t . w i s > u w l d h f w t i S n R / l o r w e t O i E h o r / . e C x P t w i h f . K : E m S z t r f E / R l y a m - r T v T / m t l e - a O m L i / r a # r I o i o m r c # / R n n n o o c # r E s k $ n r e # u i s s _ s # n # t " i l s # / # e ( t o _ p # . . e g l h # f + . o p r ) f g - > " r f c p H o m T m / T m m P o o _ n n A s U i T t H e O . R f I r Z . A s T o I c O k N | = f $ c 1 g i : / / l o c a l h o s t "
  • Reload du daemon apache

systemctl reload httpd

Donc l’idĂ©e de base Ă©tait de cloisonner la publication sftp et l’exĂ©cution du daemon php.
Les conf sont des exemples, cela doit ĂȘtre adaptĂ© au niveau de sĂ©curisation souhaitĂ©, notamment pour Apache (Droit .htaccess, Allow …) et php (disable de commande, max_size …), mais la base est lĂ .

TCHAO


Ghis
WRITTEN BY
Ghis
AdminSys