0
0

More than 1 year has passed since last update.

ArchLinux: Nginx で PHP を使う

Posted at

ArchLinux の Nginx の設定ファイルは、/etc/nginx/nginx.conf です。
PHP を使う設定です。

インストール

sudo pacman -S nginx
sudo pacman -S php-fpm

設定ファイル

/etc/nginx/nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /var/www;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        location ~ \.php$ {
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
}

設定ファイルの確認

$ sudo nginx -t
2023/02/13 08:52:58 [warn] 2460#2460: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

再起動

sudo systemctl restart php-fpm
sudo systemctl restart nginx

設定ファイルからコメントを取り除く方法

aw_omit
{if (substr($1,0,1) != "#") print $0}

実行方法

awk -f aw_omit /etc/nginx/nginx.conf

テスト用の PHP プログラム

test_a002.php
<?php phpinfo();
?>
test_a001.php
<?php
	foreach ($_SERVER as $key => $val)
		{
		echo $key . ' : ' . $val . '<br />';
		}
?>

確認した環境

$ uname -a
Linux shimizu 6.1.11-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 09 Feb 2023 20:06:08 +0000 x86_64 GNU/Linux

$ nginx -v
nginx version: nginx/1.22.1

$ php -v
PHP 8.2.2 (cli) (built: Feb  1 2023 08:33:04) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.2, Copyright (c) Zend Technologies
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0