Nodjoy

只做了一点微小的工作


  • 首页

  • 技术

  • 笔记

  • 杂记

  • 分享

  • 归档

  • 关于

  • 站点监控

  • 服务监控

  • 搜索

  • GitHub

  • Instagram

  • Weibo

  • Email

  • Bilibili

  • Bento

  • 抖音

  • 打赏

  • 在线笔记

  • 在线文档

  • 域名证书管理

  • 云盘

  • Download Hub

  • DockerHub Mirror

  • Harbor

  • Quick Reference

  • Linux 命令查询

  • Mock 模拟数据

  • 文档预览服务
友链
  • milu杰克
  • 小菜
close

Ubuntu搭建LNMP环境

时间: 2021-11-10   |   分类: 技术     |   阅读: 351 字 ~1分钟

安装Nginx

    sudo apt install nginx

安装MySQL

    sudo apt install mysql-server-5.7

添加php源

    sudo add-apt-repository ppa:ondrej/php
    sudo apt update

也可以使用ppa国内源

    deb https://launchpad.proxy.ustclug.org/ondrej/php/ubuntu focal main

安装PHP

    sudo apt install php7.4
    sudo apt install php7.4-fpm

安装PHP扩展

    sudo apt install php7.4-xml php7.4-json php7.4-mysql php7.4-curl php7.4-gd php7.4-pdo php7.4-mbstring php7.4-mysqlnd php7.4-bcmath php7.4-zip php7.4-fileinfo php7.4-redis

设置MySQL用户名密码

    #查看初始用户名和密码
    cd /etc/mysql
    sudo cat debian.cnf
    #使用初始用户名密码登录mysql
    mysql -udebian-sys-maint -pGIOyPu42YoZEwRTe
    #设置密码
    use mysql;
    update mysql.user set authentication_string='yourpassword' where user='root' and Host ='localhost';
    update user set plugin="mysql_native_password" where user='root';
    #设置允许远程登录
    update user set host="%" where user='root';
    flush privileges;
    quit;

配置Nginx多域名访问

进入/etc/nginx/conf.d目录

    cd /etc/nginx/conf.d

新建站点配置

    sudo vi mysite.com.conf
    server {
        listen 80;
        listen 443 ssl http2;
        server_name .tp5.test;
        root /www/mysite.com/public;
    
        index index.html index.htm index.php;
    
        charset utf-8;
        client_max_body_size 1000M;
    
        location / {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
            
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        access_log off;
        error_log  /var/log/nginx/tp5.test-error.log error;
    
        sendfile off;
    
        location ~ \.php(.*)$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
            fastcgi_intercept_errors off;
            fastcgi_buffer_size 16k;
            fastcgi_buffers 4 16k;
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
        }
    
        location ~ /\.ht {
            deny all;
        }
    
        ssl_certificate     /etc/ssl/certs/mysite.com.crt;
        ssl_certificate_key /etc/ssl/certs/mysite.com.key;
    }

检查配置文件并重启Nginx

    sudo nginx -t
    sudo nginx -s reload

喜欢这篇文章的话 打赏一下吧!

Wechat Alipay

#LNMP# #PHP#
使用rpmbuild制作rpm包
记一次Docker mysql容器在windows虚拟机无法启动问题
  • 文章目录
  • 站点概览
Nodjoy

Nodjoy

Developer & Acceleration Engineer⏩

GitHub Instagram Weibo Email Bilibili Bento 抖音 打赏
52 日志
4 分类
64 标签
工具站
在线笔记 在线文档 域名证书管理 云盘 Download Hub DockerHub Mirror Harbor Quick Reference Linux 命令查询 Mock 模拟数据 文档预览服务
友情链接
  • milu杰克
  • 小菜
  • 进入/etc/nginx/conf.d目录
  • 新建站点配置
  • 检查配置文件并重启Nginx
京ICP备17004223号 © 2020 - NODJOY.
Powered by - HUGO
Theme by - NexT
访客量 -
0%