From Fedora Project Wiki

(init)
 
m (update layout and other small things)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Introduction ==
== 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.
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 online references. Assume root directory of the web site is '''/var/www/html'''.


== Procedures ==
== Procedures ==
<ol>
Log in as "root" user:
  <li>
 
    Log in as "root" user:
$ su -
    <pre>
 
$ su -
Install required packages and their dependencies:
    </pre>
 
  </li>
# yum install nginx php-cli php-fpm
  <li>
 
    Install required packages and their dependencies:
Open the /etc/nginx/nginx.conf file with text editor:
    <pre>
 
$ yum install nginx php-cli php-fpm
# vi /etc/nginx/nginx.conf
    </pre>
 
  </li>
Customize the web root directory and adding index.php as default web pages, by changing the upper into the lower:
  <li>
<pre>
    Open the /etc/nginx/nginx.conf with text editor:
location / {
    <pre>
     root  html;
$ vi /etc/nginx/nginx.conf
    index  index.html index.htm;
     </pre>
}
   </li>
</pre>
   <li>
<pre>
    Customize the web root directory by changing the upper into the lower:
location / {
    <pre>
    root   /var/www/html;
        location / {
    index  index.html index.htm index.php;
            root  html;
}
            index index.html index.htm;
</pre>
 
Enable PHP by uncommenting the following lines:
<pre>
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;
}
</pre>
 
Customize the root directory of PHP and correct the SCRIPT_FILENAME, by changing the lines in last step into:
<pre>
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;
         }
         }
    </pre>
</pre>
    <pre>
 
        location / {
Start/restart the nginx service:
            root  /var/www/html;
 
            index  index.html index.htm;
  # systemctl start nginx.service
        }
 
    </pre>
and enable it:
  </li>
 
  <li>
# systemctl enable nginx.service
    Enable the PHP by uncomment the following lines:
 
    <pre>
Start the php-fpm - PHP FastCGI Process Manager:
        location ~ \.php$ {
 
            root          html;
# systemctl start php-fpm.service
            fastcgi_pass  127.0.0.1:9000;
 
            fastcgi_index index.php;
and enable it:
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 
            include        fastcgi_params;
# systemctl enable php-fpm.service
        }
 
    </pre>
Open the port on the firewall for the incoming connection:
  </li>
 
  <li>
# firewall-cmd --permanent --add-service=http
    Customize the root directory of PHP and correct the SCRIPT_FILENAME, by changing the lines in last step into:
 
    <pre>
and then reload it:
        location ~ \.php$ {
 
            root          /var/www/html;
# firewall-cmd --reload
            fastcgi_pass  127.0.0.1:9000;
 
            fastcgi_index  index.php;
 
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
Create a php_info.php in the web site root directory with contents:
            include        fastcgi_params;
<pre>
        }
<?php
    </pre>
    echo phpinfo();
  </li>
?>
  <li>
</pre>
    Start/restart the nginx service:
 
    <pre>
Visit the php_info.php file on the server with web browser for the results.
$ systemctl restart nginx.service
    </pre>
  </li>
  <li>
    Start the php-fpm - PHP FastCGI Process Manager:
    <pre>
$ php-fpm
    </pre>
  </li>
  <li>
    Open ports on the iptables firewall:
    <pre>
$ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
    </pre>
  </li>
  <li>
    Create a php_info.php in the web site root directory with contents:
    <pre>
<?php echo phpinfo(); ?>
    </pre>
  </li>
  <li>
    Visit the php_info.php file for confirming the results.
  </li>
</ol>


== PHP-FPM ==
== 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.
You can make php-fpm starts when system boot and auto-re-spawn it when it crashed. Check out spawn-fcgi for more information.


[[Category: Kaio]]
[[Category: Web]]
[[Category: Web]]

Latest revision as of 16:52, 14 December 2014

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 online references. Assume root directory of the web site is /var/www/html.

Procedures

Log in as "root" user:

$ su -

Install required packages and their dependencies:

# yum install nginx php-cli php-fpm

Open the /etc/nginx/nginx.conf file with text editor:

# vi /etc/nginx/nginx.conf

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;
}

Enable PHP by uncommenting 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;
}

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;
        }

Start/restart the nginx service:

# systemctl start nginx.service

and enable it:

  1. systemctl enable nginx.service

Start the php-fpm - PHP FastCGI Process Manager:

# systemctl start php-fpm.service

and enable it:

  1. systemctl enable php-fpm.service

Open the port on the firewall for the incoming connection:

# firewall-cmd --permanent --add-service=http

and then reload it:

# firewall-cmd --reload


Create a php_info.php in the web site root directory with contents:

<?php
    echo phpinfo();
?>

Visit the php_info.php file on the server with web browser for the results.

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.