LNMP是指Linux系统下Nginx+MySQL+PHP这种网站服务器架构,通常用于中小型网站服务。以下是在Debian系统上部署LNMP的步骤:
1. 安装Nginx
首先,更新软件包索引并安装Nginx:
sudo apt update sudo apt install nginx
安装完成后,启动Nginx服务并检查其状态:
sudo systemctl start nginx sudo systemctl status nginx
2. 安装MariaDB
安装MariaDB数据库:
sudo apt install mariadb-server
安装完成后,初始化数据库并进行安全配置:
sudo mysql_secure_installation
3. 安装PHP
安装PHP及其常用扩展:
sudo apt install php php-fpm php-mysql
启动PHP-FPM服务并检查其状态:
sudo systemctl start php7.4-fpm sudo systemctl status php7.4-fpm
4. 配置Nginx以处理PHP页面
编辑Nginx的默认配置文件:
sudo vim /etc/nginx/sites-available/default
在配置文件中添加以下内容,以便Nginx可以处理PHP文件:
server { listen 80; server_name localhost; location / { root /var/www/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
修改完成后,重启Nginx服务:
sudo systemctl restart nginx
5. 验证安装
创建一个简单的PHP测试文件以验证LNMP环境是否正常工作:
sudo vim /var/www/html/info.php
在文件中添加以下内容:
保存并退出,然后在浏览器中访问服务器的IP地址或域名,加上/info.php
,例如:http://your_server_ip/info.php
。如果看到PHP的信息页面,则说明LNMP环境配置成功。
以上步骤展示了如何在Debian系统上手动搭建LNMP环境,包括安装Nginx、MariaDB和PHP,并配置Nginx以处理PHP页面。