在ArchLinux上,使用Nginx来执行PHP

ArchLinux上的Nginx配置文件位于/etc/nginx/nginx.conf。
这是一个使用PHP的配置。

安装

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

设置文件

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

从设置文件中删除注释的方法。

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

执行方式 (shí shì)

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

用于测试的 PHP 程序

<?php phpinfo();
?>
<?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
广告
将在 10 秒后关闭
bannerAds