DropVPS Team
Writer: Cooper Reagan
How install LEMP on Ubuntu?

Table of Contents
What you will read?
Setting up a LEMP stack (Linux, Nginx, MySQL, PHP) on an Ubuntu server is a great way to run your websites or web applications efficiently. In this guide, we’ll walk you through the installation process, step-by-step.
Update System Packages
Before installing any new software, it’s always a good practice to update your system to ensure you have the latest security patches and software updates.
sudo apt update
sudo apt upgrade
Install Nginx
Nginx is a powerful and efficient web server. To install it, run the following command:
sudo apt install nginx
Once the installation is complete, you can start and enable Nginx to run on boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Install MySQL
Next, we need to install MySQL, which will serve as our database management system.
sudo apt install mysql-server
After installation, it’s important to run the security script to configure your MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and secure your installation.
Install PHP
Now, let’s install PHP along with the necessary extensions for working with Nginx and MySQL.
sudo apt install php-fpm php-mysql
To check if PHP is installed correctly, use the following command:
php -v
Configure Nginx to Use PHP
Once PHP is installed, we need to configure Nginx to process PHP files. Open the default Nginx configuration file:
sudo nano /etc/nginx/sites-available/default
Look for the following section and update it to look like this:
server {
listen 80;
server_name your_domain_or_IP;
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:/run/php/php7.x-fpm.sock; # Make sure to replace 7.x with your PHP version
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save the file and exit. Then, test the Nginx configuration for syntax errors:
sudo nginx -t
If there are no errors, reload Nginx:
sudo systemctl reload nginx
Start and Enable Services
Finally, start all the services (Nginx, MySQL, PHP) and enable them to run on system boot:
sudo systemctl start nginx
sudo systemctl start mysql
sudo systemctl start php7.x-fpm # Replace with your PHP version
sudo systemctl enable nginx
sudo systemctl enable mysql
sudo systemctl enable php7.x-fpm
Test Your LEMP Stack
To test your LEMP stack, create a simple PHP file in the web root directory:
sudo nano /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
Now, open your web browser and navigate to your server’s IP address or domain name followed by /info.php (e.g., http://your_domain_or_IP/info.php). If everything is set up correctly, you should see the PHP information page. That’s it! You’ve successfully set up a LEMP stack on your Ubuntu server. Enjoy hosting your websites or web applications!