Nginx配置php留档

好久没有用过php了,近几日配置nginx+php,留档。

安装

ubunt下nginx和php都可以使用apt安装:

sudo apt install nginx php8

如果想安装最新的php8.2,则需要运行下面语句:

sudo dpkg -l | grep php | tee packages.txt
sudo add-apt-repository ppa:ondrej/php # Press enter when prompted.
sudo apt update
sudo apt install php8.2 php8.2-cli php-8.2{bz2,curl,mbstring,intl}

sudo apt install php8.2-fpm
# OR
# sudo apt install libapache2-mod-php8.2

sudo a2enconf php8.2-fpm

# When upgrading from older PHP version:
sudo a2disconf php8.1-fpm

## Remove old packages
sudo apt purge php8.1*

安装好后,可以使用php -v来查看当前的php版本。

有时候需要重启nginx或者php-fpm服务,使用指令为:

sudo service nginx restart
sudo systemctl restart php8.2-fpm

配置:

配置也很简单,只需要在/etc/nginx/conf.d目录中写一个配置文件,如wow.conf

server {
    listen 80;
    server_name wow.airoot.org;
  
    root /var/www/;  
    index index.php index.html index.htm;
  
    location / {  
        try_files $uri $uri/ =404;
    }  
  
    location ~ \.php$ {  
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;  # 根据你的 PHP-FPM 配置修改  
        fastcgi_index index.php;  
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        include fastcgi_params;  
    }  
  
    location ~ /\.ht {
        deny all;  
    }  
}

测试

在php root目录 /var/www/中,写一个test.php文件:

 <?php
phpinfo();?>

浏览http://wow.airoot.org

若能出现php信息页面,则证明nginx+php配置成功。

后面就可以装比如wordpress套件了。

相关推荐

  1. Nginx配置php

    2024-02-11 12:16:03       28 阅读
  2. 安装Debian 11

    2024-02-11 12:16:03       37 阅读
  3. huanju一台dell机器Ubuntu wifi 故障

    2024-02-11 12:16:03       27 阅读
  4. 笔记本装FreeBSD机器磁盘一直响的解决

    2024-02-11 12:16:03       54 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-11 12:16:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-11 12:16:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-11 12:16:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-11 12:16:03       20 阅读

热门阅读

  1. RuoYi模块功能分析:第八章定时任务

    2024-02-11 12:16:03       26 阅读
  2. P2036 [COCI2008-2009 #2] PERKET题解

    2024-02-11 12:16:03       28 阅读
  3. 学习数据结构和算法的第6天

    2024-02-11 12:16:03       28 阅读
  4. 设计模式-适配器模式 Adapter

    2024-02-11 12:16:03       28 阅读
  5. 应急响应-挖矿木马-常规处置方法

    2024-02-11 12:16:03       26 阅读
  6. 面试心得--面试前应该如何准备

    2024-02-11 12:16:03       21 阅读
  7. 用Python实现刘谦春晚魔术

    2024-02-11 12:16:03       30 阅读
  8. vector如何实现有序数组?

    2024-02-11 12:16:03       25 阅读
  9. VMware16安装CentOS7mini 中遇到的一些问题

    2024-02-11 12:16:03       36 阅读
  10. Linux文本三剑客(1)

    2024-02-11 12:16:03       31 阅读
  11. Python列表中的remove功能及用法举例

    2024-02-11 12:16:03       30 阅读
  12. Linux开发:PAM3 Ubuntu(22.04)安装PAM开发库

    2024-02-11 12:16:03       26 阅读
  13. 贪心算法之田忌赛马,多种语言实现

    2024-02-11 12:16:03       26 阅读