一、安装PHP 8.2
1.Debian 12 的默认版本是 PHP 8.2。通过运行以下命令来安装它。

# apt install php-fpm php-cli php-pgsql php-mbstring php-xml php-gd

2.检查安装的 PHP 版本

# php --version
PHP 8.2.10 (cli) (built: Sep  4 2023 08:12:29) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies

二、配置PHP-FPM
1.设置文件上传大小限制和PHP内存限制

# vi /etc/php/8.2/fpm/php.ini

upload_max_filesize = 50M
...
post_max_size = 50M
...
memory_limit = 256M

2.配置PHP进程用户和组为Nginx的用户和组

# vi /etc/php/8.2/fpm/pool.d/www.conf
...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx
group = nginx
...
listen.owner = nginx
listen.group = nginx

3.重新启动PHP-fpm进程。

# systemctl restart php8.2-fpm

三、配置Nginx
1.编辑网站配置文件

# vi /etc/nginx/conf.d/test.web.conf

添加以下内容:

    # Pass PHP Scripts To FastCGI Server
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock; #depends on PHP versions
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

2.验证Nginx配置。

# nginx -t

如果你没有看到任何错误,这意味着你可以正常运行了。
3.重启Nginx服务器

# systemctl start nginx

标签: PHP

添加新评论

您是第 68094 位访客