Debian LAMP实现远程管理需分别对Apache、MySQL及系统进行配置,以下是关键步骤:
安装LAMP环境
sudo apt update sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
配置Apache允许远程访问
编辑配置文件 /etc/apache2/apache2.conf
,将 Require local
改为 Require all granted
,重启Apache:
sudo nano /etc/apache2/apache2.conf sudo systemctl restart apache2
配置MySQL远程访问
sudo mysql -u root -p ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'; CREATE USER 'remote_user'@'%' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%'; FLUSH PRIVILEGES;
/etc/mysql/mysql.conf.d/mysqld.cnf
,注释 bind-address = 127.0.0.1
,重启MySQL:sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf sudo systemctl restart mysql
开放防火墙端口
允许HTTP(80)、HTTPS(443)、MySQL(3306)端口:
sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow 3306/tcp sudo ufw enable
远程连接管理
ssh user@服务器IP
连接,执行配置命令。安全建议:禁用root远程登录、使用强密码、定期更新系统。