Seamoonsbird

Seamoonsbird



玩客云手动安装LNMP四件套

Seamoonsbird · 2026-04-27 · 36浏览 · 玩客云



玩客云安装了armbian,开始安装Nginx,MySQL,PHP

换源

  1. 编辑suorces.list

    nano /etc/apt/source.list

    然后,在后面添加以下代码

    # 这四个是中科大源,我不使用所以注释掉了
    #deb http://mirrors.ustc.edu.cn/debian stretch main contrib non-free
    #deb http://mirrors.ustc.edu.cn/debian stretch-updates main contrib non-free
    #deb http://mirrors.ustc.edu.cn/debian stretch-backports main contrib non-free
    #deb http://mirrors.ustc.edu.cn/debian-security/ stretch/updates main contrib non-free
    
    # 此处我使用哈工深源,因为有校园网更方便
    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.osa.moe/debian/ bookworm main contrib non-free non-free-firmware
    # deb-src https://mirrors.osa.moe/debian/ bookworm main contrib non-free non-free-firmware
    
    deb https://mirrors.osa.moe/debian/ bookworm-updates main contrib non-free non-free-firmware
    # deb-src https://mirrors.osa.moe/debian/ bookworm-updates main contrib non-free non-free-firmware
    
    deb https://mirrors.osa.moe/debian/ bookworm-backports main contrib non-free non-free-firmware
    # deb-src https://mirrors.osa.moe/debian/ bookworm-backports main contrib non-free non-free-firmware
    
    # deb https://mirrors.osa.moe/debian-security bookworm-security main contrib non-free non-free-firmware
    # # deb-src https://mirrors.osa.moe/debian-security bookworm-security main contrib non-free non-free-firmware
    
    deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
    # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
  2. 编辑/etc/apt/sources.list.d/armbian.list文件

    nano /etc/apt/sources.list.d/armbian.list

    将原来的每一行内容都在开头处用#号注释掉,然后,添加如下内容

    deb https://mirrors.tuna.tsinghua.edu.cn/armbian stretch main stretch-utils stretch-desktop

    因为哈工深镜像站没有armbian,还是要用清华源。

  3. 执行更新

    apt-get update && apt-get upgrade

安装Nginx/PHP/MySQL

  1. 安装Nginx

    apt-get -y install nginx
  2. 安装PHP

    apt install -y php php-fpm php-mysql php-gd php-curl php-mbstring

    说明:

  3. PHP
    核心运行环境,PHP编程语言解释器
  4. PHP-fpm
    负责接受Nginx转发的PHP请求/执行代码
  5. PHP-MySQL
    连接数据库
  6. PHP-gd
    图像处理库
  7. PHP-curl
    网络请求扩展
  8. PHP-mbstring
    多字节字符串扩展,用于处理中文、日文、特殊字符
  9. 安装MariaDB

    apt install -y mariadb-server
  10. MariaDB是一个能够兼容MySQL的数据库,因为MySQL闭源,对ARM设备兼容差,但作者一样,可以直接替代了
  11. 修改Nginx配置
  12. 打开配置文件

    nano -c /etc/nginx/sites-enabled/default
    这里的nano -c意思是让nano打开文本时显示行号,方便查找所需要修改的行。这里的行号可能会因nginx的版本不同有所变化,根据自己实际的行号找到图中所对应的行进行修改。
  • 根据提示,在第44行后面加上index.php,注释之后,代码如下:

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;
  • 在第56-63行,将第57和61行取消原有#注释,注释后代码如下:

     location ~ \.php$ {
                  include snippets/fastcgi-php.conf;
          #
          #       # With php-fpm (or other unix sockets):
                  fastcgi_pass unix:/run/php/php8.2-fpm.sock;
          #       # With php-cgi (or other tcp sockets):
          #       fastcgi_pass 127.0.0.1:9000;
          }
注意:代码里面的fastcgi_pass unix:/run/php/php8.2-fpm.sock;的PHP版本要和你安装的一致,比如我的就是8.2,查看版本号可以使用ls /run/php/命令。
  1. 重启Nginx

    service nginx restart
  2. 配置MySQL
  3. 重启服务

    service mysqld restart
  4. 使用配置向导

    mysql_secure_installation

    输出如下,根据提示做即可

    Enter current password for root (enter for none):<–初次运行直接回车  
    Switch to unix_socket authentication [Y/n]  
    Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车  
    New password: <– 设置root用户的密码  
    Re-enter new password: <– 再输入一次你设置的密码  
    Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车  
    Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车, 建议 N  
    Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车  
    Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

测试环境

  1. 创建测试文件

    echo "<?php phpinfo(); ?>" >/var/www/html/info.php
  2. 打开网址localhost\info.php其中localhost需要换成服务器IP地址


©

comment 评论区

添加新评论

face表情



  • ©2026 bilibili.com

textsms
内容不能为空
昵称不能为空
email
邮件地址格式错误
web
beach_access
验证码不能为空
keyboard发表评论


star_outline 咱快来抢个沙发吧!




©2026 Seamoonsbird

Theme Romanticism2.2 by Akashi
Powered by Typecho