DeployNginxPHPServer

From FedoraProject

(Difference between revisions)
Jump to: navigation, search
(Introduction)
(updated the index.php as default web page.)
 
Line 24: Line 24:
 
   </li>
 
   </li>
 
   <li>
 
   <li>
     Customize the web root directory by changing the upper into the lower:
+
     Customize the web root directory and adding index.php as default web pages, by changing the upper into the lower:
 
     <pre>
 
     <pre>
 
         location / {
 
         location / {
Line 34: Line 34:
 
         location / {
 
         location / {
 
             root  /var/www/html;
 
             root  /var/www/html;
             index  index.html index.htm;
+
             index  index.html index.htm index.php;
 
         }
 
         }
 
     </pre>
 
     </pre>

Latest revision as of 06:09, 16 August 2012

[edit] Introduction

This is the procedures for deploying a nginx server which supports PHP, with fewest steps and shortest time on Fedora 17. For advanced configurations please check out references from the Internet. Assume root directory of the web site is /var/www/html.

[edit] Procedures

  1. Log in as "root" user:
    $ su -
        
  2. Install required packages and their dependencies:
    $ yum install nginx php-cli php-fpm
        
  3. Open the /etc/nginx/nginx.conf with text editor:
    $ vi /etc/nginx/nginx.conf
        
  4. Customize the web root directory and adding index.php as default web pages, by changing the upper into the lower:
            location / {
                root   html;
                index  index.html index.htm;
            }
        
            location / {
                root   /var/www/html;
                index  index.html index.htm index.php;
            }
        
  5. Enable the PHP by uncomment the following lines:
            location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
            }
        
  6. Customize the root directory of PHP and correct the SCRIPT_FILENAME, by changing the lines in last step into:
            location ~ \.php$ {
                root           /var/www/html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        
  7. Start/restart the nginx service:
    $ systemctl restart nginx.service
        
  8. Start the php-fpm - PHP FastCGI Process Manager:
    $ php-fpm
        
  9. Open ports on the iptables firewall:
    $ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
        
  10. Create a php_info.php in the web site root directory with contents:
    <?php echo phpinfo(); ?>
        
  11. Visit the php_info.php file on the server with web browser for the results.

[edit] PHP-FPM

You can make php-fpm starts when system boot and auto-re-spawn it when it crashed. Check out spawn-fcgi for more information.