- 系统:腾讯云 Ubuntu22.04 LTS
- 软件:PHP 8.1.2
- 软件:nginx 1.18.0
安装 PHP
1 | sudo apt install php8.1-fpm |
查看 PHP 版本
1 | php -v |
安装、配置 Nginx
1 | sudo apt install nginx -y |
1 | sudo vim /etc/nginx/sites-enabled/default |
在 server{} 内,找到 index 开头的配置行,在该行中添加 index.php
该配置行应该如下所示:
1 | index index.php index.html index.htm index.nginx-debian.html; |
找到 location ~ \.php$ { 配置行,去除以下配置行的注释符号
注意:并修改php-fpm的配置文件路径,我们这里安装的是php8.1,不是7.4
该配置行应该如下所示:
1 | location ~ \.php$ { |
重启 nginx
1 | sudo systemctl restart nginx |
测试效果
在 /var/www/html 目录下新建 info.php 文件
1 | phpinfo(); |
启动 php-fpm
1 | sudo systemctl start php8.1-fpm |
访问 http://ip/info.php 查看效果