facebook twitter hatena line email

「Linux/nginx/php動作」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(Admin がページ「Linux/nginxインストール/php動作」を「Linux/nginx/php動作」に移動しました)
(nginx設定変更)
行9: 行9:
 
==nginx設定変更==
 
==nginx設定変更==
 
nginx.confに以下を追加
 
nginx.confに以下を追加
  location ~ \.php$ {
+
server {
      root /etc/nginx/html;
+
  listen      80;
      fastcgi_pass  127.0.0.1:9000;
+
  server_name 192.168.99.100;
      fastcgi_index  index.php;
+
  root /var/www/html;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+
  index  index.php index.html;
      include        fastcgi_params;
+
  location ~ \.php$ {
}
+
        root /var/www/html;
*/etc/nginx/html/index.php
+
        fastcgi_pass  127.0.0.1:9000;
 +
        fastcgi_index  index.php;
 +
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 +
        include        fastcgi_params;
 +
  }
 +
*/var/www/html/index.php
 
  <?php
 
  <?php
 
  echo 'helloworld'; // helloworld
 
  echo 'helloworld'; // helloworld

2017年2月16日 (木) 00:25時点における版

phpを動作させるには

php-fpmと連携する方法と、apacheからphpを実行する方法があります。

ここではphp-fpmを連携する方法を紹介

php-fpmインストール

linux/phpインストール/php-fpm [ショートカット]

nginx設定変更

nginx.confに以下を追加 server {

  listen       80;
  server_name  192.168.99.100;
  root /var/www/html;
  index  index.php index.html;
  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;
  }
  • /var/www/html/index.php
<?php
echo 'helloworld'; // helloworld

サーバ再起動

$ sudo /etc/init.d/nginx restart
$ sudo /etc/init.d/php-fpm restart