VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu?comment=198207

⇱ How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu | DigitalOcean


How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu

Updated on November 3, 2025
Not using Ubuntu 22.04?
Choose a different version or distribution.
Ubuntu 22.04
👁 How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu

Introduction

The LEMP software stack serves dynamic web pages and web applications written in PHP. This is an acronym that describes a Linux operating system, with an Nginx (pronounced like “Engine-X”) web server. The backend data is stored in the MySQL database and the dynamic processing is handled by PHP.

This guide demonstrates how to install a LEMP stack on an Ubuntu server. The Ubuntu operating system takes care of the Linux portion of the stack. We will describe how to get the rest of the components up and running.

Note: This tutorial primarily targets Ubuntu 22.04 LTS with PHP 8.1. For Ubuntu 24.04 LTS users, adjust PHP version references from php8.1-fpm to php8.3-fpm throughout the commands. Also, be sure to update any PHP-FPM socket paths in your Nginx configuration (e.g., use /run/php/php8.3-fpm.sock for Ubuntu 24.04).

How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu

  1. Installing the Nginx Web Server
  2. Installing MySQL
  3. Installing PHP
  4. Configuring Nginx to Use the PHP Processor
  5. Testing PHP With Nginx
  6. Testing Database Connection From PHP

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

This comment has been deleted

Unsure if something changed in mysql_secure_installation, but I ran into a strange error:

MySQL Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method doesn’t store authentication data in the MySQL server …

To work around this, login to another session:

sudo killall -9 mysql_secure_installation

start mysql manually, then execute (substituting your own password):

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘WhateverYouWant’;

After that, you can run mysql_secure_installation (but will have to specify the pw) to completion.

Unfortunately, this breaks the subsequent steps of passwordless login as root. I’m not sure what the remedy is, though.

after sudo mysql_secure_installation command, while setting root mysql password i get this error. anyone have idea?

… Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

was unable to complete the mysql installation after multiple attempts. Turns out, 1GB of RAM is required for a droplet, and after adjusting from 512MB, it worked, please update and mention in this guide. Thanks and more power to you.

When I try to start mysql-server, I get an error and am unable to do so after installation. See the below error…

Process: 3897 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)

I think this tutorial needs to be amended since mysql_secure_installation throws an error. More info here under Step 2.

Apr 10 07:04:18 ocean1 systemd[1]: mysql.service: A process of this unit has been killed by the OOM killer.

Apr 10 07:04:18 ocean1 systemd[1]: mysql.service: Main process exited, code=killed, status=9/KILL

Apr 10 07:04:18 ocean1 systemd[1]: mysql.service: Failed with result ‘oom-kill’.

Apr 10 07:04:18 ocean1 systemd[1]: Failed to start MySQL Community Server.

Apr 10 07:04:18 ocean1 systemd[1]: mysql.service: Consumed 1.227s CPU time.

dpkg: error processing package mysql-server-8.0 (–configure):

installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1

Setting up libcgi-pm-perl (4.54-1) …

Setting up libhtml-template-perl (2.97-1.1) …

Setting up libcgi-fast-perl (1:2.15-1) …

Processing triggers for man-db (2.10.2-1) …

Processing triggers for libc-bin (2.35-0ubuntu3.1) …

Errors were encountered while processing:

mysql-server-8.0

needrestart is being skipped since dpkg has failed

E: Sub-process /usr/bin/dpkg returned an error code (1)

Super clear and easy to use. Thank you so much for your excellent work.

👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.