栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Ubuntu 20.04 安装配置nginx + PHP

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Ubuntu 20.04 安装配置nginx + PHP

步骤

## 先清除干净相关的软件,例如apache、php、nginx本身
sudo apt update
sudo apt-get autoremove --purge  php-fpm
sudo apt-get autoremove --purge  apache2
sudo apt-get autoremove --purge  nginx

## 开始安装nginx
sudo apt-get install nginx

## 设置Ubuntu自带的防火墙,允许nginx通信
sudo ufw allow 'Nginx Full'
sudo ufw allow 'Nginx HTTP'
sudo ufw status
## 检查nginx运行情况
service nginx status

## 安装PHP
sudo apt install php-fpm
php -v

## 检查php运行情况,以下的7.4要根据实际情况修改
systemctl status php7.4-fpm
## Enter P to exit
php -v
service nginx status
service nginx restart

## 开始创建nginx虚拟站点
cd /etc/nginx/sites-available/
sudo touch hello.com.conf
=================配置为以下内容,注意其中的php7.4要修改为对应版本=======
server {
    listen 80;
    listen [::]:80;
    root /var/www/;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name hello.com;

    location / {
        try_files $uri $uri/ index.php =404;
    }
    
    location ~ .php$ {
               include snippets/fastcgi-php.conf;
               fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}
====================================

## 注意!以上内容很容易因为奇怪的空格导致无法启动nginx,
## 有需要时,请手动输入以上内容


cd ../sites-enabled/
sudo ln -s ../sites-available/hello.com.conf .
## 重启Nginx服务器
service nginx restart

## 配置Ubuntu虚拟域名
sudo nano /etc/hosts
=================增加以下内容=======
127.0.0.1       hello.com
==================================

ping hello.com
## 看到结果包含127.0.0.1代表成功,Ctrl+C退出


## 开始修改站点内容
sudo touch /var/www/index.php
sudo nano /var/www/index.php
=================配置为以下内容=======
      phpinfo();
====================================

## 打开浏览器,访问http://hello.com/
## 如果可以看到php信息,即可


 

鸣谢

Ubuntu20.04 + Nginx + php7.4 安装配置_alen_feng的专栏-CSDN博客

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号