版本比较
标识
- 该行被添加。
- 该行被删除。
- 格式已经改变。
简介
本文内容基于基础的 Debian12 的镜像完成 Nginx+PHP+MySQL 的配置,各组件版本如下表
| 内容 | 版本 | 备注 |
|---|---|---|
| 操作系统 | Debian 12 | 使用清华镜像源 |
| Nginx | 1.29.3 | Nginx 官网源 |
| MySQL | 8.4.7 | Oracle 官网源 |
| PHP | 8.2 | 操作系统源 |

配置操作系统镜像源
系统的安装可以参考 https://wiki.waringid.me/x/MYAYAQ 的内容。系统镜像源的配置如下
| 代码块 | ||
|---|---|---|
| ||
sudo vim /etc/apt/sources.list.d/debian.sources Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/debian Suites: bookworm bookworm-updates bookworm-backports Components: main contrib non-free non-free-firmware Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 # Types: deb-src # URIs: https://mirrors.tuna.tsinghua.edu.cn/debian # Suites: bookworm bookworm-updates bookworm-backports # Components: main contrib non-free non-free-firmware # Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg # 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换 Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security Suites: bookworm-security Components: main contrib non-free non-free-firmware Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg # Types: deb-src # URIs: https://security.debian.org/debian-securty # Suites: bookworm-security # Components: main contrib non-free non-free-firmware # Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg |
完成配置后执行更新操作
配置 Nginx
Nginx 采用官网源更新至最新的版本
| 代码块 | ||
|---|---|---|
| ||
sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list sudo apt update sudo apt install nginx -y nginx -v sudo cat /etc/apt/sources.list.d/nginx.list |
| 代码块 | ||
|---|---|---|
| ||
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian bookworm nginx |
| 代码块 | ||
|---|---|---|
| ||
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
|
配置 Mysql
Mysql 采用官网源更新至 8.4.2 版本。
原计划使用清华源的配置完成数据库的安装,但是更新过程中一直报证书错误,通过其它的方法没法解决该问题。采用官网的源完成更新。
| 代码块 | ||
|---|---|---|
| ||
wget https://dev.mysql.com/downloads/repo/apt/mysql-apt-config_0.8.36-1_all.deb sudo dpkg -i mysql-apt-config_0.8.36-1_all.deb sudo apt update sudo apt install mysql-server sudo mysql_secure_installation sudo cat /etc/apt/sources.list.d/mysql.list |
| 代码块 | ||
|---|---|---|
| ||
deb [signed-by=/usr/share/keyrings/mysql-apt-config.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-apt-config deb [signed-by=/usr/share/keyrings/mysql-apt-config.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-8.4-lts deb [signed-by=/usr/share/keyrings/mysql-apt-config.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-tools deb-src [signed-by=/usr/share/keyrings/mysql-apt-config.gpg] http://repo.mysql.com/apt/debian/ bookworm mysql-8.4-lts |
配置 php
PHP 采用系统自带的源安装
| 代码块 | ||
|---|---|---|
| ||
sudo apt-get install php php-mysql php-cli php-fpm graphviz php-xml php-gd php-zip \ php-ldap php-curl php-mbstring php-json php-apcu php-soap |
需要配置 Nginx 和 PHP 组合,需要调整对应的权限组。默认情况下 Nginx 的启动用户是 Nginx,PHP-FPM 的启动用户是 www-data。两者需要设置一致,否则后续启动访问时会报错。
调整 php.ini 配置
修改 upload_max_filesize 和 post_max_size 的变量设置,调整最大上传的资源限制
| 代码块 | ||
|---|---|---|
| ||
upload_max_filesize = 50M ... post_max_size = 50M60M memory_limit = 256M |
也可以直接通过命令方式修改
| 代码块 | ||
|---|---|---|
| ||
sudo sed -i 's/post_max_size = 8M/post_max_size = 50M/' /etc/php/8.2/fpm/php.ini sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/' /etc/php/8.2/fpm/php.ini sudo sed -i 's/memory_limit = 128M/memory_limit = 256M/' /etc/php/8.2/fpm/php.ini |
调整 php-fpm 配置
| 代码块 | ||
|---|---|---|
| ||
sudo vim /etc/php/8.2/fpm/pool.d/www.conf user = nginx group = nginx listen.owner = nginx listen.group = nginx sudo systemctl restart php8.2-fpm |
整合 Nginx 配置
先创建对应的路径和测试的 php 文件,然后在 Nginx 配置中增加对应的 PHP 配置内容
| 代码块 | ||
|---|---|---|
| ||
sudo mkdir /var/www/html/itop sudo vim /var/www/html/itop/phpinfo.php <?php phpinfo(); ?> sudo chown -R nginx:nginx /var/www/html |
接下来整合 Nginx 配置文件,先创建对应的配置文件
| 代码块 | ||
|---|---|---|
| ||
sudo vim /etc/nginx/conf.d/php.conf |
| 代码块 | ||
|---|---|---|
| ||
server {
listen 80;
server_name app.example.com;
root /var/www/html/itop;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
location ~ /\.ht {
deny all;
}
} |
重启 Nginx 服务后能正常访问 PHP 页面即可

配置 phpMyAdmin
phpMyAdmin 用来通过 web 方式连接数据,它的操作方式非常简单,下载文件后复制到对应的配置目录即可
先下载对应的版本,当前最新版本是 https://files.phpmyadmin.net/phpMyAdmin/5.2.3/phpMyAdmin-5.2.3-all-languages.tar.gz
| 代码块 | ||
|---|---|---|
| ||
tar zxvf phpMyAdmin-5.2.3-all-languages.tar.gz mv phpMyAdmin-5.2.3-all-languages phpadmin sudo mv phpadmin/ /var/www/html/itop sudo cp /var/www/html/itop/phpadmin/config.sample.inc.php /var/www/html/itop/phpadmin/config.inc.php sudo chown -R nginx:nginx /var/www/html/itop/phpadmin suod vim /var/www/html/itop/phpadmin/config.inc.php |
配置文件中添加密码的 HASH 值,如下所示
$cfg['blowfish_secret'] = 'Tc/HfLPBOAPxJ-rhQP}HJoZEK69c3j:m';
完成配置后就可以直接访问了

| 目录 |
|---|