当前位置:首页 » 编程语言 » ubuntunginxphp配置

ubuntunginxphp配置

发布时间: 2025-06-29 23:44:50

A. Debian 11 / Ubuntu 22.04 使用源安装 LEMP 教程


本文将详细介绍在 Debian 11 和 Ubuntu 22.04 系统中通过官方源和第三方源安装 Nginx、php 和 Mysql 的详细教程,并且会根据用户需求选择 PHP 版本,无论您是偏好 Debian 10、Ubuntu 20.04 还是最新版的 22.04。


操作务必在 root 权限下进行,可以通过sudo -i 或 su root 进行切换。首先更新系统并安装必备软件:



  1. 运行以下命令更新并升级系统:
    bash
    apt update && apt upgrade -y && apt dist-upgrade -y
    apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates sudo (对于 Debian 11)


接下来,我们将添加高效稳定的 Nginx 源。推荐使用烧饼博客团队的源:



  1. 添加 Nginx 源 Key:
    bash
    curl -sSL n.wtf/public.key | gpg --dearmor > /usr/share/keyrings/n.wtf.gpg
  2. 添加 Nginx 源至 /etc/apt/sources.list.d:
    bash
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/n.wtf.gpg] mirror-cdn.xtom.com/sb/... $(lsb_release -sc) main" >> /etc/apt/sources.list.d/n.wtf.list
    (国内用户可替换为国内清华 TUNA源)

  3. 更新并安装 Nginx:
    bash
    apt update && apt install nginx-extras -y


然后安装 PHP,这里以 Ondřej Surý 的源为例,针对 Debian 和 Ubuntu 有细微差别:



  1. 区别对待 Debian 和 Ubuntu 的 PHP 安装:
    bash
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/php.gpg] packages.sury.org/php/ $(lsb_release -sc) main" >> /etc/apt/sources.list.d/php.list

  2. 安装 PHP 8.x 版本:
    bash
    apt update && apt install php8.2-fpm php8.2-cli php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-imap php8.2-opcache php8.2-soap php8.2-gmp php8.2-bcmath -y


同样,为其他 PHP 版本做相应替换,并确保 PHP 配置安全。安装完成后,别忘了检查 PHP 版本和配置。


对于 MySQL,Debian 11 以上默认使用 MariaDB,步骤如下:



  1. 添加 MariaDB 源和 GPG Key:
    bash
    curl -sSL mariadb.org/mariadb_rel... | gpg --dearmor > /usr/share/keyrings/mariadb.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mariadb.gpg] mirror-cdn.xtom.com/mar... $(lsb_release -sc) main" >> /etc/apt/sources.list.d/mariadb.list
    (国内替换为清华 TUNA源)

  2. 安装 MariaDB:
    bash
    apt update && apt install mariadb-server


安装过程还包括安全设置和数据库创建。对于 MySQL 8.0 的安装,可按照官方教程进行。


至此,您已成功安装了 LEMP 环境。如有任何问题或需要进一步帮助,请随时在文章下方留言讨论。如果您希望获取更多支持或联系作者,请发送邮件至 [email protected]


热点内容
Android推送系统 发布:2025-06-30 04:26:21 浏览:333
滴滴上传人证 发布:2025-06-30 04:21:21 浏览:572
android游戏地图 发布:2025-06-30 04:08:30 浏览:106
安卓和爱疯哪个好 发布:2025-06-30 04:05:19 浏览:32
投诉功能源码 发布:2025-06-30 04:04:38 浏览:882
rsa加密java解密 发布:2025-06-30 04:04:36 浏览:915
企业支付密码器如何算密码 发布:2025-06-30 03:48:25 浏览:150
java客服 发布:2025-06-30 03:48:25 浏览:882
查看外分密码为什么用不成呢 发布:2025-06-30 03:43:27 浏览:67
饰品的脚本 发布:2025-06-30 03:16:46 浏览:255