Monday, 27 May 2013

Apache+PHP+Fastcgi on Ubuntu server

1. In order to install Apache2, mod_fcgid, and php5, run
    #apt-get install apache2 apache2-suexec libapache2-mod-fcgid php-cgi
2. If Apache2 was already installed with PHP5 as an Apache2 module, disable the PHP5 module,
     #a2dismod php5
3. Then enable the following modules,
     #a2enmod rewrite
     #a2enmod suexec
     #a2enmod include
     #a2enmod fcgid
4. Open /etc/php5/cgi/php.ini, and uncomment following one line,
     cgi.fix_pathinfo = 1
5. Reload Apache,
    #/etc/init.d/apache2 force-reload
6. Creating Vhost for www.test.com,
           #useradd -s /bin/false -d /var/www/test test
           #mkdir -p /var/www/test/php-fcgi-scripts
           #mkdir -p /var/www/test/www 
           #vi /var/www/test/php-fcgi-scripts/php-fcgi-starter
                       #!/bin/sh
                       PHPRC=/etc/php5/cgi
                       export PHPRC
                       export PHP_FCGI_MAX_REQUESTS=5000
                       export PHP_FCGI_CHILDREN=8
                       exec /usr/lib/cgi-bin/php
      The PHPRC line contains the directory where the php.ini file is located                                         (i.e., /etc/php5/cgi/ translates to/etc/php5/cgi/php.ini). PHP_FCGI_MAX_REQUESTS is  the  maximum number of requests before an fcgid process is stopped and a new one is launched. PHP_FCGI_CHILDREN defines the number of PHP children that will be launched.  
           #chmod 755 /var/www/test/php-fcgi-scripts/php-fcgi-starter
           #chown -R test:test /var/www/test/php-fcgi-scripts
           vi /etc/apache2/sites-available/test
<VirtualHost *:80>
  ServerName www.test.com
  ServerAlias test.com
  ServerAdmin webmaster@test.com
  DocumentRoot /var/www/test/www/

  <IfModule mod_fcgid.c>
    SuexecUserGroup test test
   #PHP_Fix_Pathinfo_Enable 1
    <Directory /var/www/test/www/>
      Options +ExecCGI
      AllowOverride All
      AddHandler fcgid-script .php
      FCGIWrapper /var/www/test/php-fcgi-scripts/php-fcgi-starter .php
      Order allow,deny
      Allow from all
    </Directory>
  </IfModule>

  # ErrorLog /var/log/apache2/error.log
  # CustomLog /var/log/apache2/access.log combined
  ServerSignature Off

</VirtualHost>    
           
       
           #a2ensite test              
7. Reload Apache afterwards:
    #/etc/init.d/apache2 reload



No comments:

Post a Comment