在Debian系统上配置LNMP(Linux, Nginx, MySQL/MariaDB, PHP)并安装PHPMyAdmin的步骤如下:
首先,确保你的系统包是最新的:
sudo apt update
sudo apt upgrade -y
安装Nginx服务器:
sudo apt install nginx -y
启动并启用Nginx服务:
sudo systemctl start nginx
sudo systemctl enable nginx
安装MariaDB(MySQL的一个分支):
sudo apt install mariadb-server mariadb-client -y
启动并启用MariaDB服务:
sudo systemctl start mariadb
sudo systemctl enable mariadb
运行安全脚本以设置root密码和其他安全选项:
sudo mysql_secure_installation
安装PHP及其常用扩展:
sudo apt install php-fpm php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y
启动并启用PHP-FPM服务:
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
编辑Nginx默认站点配置文件:
sudo nano /etc/nginx/sites-available/default
将以下内容添加到server块中:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
保存并退出编辑器,然后测试Nginx配置:
sudo nginx -t
重新加载Nginx以应用更改:
sudo systemctl reload nginx
更新包列表并安装PHPMyAdmin:
sudo apt update
sudo apt install phpmyadmin -y
在安装过程中,系统会提示你选择Web服务器(选择Nginx),并设置一个用于访问PHPMyAdmin的URL(例如http://your_server_ip/phpmyadmin)。
编辑PHPMyAdmin配置文件以确保安全性和正确性:
sudo nano /etc/phpmyadmin/config.inc.php
确保以下行存在且正确:
$cfg['blowfish_secret'] = 'your_random_string'; // 替换为一个随机字符串
保存并退出编辑器。
重启PHP-FPM和Nginx服务以应用所有更改:
sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx
现在,你应该能够通过浏览器访问http://your_server_ip/phpmyadmin来使用PHPMyAdmin了。
通过以上步骤,你就可以在Debian系统上成功配置LNMP并安装PHPMyAdmin了。