LNMP指的是Linux + Nginx + MySQL + PHP,是将这四个组件安装配置在Linux系统上的一种方法,常用于搭建网站服务器。在Debian系统上实现LNMP的自动化,可以通过编写Shell脚本来完成。以下是一个基本的LNMP自动化安装脚本示例,以及各个组件的安装步骤:
可以使用像中提到的LNMP一键安装包,它是一个用Linux Shell编写的可以为多种Linux发行版(包括Debian)安装LNMP环境的Shell程序。使用这个脚本可以大大简化自动化安装的过程。
sudo apt update
sudo apt install nginx -y
sudo apt install mariadb-server -y
sudo mysql_secure_installation
sudo apt install php-fpm php-opcache php-cli php-gd php-curl php-mysql -y
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com.conf
sudo nano /etc/nginx/sites-available/example.com.conf
在配置文件中添加以下内容:
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
保存并退出编辑器,然后测试Nginx配置文件的语法是否正确:
sudo nginx -t
如果没有错误,重启Nginx服务:
sudo systemctl restart nginx
确保PHP-FPM正在运行:
sudo systemctl status php7.4-fpm
如果服务未运行,启动它:
sudo systemctl start php7.4-fpm
并设置PHP-FPM开机自启动:
sudo systemctl enable php7.4-fpm
以上步骤展示了如何在Debian系统上自动化安装LNMP环境。通过这种方式,你可以快速地在多台服务器上部署LNMP环境,而无需手动执行每个安装命令。