4 月 24, 2026 其它

Ubuntu Server 26.04 LTS 安装mysql8+nginx+php8

# 更新系统
sudo apt update && sudo apt upgrade -y

----- 安装 MySQL 8.0 -----

# 安装 MySQL 服务
sudo apt install mysql-server -y

# 编辑配置
vi /etc/mysql/mysql.conf.d/mysqld.cnf

# 启动并设置开机自启
sudo systemctl start mysql
sudo systemctl enable mysql

# 运行安全配置脚本
sudo mysql_secure_installation

# 登录并修改密码
sudo mysql -u root

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your_strong_password';
FLUSH PRIVILEGES;
EXIT;

----- 安装 Nginx -----

# 安装 Nginx
sudo apt install nginx -y

# 启动并设置开机自启
sudo systemctl start nginx
sudo systemctl enable nginx

----- 安装 PHP -----

# 安装 PHP-FPM 及常用扩展
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y

# 查看PHP版本
php -v

# 启动并设置开机自启(服务名请根据实际安装调整,如 php8.5-fpm)
sudo systemctl start php8.5-fpm
sudo systemctl enable php8.5-fpm

# 配置 Nginx 解析 PHP
sudo vi /etc/nginx/sites-available/default