安装LNMP(Linux、Nginx、MySQL、PHP)环境在Ubuntu上可以按照以下步骤进行:
更新APT软件包列表:sudo apt update安装Nginx:sudo apt install nginx启动Nginx服务并设置开机自启动:sudo systemctl start nginxsudo systemctl enable nginx安装MySQL数据库服务器:sudo apt install mysql-server在安装过程中会提示设置MySQL的root密码等配置信息。
启动MySQL服务并设置开机自启动:sudo systemctl start mysqlsudo systemctl enable mysql安装PHP及相关扩展:sudo apt install php-fpm php-mysql配置Nginx以支持PHP:编辑Nginx配置文件:
sudo nano /etc/nginx/sites-available/default在server{}块中添加以下内容:
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;}保存并关闭文件,重新加载Nginx配置:
sudo systemctl reload nginx测试LNMP环境:在/var/www/html/目录下创建一个PHP测试文件:
sudo nano /var/www/html/info.php在文件中添加以下内容:
<?phpphpinfo();?>保存并关闭文件,然后在浏览器中访问http://服务器IP/info.php,如果能够正常显示PHP信息,则安装成功。
以上就是在Ubuntu上安装LNMP环境的步骤。




