8_How to install LEMP stack on Ubuntu VPS_

 

地址:https://www.codewithharry.com/blogpost/lemp-stack-on-ubuntu-20/

 

 

How to install LEMP stack (Linux, Nginx, MySQL, PHP) on Ubuntu 20.04

In this tutorial, we will install the LEMP stack on the ubuntu 20 based server. LEMP consists of Linux, Nginx(pronounced as Engine-x), MySQL for database, and PHP as a backend programming language. Together you can use this combination to host a set of high-performing sites on a single server. I will assume that you have finished the initial server setup as described here on your ubuntu server before installing the LEMP stack on Ubuntu 20.04.

 

 

 

If you are already using some other web server like apache2, it is recommended that you uninstall it or rebuild your server from scratch using the console provided by your hosting provider. DigitalOcean gives a convenient way to achieve this in its dashboard.

Let's install the LEMP stack now. Follow the steps below:

Step 1 - Update the server's package index

Update the server's package index by executing the command below:

sudo apt update

 

 

 

Step 2 - Install Nginx

Install Nginx using the command below:

sudo apt install nginx

Step 3 - Allow Nginx through the firewall

Allow Nginx through the firewall using the command below:

sudo ufw app list
sudo ufw allow 'Nginx Full'

You can now go to your server's IP address to check if Nginx is installed successfully. You should see a page like this:

 

 

 

Step 4 - Installing MySQL

Let's install MySQL using the command below:

sudo apt install mysql-server

This command will install MySQL, and you will be able to see the console by entering "sudo mysql" in the terminal.

sudo mysql

Step 5 - Installing PHP

The last component in the LEMP stack is PHP. Let's install it using the command below:

sudo apt install php-fpm php-mysql

If you want to host a PHP website, you will have to copy your files to '/var/www/html' and modify the file located at '/etc/nginx/sites-available/default' to look something like this:

 

 

 

these are the additional lines added inside the "location ~ \.php$ {" block

include fastcgi_params;
fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

Here is a sample index.php site for you to try out:

<?php
phpinfo();
?>

Once you visit the IP of your droplet, you will see a page like this:

You will now be able to use PHP with Nginx. Happy coding!

 

 

 

 

posted @   漫漫长路</>  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示