= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 H o w   t o   u s e   D j a n g o   w i t h   F a s t C G I 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 W h i l e   t h e   c u r r e n t   p r e f e r r e d   s e t u p   f o r   r u n n i n g   d j a n g o   i s   A p a c h e _   w i t h 
 
 ` m o d _ p y t h o n ` _ ,   f o r   m a n y   u s e r s   o n   s h a r e d   h o s t s   F a s t C G I _   i s   t h e   o n l y   v i a b l e 
 
 o p t i o n .     A l s o ,   f o r   c e r t a i n   s e t u p s   F a s t C G I   a l l o w s   b e t t e r   s e c u r i t y   a n d   p o s s i b l y 
 
 b e t t e r   p e r f o r m a n c e   t h a n   m o d _ p y t h o n . 
 
 
 
 F a s t C G I   i s   a   m e t h o d   o f   h a v i n g   a n   e x t e r n a l   a p p l i c a t i o n   s e r v e   p a g e s   t o   a 
 
 w e b - s e r v e r ,   v i a   a   s o c k e t .     L i k e   m o d _ p y t h o n ,   F a s t C G I   a l l o w s   c o d e   t o   s t a y   i n 
 
 m e m o r y ,   t h u s   a l l o w i n g   r e q u e s t s   t o   b e   s e r v e d   w i t h   n o   s t a r t - u p   t i m e .     U n l i k e 
 
 m o d _ p y t h o n   o r   ` m o d _ p e r l ` _ ,   y o u r   f a s t C G I   p r o c e s s   d o e s   n o t   r u n   i n s i d e   t h e 
 
 w e b - s e r v e r   p r o c e s s ,   b u t   r u n s   a s   a   s e p a r a t e   p e r s i s t e n t   p r o c e s s . 
 
 
 
 . .   _ A p a c h e :   h t t p : / / h t t p d . a p a c h e . o r g / 
 
 . .   _ m o d _ p y t h o n :   h t t p : / / w w w . m o d p y t h o n . o r g / 
 
 . .   _ m o d _ p e r l :   h t t p : / / p e r l . a p a c h e . o r g / 
 
 
 
 . .   a d m o n i t i o n : :   W h y   r u n   c o d e   i n   a   s e p a r a t e   p r o c e s s ? 
 
 
 
         T h e   t r a d i t i o n a l   ` ` m o d _ f o o ` `   t r e n d   i n   a p a c h e   h a s   v a r i o u s   s c r i p t i n g   l a n g u a g e s 
 
         ( s u c h   a s   P H P ,   P y t h o n ,   P e r l )   r u n n i n g   i n s i d e   t h e   p r o c e s s   s p a c e   o f   y o u r   
 
         w e b   s e r v e r .     W h i l e   t h i s   d o e s   a c h i e v e   a   r e d u c t i o n   o f   s t a r t   t i m e ,   i t   c o m e s 
 
         a t   t h e   c o s t   o f   m e m o r y ,   a s   e v e r y   a p a c h e   p r o c e s s   g e t s   i t s   o w n   p y t h o n 
 
         i n t e r p r e t e r ,   w h i c h   w i l l   u s e   u p   a   c o n s i d e r a b l e   a m o u n t   o f   R A M .   D u e 
 
         t o   t h e   n a t u r e   o f   F a s t C G I ,   i t   i s   e v e n   p o s s i b l e   t o   h a v e   p r o c e s s e s   w h i c h   r u n 
 
         u n d e r   a   d i f f e r e n t   u s e r   a s   t h e   w e b   s e r v e r   p r o c e s s .     O n   a   s h a r e d   s y s t e m ,   t h i s 
 
         m e a n s   t h e   a b i l i t y   t o   f u r t h e r   s e c u r e   y o u r   c o d e   f r o m   o t h e r   u s e r s . 
 
 
 
 
 
 S t a r t i n g   y o u r   F a s t C G I   s e r v e r 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 S i n c e   F a s t C G I   o p e r a t e s   o n   a   c l i e n t - s e r v e r   m o d e l ,   i n   m o s t   c a s e s   y o u   w i l l   b e   s t a r t i n g 
 
 t h e   F a s t C G I   p r o c e s s   o n   y o u r   o w n .       Y o u r   w e b s e r v e r   ( b e   i t   A p a c h e ,   L i g H T T P d ,   o r   o t h e r w i s e ) 
 
 w i l l   o n l y   c o n t a c t   y o u r   D j a n g o - F a s t C G I   p r o c e s s   w h e n   i t   n e e d s   a   d y n a m i c   p a g e   t o   b e   l o a d e d . 
 
 S i n c e   y o u r   d a e m o n   i s   a l r e a d y   r u n n i n g   w i t h   t h e   c o d e   i n   m e m o r y ,   i t   w i l l   b e   a b l e   t o   s e r v e   u p 
 
 t h e   r e s p o n s e   v e r y   q u i c k l y . 
 
 
 
 . .   a d m o n i t i o n : :   N o t e 
 
 
 
         T h o s e   w h o   a r e   o n   s h a r e d   h o s t i n g   s y s t e m s   w i l l   p r o b a b l y   b e   f o r c e d   t o   u s e 
 
         w e b s e r v e r - m a n a g e d   F a s t C G I   p r o c e s s e s .     S e e   t h e   s e c t i o n   b e l o w   o n   r u n n i n g   
 
         d j a n g o   w i t h   w e b s e r v e r - m a n a g e d   p r o c e s s e s   f o r   m o r e   i n f o r m a t i o n   o n   t h i s . 
 
 
 
 T h e r e   a r e   t w o   w a y s   t h e   W e b   s e r v e r   c a n   c o n n e c t   t o   y o u r   F a s t C G I   s e r v e r .     I t   c a n   
 
 e i t h e r   u s e   a   u n i x   d o m a i n   s o c k e t   ( n a m e d   p i p e   o n   w i n 3 2   s y s t e m s )   o r   i t   c a n   u s e   a 
 
 T C P   s o c k e t .       W h a t   y o u   c h o o s e   i s   a   m a n n e r   o f   p r e f e r e n c e ;   a   T C P   s o c k e t   i s   u s u a l l y 
 
 e a s i e r   d u e   t o   p e r m i s s i o n i n g   i s s u e s . 
 
 
 
 T o   s t a r t   y o u r   s e r v e r ,   f i r s t   c h a n g e   i n t o   t h e   d i r e c t o r y   o f   y o u r   p r o j e c t   ( w h e r e v e r 
 
 y o u r   ` ` m a n a g e . p y ` `   i s ,   a n d   t h e n   r u n   t h e   m a n a g e . p y   w i t h   t h e   r u n f c g i   o p t i o n : : 
 
 
 
         p y t h o n   m a n a g e . p y   r u n f c g i   [ o p t i o n s ] 
 
 
 
 Y o u   c a n   s p e c i f y   ` ` h e l p ` `   a s   t h e   o n l y   o p t i o n   a f t e r   r u n f c g i ,   a n d   i t   w i l l   p r i n t   o u t 
 
 a   l i s t i n g   o f   a l l   t h e   a v a i l a b l e   o p t i o n s .     Y o u   w i l l   n e e d   t o   s p e c i f y   e i t h e r   a   s o c k e t 
 
 o r   a   h o s t   a n d   p o r t . 
 
 
 
 W h e n   y o u   s e t   u p   y o u r   w e b   s e r v e r ,   y o u   w i l l   n e e d   t o   p o i n t   i t   a t   t h e   h o s t / p o r t   o r 
 
 s o c k e t   y o u   c h o s e   w h e n   s t a r t i n g   t h e   F a s t C G I   s e r v e r . 
 
 
 
 E x a m p l e s 
 
 - - - - - - - - 
 
 
 
 R u n n i n g   a   t h r e a d e d   s e r v e r   o n   a   T C P   p o r t : : 
 
         
 
         . / m a n a g e . p y   r u n f c g i   m e t h o d = t h r e a d e d   h o s t = 1 2 7 . 0 . 0 . 1   p o r t = 3 0 3 3 
 
 
 
 R u n n i n g   a   p r e f o r k e d   s e r v e r   o n   a   U n i x   d o m a i n   s o c k e t : : 
 
 
 
         . / m a n a g e . p y   r u n f c g i   m e t h o d = p r e f o r k   s o c k e t = / h o m e / u s e r / m y s i t e . s o c k   p i d f i l e = d j a n g o . p i d 
 
 
 
 R u n   w i t h o u t   d a e m o n i z i n g   ( b a c k g r o u n d i n g )   t h e   p r o c e s s   ( g o o d   f o r   d e b u g g i n g ) : : 
 
 
 
         . / m a n a g e . p y   r u n f c g i   d a e m o n i z e = f a l s e   s o c k e t = / t m p / m y s i t e . s o c k 
 
 
 
 
 
 S t o p p i n g   t h e   F a s t C G I   d a e m o n 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 I f   y o u   h a v e   t h e   p r o c e s s   r u n n i n g   i n   t h e   f o r e g r o u n d ,   i t ' s   e a s y   e n o u g h   t o   s t o p   i t , 
 
 s i m p l y   h i t t i n g   ` ` C t r l - C ` `   w i l l   c a u s e   t h e   F a s t C G I   s e r v e r   t o   e x i t .     H o w e v e r ,   w h e n 
 
 w e ' r e   d e a l i n g   w i t h   b a c k g r o u n d   p r o c e s s e s ,   y o u   w i l l   n e e d   t o   r e s o r t   t o   t h e   u n i x   
 
 ` ` k i l l ` `   c o m m a n d .     
 
 
 
 I f   y o u   s p e c i f y   t h e   ` ` p i d f i l e ` `   o p t i o n   t o   y o u r   m a n a g e . p y   r u n f c g i ,   y o u   c a n   t h e n   k i l l 
 
 t h e   r u n n i n g   F a s t C G I   d a e m o n   l i k e   t h i s : : 
 
         
 
         k i l l   ` c a t   $ P I D F I L E ` 
 
 
 
 F o r   u n i x   u s e r s ,   t o   e a s i l y   r e s t a r t   y o u r   F a s t C G I   d a e m o n ,   t h i s   s m a l l   
 
 s h e l l   s c r i p t   m a y   b e   o f   u s e : : 
 
 
 
         # ! / b i n / b a s h 
 
 
 
         P R O J D I R = " / h o m e / u s e r / m y p r o j e c t " 
 
         P I D F I L E = " $ P R O J D I R / m y s i t e . p i d " 
 
         S O C K E T = " $ P R O J D I R / m y s i t e . s o c k " 
 
 
 
         c d   $ P R O J D I R 
 
         i f   [   - f   $ P I D F I L E   ] ;   t h e n 
 
                 k i l l   ` c a t   - -   $ P I D F I L E ` 
 
                 r m   - f   - -   $ P I D F I L E 
 
         f i 
 
 
 
         e x e c   / u s r / b i n / e n v   -   \ 
 
             P Y T H O N P A T H = " . . / p y t h o n : . . "   \ 
 
             . / m a n a g e . p y   r u n f c g i   s o c k e t = $ S O C K E T   p i d f i l e = $ P I D F I L E 
 
 
 
         
 
 A p a c h e   S e t u p 
 
 = = = = = = = = = = = = 
 
 
 
 T o   c o n f i g u r e   D j a n g o   w i t h   a p a c h e   a n d   F a s t C G I ,   y o u   m u s t   h a v e   A p a c h e   i n s t a l l e d   
 
 a n d   s e t   u p ,   w i t h   m o d _ f a s t c g i   i n s t a l l e d   a n d   e n a b l e d .     C o n s u l t   y o u r   s e r v e r 
 
 d o c u m e n t a t i o n   f o r   d o i n g   s o . 
 
 
 
 A d d   t h e   f o l l o w i n g   t o   y o u r   h t t p d . c o n f : : 
 
 
 
         #   C o n n e c t   t o   F a s t C G I   v i a   a   s o c k e t   /   n a m e d   p i p e 
 
         F a s t C G I E x t e r n a l S e r v e r   / h o m e / u s e r / p u b l i c _ h t m l / m y s i t e . f c g i   - s o c k e t   / h o m e / u s e r / m y s i t e . s o c k 
 
         #   C o n n e c t   t o   F a s t C G I   v i a   a   T C P   h o s t / p o r t 
 
         #   F a s t C G I E x t e r n a l S e r v e r   / h o m e / u s e r / p u b l i c _ h t m l / m y s i t e . f c g i   - h o s t   1 2 7 . 0 . 0 . 1 : 3 0 3 3 
 
 
 
         < V i r t u a l H o s t   6 4 . 9 2 . 1 6 0 . 9 1 > 
 
             S e r v e r N a m e   m y s i t e . c o m 
 
             D o c u m e n t R o o t   / h o m e / u s e r / p u b l i c _ h t m l 
 
             A l i a s   / m e d i a   / h o m e / u s e r / p y t h o n / d j a n g o / c o n t r i b / a d m i n / m e d i a 
 
             R e w r i t e E n g i n e   O n 
 
             R e w r i t e R u l e   ^ / ( m e d i a . * ) $   / $ 1   [ Q S A , L ] 
 
             R e w r i t e C o n d   % { R E Q U E S T _ F I L E N A M E }   ! - f   
 
             R e w r i t e R u l e   ^ / ( . * ) $   / m y s i t e . f c g i / $ 1   [ Q S A , L ] 
 
         < / V i r t u a l H o s t > 
 
 
 
 N o t e   t h a t   w h i l e   y o u   h a v e   t o   s p e c i f y   a   m y s i t e . f c g i ,   t h a t   t h i s   f i l e   d o e s n ' t 
 
 a c t u a l l y   h a v e   t o   e x i s t .     I t   i s   j u s t   a n   i n t e r n a l   U R L   t o   t h e   w e b s e r v e r   w h i c h   
 
 s i g n i f i e s   t h a t   a n y   r e q u e s t s   t o   t h a t   U R L   w i l l   g o   t o   t h e   e x t e r n a l   F a s t C G I   
 
 s e r v e r . 
 
 
 
 
 
 
 
 L i g H T T P d   S e t u p 
 
 = = = = = = = = = = = = = = 
 
 
 
 L i g H T T P d   i s   a   l i g h t - w e i g h t   a s y n c h r o n o u s   w e b - s e r v e r ,   w h i c h   i s   c o m m o n l y   u s e d 
 
 f o r   s e r v i n g   s t a t i c   f i l e s .     H o w e v e r ,   i t   s u p p o r t s   F a s t C G I   n a t i v e l y ,   a n d   a s   s u c h 
 
 i s   a   v e r y   g o o d   c h o i c e   f o r   s e r v i n g   b o t h   s t a t i c   a n d   d y n a m i c   m e d i a ,   i f   y o u r   s i t e 
 
 d o e s   n o t   h a v e   a n y   a p a c h e - s p e c i f i c   c o m p o n e n t s . 
 
 
 
 M a k e   s u r e   ` ` m o d _ f a s t c g i ` `   i s   i n   y o u r   m o d u l e s   l i s t ,   s o m e w h e r e   a f t e r   
 
 m o d _ r e w r i t e   a n d   m o d _ a c c e s s ,   b u t   n o t   a f t e r   m o d _ a c c e s s l o g .     Y o u ' l l   p r o b a b l y 
 
 w a n t   m o d _ a l i a s   a s   w e l l ,   f o r   s e r v i n g   a d m i n   m e d i a . 
 
 
 
 A d d   t h e   f o l l o w i n g   t o   y o u r   l i g h t t p d   c o n f i g   f i l e : : 
 
 
 
         s e r v e r . d o c u m e n t - r o o t   =   " / h o m e / u s e r / p u b l i c _ h t m l " 
 
         f a s t c g i . s e r v e r   =   ( 
 
                 " / m y s i t e . f c g i "   = >   ( 
 
                         " m a i n "   = >   ( 
 
 	                 #   U s e   h o s t   /   p o r t   i n s t e a d   o f   s o c k e t   f o r   T C P   f a s t c g i 
 
 	 	 #   " h o s t "   = >   " 1 2 7 . 0 . 0 . 1 " , 
 
 	 	 #   " p o r t "     = >   3 0 3 3 , 
 
                                 " s o c k e t "   = >   " / h o m e / u s e r / m y s i t e . s o c k " , 
 
                                 " c h e c k - l o c a l "   = >   " d i s a b l e " , 
 
                         ) 
 
                 ) , 
 
         ) 
 
         a l i a s . u r l   =   ( 
 
                 " / m e d i a / "   = >   " / h o m e / u s e r / d j a n g o / c o n t r i b / a d m i n / m e d i a / " , 
 
         ) 
 
 
 
         u r l . r e w r i t e - o n c e   =   ( 
 
                 " ^ ( / m e d i a . * ) $ "   = >   " $ 1 " , 
 
                 " ^ / f a v i c o n \ . i c o $ "   = >   " / m e d i a / f a v i c o n . i c o " , 
 
                 " ^ ( / . * ) $ "   = >   " / m y s i t e . f c g i $ 1 " , 
 
         ) 
 
 
 
 R u n n i n g   m u l t i p l e   d j a n g o   s i t e s   o n   o n e   L i g H T T P d 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 L i g H T T P d   a l l o w s   y o u   t o   u s e   w h a t   i s   c a l l e d   c o n d i t i o n a l   c o n f i g u r a t i o n   t o   a l l o w 
 
 c o n f i g u r a t i o n   t o   b e   c u s t o m i z e d   p e r - h o s t .     I n   o r d e r   t o   s p e c i f y   m u l t i p l e   f a s t c g i 
 
 s i t e s ,   s i m p l y   a d d   a   c o n d i t i o n a l   b l o c k   a r o u n d   y o u r   f a s t c g i   c o n f i g   f o r   e a c h   s i t e : : 
 
 
 
         $ H T T P [ " h o s t " ]   = =   " w w w . w e b s i t e 1 . c o m "   { 
 
                 s e r v e r . d o c u m e n t - r o o t   =   " / f o o / s i t e 1 " 
 
                 f a s t c g i . s e r v e r   =   ( 
 
 	       . . . 
 
 	 ) 
 
 	 . . . 
 
         } 
 
 
 
         $ H T T P [ " h o s t " ]   = =   " w w w . w e b s i t e 2 . c o m "   { 
 
                 s e r v e r . d o c u m e n t - r o o t   =   " / f o o / s i t e 2 " 
 
                 f a s t c g i . s e r v e r   =   ( 
 
 	       . . . 
 
 	 ) 
 
 	 . . . 
 
         } 
 
 
 
 Y o u   c a n   a l s o   r u n   m u l t i p l e   d j a n g o   i n s t a l l a t i o n s   o n   t h e   s a m e   s i t e   s i m p l y   b y   
 
 s p e c i f y i n g   m u l t i p l e   e n t r i e s   i n   t h e   ` ` f a s t c g i . s e r v e r ` `   d i r e c t i v e ,   a d d   o n e 
 
 f a s t c g i   h o s t   f o r   e a c h . 
 
 
 
 
 
 R u n n i n g   D j a n g o   o n   a   s h a r e d - h o s t i n g   p r o v i d e r 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 F o r   m a n y   u s e r s   o n   s h a r e d - h o s t i n g   p r o v i d e r s ,   y o u   a r e n ' t   a b l e   t o   r u n   y o u r   o w n   
 
 s e r v e r   d a e m o n s   n o r   d o   t h e y   h a v e   a c c e s s   t o   t h e   h t t p d . c o n f   o f   t h e i r   w e b s e r v e r . 
 
 H o w e v e r ,   i t   i s   s t i l l   p o s s i b l e   t o   r u n   D j a n g o   u s i n g   w e b s e r v e r - s p a w n e d   p r o c e s s e s . 
 
 
 
 
 
 . .   a d m o n i t i o n : :   N o t e 
 
 
 
         I f   y o u   a r e   u s i n g   w e b s e r v e r - m a n a g e d   p r o c e s s e s ,   t h e r e ' s   n o   n e e d   f o r   y o u   
 
         t o   s t a r t   t h e   F a s t C G I   s e r v e r   o n   y o u r   o w n .     A p a c h e   w i l l   s p a w n   a   n u m b e r   
 
         o f   p r o c e s s e s ,   s c a l i n g   a s   i t   n e e d s   t o . 
 
 
 
 
 
 I n   y o u r   w e b   r o o t   d i r e c t o r y ,   a d d   t h i s   t o   a   f i l e   n a m e d   . h t a c c e s s   : : 
 
 
 
         A d d H a n d l e r   f a s t c g i - s c r i p t   . f c g i 
 
         R e w r i t e E n g i n e   O n 
 
         R e w r i t e C o n d   % { R E Q U E S T _ F I L E N A M E }   ! - f   
 
         R e w r i t e R u l e   ^ / ( . * ) $   / m y s i t e . f c g i / $ 1   [ Q S A , L ] 
 
 
 
 
 
 N o w   y o u   m u s t   a d d   a   s m a l l   s h i m   s c r i p t   i n   o r d e r   f o r   a p a c h e   t o   p r o p e r l y 
 
 s p a w n   y o u r   F a s t C G I   p r o g r a m .     C r e a t e   a   m y s i t e . f c g i   a n d   p l a c e   i t   i n   y o u r 
 
 w e b   d i r e c t o r y ,   m a k i n g   i t   e x e c u t a b l e   : : 
 
 
 
         # ! / u s r / b i n / p y t h o n 
 
         i m p o r t   s y s ,   o s 
 
 
 
         #   a d d   a   c u s t o m   p y t h o n p a t h 
 
         s y s . p a t h . i n s e r t ( 0 ,   " / h o m e / u s e r / p y t h o n " ) 
 
 
 
         #   s w i t c h   t o   t h e   d i r e c t o r y   o f   y o u r   p r o j e c t .   ( o p t i o n a l ) 
 
         #   o s . c h d i r ( " / h o m e / u s e r / m y p r o j e c t " ) 
 
 
 
         #   c h a n g e   t o   t h e   n a m e   o f   y o u r   a p p ' s   s e t t i n g s   m o d u l e 
 
         o s . e n v i r o n [ ' D J A N G O _ S E T T I N G S _ M O D U L E ' ]   =   " m y p r o j e c t . s e t t i n g s "   
 
 
 
         f r o m   d j a n g o . c o r e . s e r v e r s . f a s t c g i   i m p o r t   r u n f a s t c g i 
 
         r u n f a s t c g i ( [ " m e t h o d = t h r e a d e d " ,   " d a e m o n i z e = f a l s e " ] ) 
 
 
 
 
 
 R e s t a r t i n g   t h e   s p a w n e d   s e r v e r 
 
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 
 
 I f   y o u   c h a n g e   t h e   c o d e   o f   y o u r   s i t e ,   t o   m a k e   a p a c h e   r e - l o a d   y o u r   d j a n g o   
 
 a p p l i c a t i o n ,   y o u   d o   n o t   n e e d   t o   r e s t a r t   t h e   s e r v e r .     S i m p l y   r e - u p l o a d   o r 
 
 e d i t   y o u r   ` ` m y s i t e . f c g i ` `   i n   s u c h   a   w a y   t h a t   t h e   t i m e s t a m p   o n   t h e   f i l e   
 
 w i l l   c h a n g e .     W h e n   a p a c h e   s e e s   t h a t   t h e   f i l e   h a s   b e e n   u p d a t e d ,   i t   w i l l 
 
 r e s t a r t   y o u r   d j a n g o   a p p l i c a t i o n   f o r   y o u . 
 
 
 
 I f   y o u   h a v e   a c c e s s   t o   a   c o m m a n d   s h e l l   o n   a   u n i x   s y s t e m ,   r e s t a r t i n g   t h e 
 
 s e r v e r   c a n   b e   d o n e   w i t h   t h e   ` ` t o u c h ` `   c o m m a n d : : 
 
         
 
         t o u c h   m y s i t e . f c g i 
 
 