Products
96SEO 2025-08-28 12:56 1
在Linux上部署LNMP环境,先说说需要准备好以下条件: - 一台Linux服务器 - SSH登录权限 - 开放的80和443端口
Nginx是LNMP环境中的Web服务器,负责处理HTTP请求。
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
MySQL/MariaDB是LNMP环境中的数据库服务器,用于存储网站数据。
sudo apt install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysqlsecureinstallation
PHP是LNMP环境中的脚本语言,用于处理服务器端的逻辑。
sudo apt install php-fpm php-mysql -y
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
为了使Nginx能够处理PHP请求,需要配置Nginx的默认站点配置文件。
sudo nano /etc/nginx/sites-available/default
nginx
server {
listen 80 default_server;
listen :80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILE不结盟E $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
sudo nginx -t
sudo systemctl reload nginx
为了验证LNMP环境是否部署成功,可以创建一个简单的PHP文件并测试它。
info.php
的文件, 并将其放置在/var/www/html/
目录下:
echo "" | sudo tee /var/www/html/info.php
http://your_server_ip/info.php
你应该能看到PHP信息页面。现在你的LNMP环境已经部署完成,你可以开始开发和部署你的Web应用程序了。希望这篇文章能帮助你成功地在Linux上部署LNMP环境!
Demand feedback