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 進行切換。首先更新系統並安裝必備軟體:
- 運行以下命令更新並升級系統:
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 源。推薦使用燒餅博客團隊的源:
- 添加 Nginx 源 Key:
bash
curl -sSL n.wtf/public.key | gpg --dearmor > /usr/share/keyrings/n.wtf.gpg - 添加 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源) - 更新並安裝 Nginx:
bash
apt update && apt install nginx-extras -y
然後安裝 PHP,這里以 Ondřej Surý 的源為例,針對 Debian 和 Ubuntu 有細微差別:
- 區別對待 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 - 安裝 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,步驟如下:
- 添加 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源) - 安裝 MariaDB:
bash
apt update && apt install mariadb-server
安裝過程還包括安全設置和資料庫創建。對於 MySQL 8.0 的安裝,可按照官方教程進行。
至此,您已成功安裝了 LEMP 環境。如有任何問題或需要進一步幫助,請隨時在文章下方留言討論。如果您希望獲取更多支持或聯系作者,請發送郵件至 [email protected]。
熱點內容