Ubuntu 20.04 安装配置nginx + PHP

57 篇文章 0 订阅

步骤

## 先清除干净相关的软件,例如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
=================配置为以下内容=======
<?php
      phpinfo();
====================================

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


 

鸣谢

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

Ubuntu 20.04安装Notepad需要使用Snap程序包管理器。根据引用和的信息,您可以通过在终端中输入以下命令来安装Notepad: sudo snap install notepad-plus-plus 这将下载并安装Notepad及其所有依赖项。请注意,您需要具有管理员权限才能运行此命令。安装完成后,您可以在应用程序菜单中找到Notepad并开始使用它。 请记住,Notepad是Windows和Mac OS系统上的一个简单但功能强大的代码编辑器,而Ubuntu上的Notepad-plus-plus是为类Unix操作系统提供的兼容版本。如果您对Notepad-plus-plus在Linux上的功能有任何疑问,您可以参考引用中提到的另一个名为Notepadqq的替代编辑器。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Ubuntu 安装 notepad++ 以及 解决中文字体乱码显示 以及 字体倒了的问题](https://blog.csdn.net/jisuanji198509/article/details/118706780)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [如何在Ubuntu 20.04安装NotePad++](https://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/117193524)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rudon滨海渔村

花的越多,赚得越多...

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值