Ubuntu 18.04 搭建LNMP开发环境

nginx/1.14.0安装

  1. 安装nginx

    # 更新apt仓库缓存
    sudo apt-get update
    # 安装nginx
    sudo apt-get install nginx
    # 检查状态
    sudo systemctl status nginx
    
  2. 配置nginx

    查找配置文件:

    sudo find / -name nginx.conf
    sudo vim /etc/nginx/nginx.conf
    

    配置更改:

    # 客户端上传文件大小
    client_max_body_size 20m;
    # 设置网站访问验证
    auth_basic "Please input user and password"; # 验证时的提示信息
    auth_basic_user_file .htpasswd; # 认证文件
    

PHP/5.6安装

  1. 安装php

    # 更新安装源
    sudo add-apt-repository ppa:ondrej/php
    # 更新apt仓库缓存
    sudo apt-get update
    # 查询当前仓库的php版本
    sudo apt-cache show php
    # 安装php5.6
    sudo apt-get install php5.6
    # 安装php5.6拓展
    sudo apt-get php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip
    # 安装php5.6-fpm
    sudo apt-get install php5.6-fpm
    # 检查状态
    sudo systemctl status php5.6-fpm
    
  2. 安装PHP代码解密扩展

    # 将ioncube.tar.gz解压到home目录,执行以下操作
    sudo zxvf ioncube.tar.gz
    sudo mv ~/ioncube/ioncube_loader_lin_5.6.so /usr/lib/php/20131226/
    sudo mv ~/ioncube/00-ioncube.ini /etc/php/5.6/fpm/conf.d
    
  3. 配置php.ini文件

    查找配置文件:

    sudo find / -name php.ini
    sudo vim /etc/php/5.6/fpm/php.ini
    

    配置更改:

    # 允许上传文件大小的最大值
    upload_max_filesize = 20M
    # 通过表单POST给PHP的所能接收的最大值
    post_max_size = 30M
    # php页面占用的最大内存
    memory_limit = 256M
    # php页面执行最大时间
    max_execution_time = 300
    # php页面接受数据最大时间
    max_input_time = 600
    
  4. 卸载apach(防止跟nginx端口冲突,可不操作)

    sudo apt-get --purge remove apache2
    sudo apt-get --purge remove apache2.2-common
    sudo apt-get autoremove
    sudo find  /etc -name "*apache*" -exec  rm -rf {} \;
    

mysql/5.7.32安装

  1. 安装mysql

    # 更新安装源
    sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty main universe'
    # sudo add-apt-repository 'deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse' #备用
    # 更新apt仓库缓存
    sudo apt update
    # 查询当前仓库的mysql版本
    sudo apt-cache show mysql-server
    # 安装当前仓库的mysql版本
    sudo apt install mysql-server -y
    # 安装mysql指定版本
    sudo apt install mysql-server=5.7.32-1ubuntu18.04
    # 检查状态
    sudo systemctl status mysql
    # mysql默认账号密码保存文件路径
    sudo cat /etc/mysql/debian.cnf
    
  2. 配置mysql

    查找配置文件:

    sudo find / -name my.cnf
    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
    

    配置更改:

    # 允许远程配置
    bind-address = 0.0.0.0
    # 在【mysqld】下加入以下配置(解决group by报错解决)
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    group_concat_max_len = 102400
    

系统基础配置和查询

1. 查看版本
# 简单信息
cat /etc/issue
# 具体信息
cat /etc/lsb-release
# 内核信息
uname -a
2. 硬件查询
  1. 查看CPU

    # 查看 CPU 型号和频率
    cat /proc/cpuinfo | grep "model name" | uniq
    # 查看物理 CPU 个数
    cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
    # 查看每个物理 CPU 中 core 的个数 - core - 核数
    cat /proc/cpuinfo | grep "cpu cores" | uniq
    # 查看逻辑 CPU 的个数(正常,逻辑CPU = 物理 CPU 个数 × 每颗核数)
    cat /proc/cpuinfo | grep "processor" | wc -l
    # 查询系统 CPU 是否启用超线程 - HTT(开启,逻辑CPU = 物理 CPU 个数 × 每颗核数 × 2)
    cat /proc/cpuinfo | grep -e "cpu cores"  -e "siblings" | sort | uniq
    
  2. 查看内存

    # 查看内存总数
    cat /proc/meminfo | grep MemTotal
    # 查看内存条数
    sudo dmidecode |grep -A16 "Memory Device$"
    
  3. 查看硬盘

    fdisk -l | grep Disk
    
3. DNS配置
  1. 临时配置

    vim /etc/resolv.conf
    nameserver 114.114.114.114
    nameserver 8.8.8.8
    
  2. 永久配置

    vim /etc/netplan/*.yaml
    network:
      renderer: networkd
      ethernets:
        enp3s0:
          addresses:
            - [10.10.10.2/24]
          gateway4: 10.10.10.1
          nameservers:
              addresses: [10.10.10.1, 1.1.1.1]
      version: 2
    
4. 服务器时间与本地同步
# 查看时区与时间(0800 表示中国北京时间)
date -R
# 修改时区(按顺序选择 亚洲-中国-北京-确定)
tzselect
# 更新本地时区
sudo cp /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
5. 查看服务状态
# 启动服务
sudo systemctl start xxx
# 重启服务
sudo systemctl restart xxx
# 检查服务状态
sudo systemctl status xxx
# 停止服务
sudo systemctl stop xxx
# 设置服务自启动
sudo systemctl enable xxx 
# 取消服务自启动
sudo systemctl disable xxx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值