{"id":3063,"date":"2026-10-26T11:36:14","date_gmt":"2026-10-26T11:36:14","guid":{"rendered":"https:\/\/ukspeed.co.uk\/blog\/how-to-set-up-lemp-stack-uk-vps-nginx-mysql-php-2026\/"},"modified":"2026-10-26T11:57:24","modified_gmt":"2026-10-26T11:57:24","slug":"how-to-set-up-lemp-stack-uk-vps-nginx-mysql-php-2026","status":"publish","type":"post","link":"https:\/\/ukspeed.co.uk\/blog\/how-to-set-up-lemp-stack-uk-vps-nginx-mysql-php-2026\/","title":{"rendered":"How to Set Up a LEMP Stack on a UK VPS (Nginx + MySQL + PHP) in 2026"},"content":{"rendered":"\n<div class=\"uks-toc\"><strong>Table of Contents<\/strong><ol><li><a href=\"#sec-1\">LEMP Stack Explained: What It Is and Why Run It on a VPS<\/a><\/li><li><a href=\"#sec-2\">LEMP vs LAMP: Why Nginx Instead of Apache<\/a><\/li><li><a href=\"#sec-3\">Prerequisites Before You Begin<\/a><\/li><li><a href=\"#sec-4\">Step 1: Install and Configure Nginx<\/a><\/li><li><a href=\"#sec-5\">Step 2: Install MySQL and Secure It<\/a><\/li><li><a href=\"#sec-6\">Step 3: Install PHP-FPM and Connect It to Nginx<\/a><\/li><li><a href=\"#sec-7\">Step 4: Create a Server Block and Test PHP Processing<\/a><\/li><li><a href=\"#sec-8\">Securing and Tuning Your LEMP Stack<\/a><\/li><li><a href=\"#sec-9\">Conclusion<\/a><\/li><\/ol><\/div>\n\n\n\n<p><strong>A LEMP stack is a group of four open-source components \u2014 Linux, Nginx, MySQL and PHP \u2014 that work together to serve fast, dynamic websites and web applications.<\/strong> It is one of the most popular foundations for hosting WordPress, Laravel, and custom PHP projects, and it runs beautifully on a modern UK VPS where you control the full operating system. In this 2026 guide you will build a complete LEMP server from a clean Ubuntu or Debian install, install and connect Nginx, MySQL and PHP, create a working <a href=\"https:\/\/ukspeed.co.uk\/blog\/how-to-transfer-files-to-a-vps-sftp-scp-rsync-2026\/\">server block<\/a>, and finish with the security and tuning steps that matter before you put the site in front of real visitors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-1\">LEMP Stack Explained: What It Is and Why Run It on a VPS<\/h2>\n\n\n<figure class=\"wp-block-image size-large uks-ill\"><img decoding=\"async\" src=\"https:\/\/ukspeed.co.uk\/blog\/wp-content\/uploads\/2026\/10\/lemp-stack-components.svg\" alt=\"LEMP stack: Linux, Nginx, MySQL, PHP\" width=\"860\" height=\"360\" loading=\"lazy\" \/><\/figure>\n\n\n\n\n<p>The name is an acronym: Linux is the operating system, the &#8220;E&#8221; stands for Nginx (pronounced &#8220;engine-x&#8221;), MySQL is the database, and PHP is the scripting language that generates your pages. On a shared hosting plan these layers are hidden from you and tuned for the average customer, but on a VPS you own the whole stack. That means you choose the PHP version, control how many worker processes run, decide which security rules apply, and can squeeze far more performance out of the same hardware. For UK-based sites, running your own LEMP server close to your audience also keeps latency low and gives you predictable resources rather than a noisy shared neighbourhood.<\/p>\n\n\n\n<p>Because every piece is open source, a LEMP stack has no licensing cost, scales from a tiny blog to a high-traffic store, and is supported by a huge community. That combination of control, price and flexibility is exactly why it remains the default choice for serious self-hosting in 2026.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-2\">LEMP vs LAMP: Why Nginx Instead of Apache<\/h2>\n\n\n\n<p>LEMP is the close cousin of the older LAMP stack, where the &#8220;A&#8221; stands for Apache. Both deliver the same end result, but they handle connections very differently. Apache traditionally spawns a process or thread per connection, which is flexible but memory-hungry under load. Nginx uses an event-driven, asynchronous model that handles thousands of simultaneous connections with a small, steady memory footprint, which is why it excels at serving static files and acting as a high-concurrency front end. If you want a deeper comparison against other servers, our guide on <a href=\"https:\/\/ukspeed.co.uk\/blog\/wordpress-on-litespeed-vs-nginx-vs-apache-which-web-server-wins-for-uk-sites-in-2026\/\">WordPress on LiteSpeed vs Nginx vs Apache<\/a> breaks down the trade-offs for UK sites.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Aspect<\/th><th>Nginx (LEMP)<\/th><th>Apache (LAMP)<\/th><\/tr><\/thead><tbody><tr><td>Connection model<\/td><td>Event-driven, asynchronous<\/td><td>Process\/thread per connection<\/td><\/tr><tr><td>Memory under load<\/td><td>Low and stable<\/td><td>Higher as traffic grows<\/td><\/tr><tr><td>Static file serving<\/td><td>Very fast<\/td><td>Good<\/td><\/tr><tr><td>PHP handling<\/td><td>Via PHP-FPM over FastCGI<\/td><td>Built-in module or PHP-FPM<\/td><\/tr><tr><td>Per-directory config<\/td><td>Central config, no .htaccess<\/td><td>Flexible .htaccess files<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Neither choice is wrong, but for a lean, high-traffic VPS the Nginx approach usually wins. The one thing to remember is that Nginx does not process PHP itself \u2014 it hands PHP requests to a separate service called PHP-FPM, which we will wire up later. If you want the wider history of these bundles, the Wikipedia entry on the <a href=\"https:\/\/en.wikipedia.org\/wiki\/LAMP_%28software_bundle%29\" target=\"_blank\" rel=\"noopener\">LAMP software bundle<\/a> also documents the LEMP variant and its origins.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-3\">Prerequisites Before You Begin<\/h2>\n\n\n<figure class=\"wp-block-image size-large uks-ill\"><img decoding=\"async\" src=\"https:\/\/ukspeed.co.uk\/blog\/wp-content\/uploads\/2026\/10\/lemp-setup-steps.svg\" alt=\"LEMP stack setup steps on a VPS\" width=\"860\" height=\"360\" loading=\"lazy\" \/><\/figure>\n\n\n\n\n<p>Before touching any packages, make sure your environment is ready. The commands in this guide target Ubuntu and Debian systems, which use the <code>apt<\/code> package manager; if you are on RHEL, AlmaLinux or Rocky Linux you would use <code>dnf<\/code> instead, and some package names differ slightly. Have the following in place:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A UK VPS running a fresh Ubuntu 24.04 LTS or Debian 12 install.<\/li><li>A non-root user with <code>sudo<\/code> privileges, used for every command below.<\/li><li>SSH access to the server and a terminal on your local machine.<\/li><li>A domain name with its DNS A record pointed at your VPS IP address.<\/li><li>An up-to-date system \u2014 run <code>sudo apt update<\/code> and <code>sudo apt upgrade<\/code> first.<\/li><\/ul>\n\n\n\n<p>With those ready, the full build follows four clear stages:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Install and configure Nginx as the web server.<\/li><li>Install MySQL and lock it down for production.<\/li><li>Install PHP-FPM and connect it to Nginx over FastCGI.<\/li><li>Create a server block and confirm PHP is processed correctly.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-4\">Step 1: Install and Configure Nginx<\/h2>\n\n\n\n<p>Start with the web server. Install it with <code>sudo apt install nginx<\/code>, and once it finishes the service should start automatically. You can confirm it is running with <code>systemctl status nginx<\/code>. If a firewall is already active, allow web traffic so visitors can reach you on ports <code>80<\/code> and <code>443<\/code> \u2014 for example <code>sudo ufw allow 'Nginx Full'<\/code>.<\/p>\n\n\n\n<p>Open your VPS IP address in a browser and you should see the default Nginx welcome page, which confirms the server is listening and serving files. Nginx stores its site definitions in <code>\/etc\/nginx\/sites-available<\/code> and activates them through symbolic links in <code>\/etc\/nginx\/sites-enabled<\/code>. We will come back to that directory to define your own site. For now, the key habit to build is testing before reloading: whenever you change configuration, run <code>sudo nginx -t<\/code> to check the syntax, then apply it with <code>sudo systemctl reload nginx<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-5\">Step 2: Install MySQL and Secure It<\/h2>\n\n\n\n<p>Next comes the database. Install the server with <code>sudo apt install mysql-server<\/code>. The packages set up the service, but the default install leaves several insecure defaults in place, so the very next thing you must run is <code>sudo mysql_secure_installation<\/code>. This interactive tool lets you set a strong root password, remove anonymous accounts, disable remote root login, and drop the test database. Answer yes to the hardening prompts unless you have a specific reason not to.<\/p>\n\n\n\n<p>Once secured, log in with <code>sudo mysql<\/code> and create a dedicated database and user for your application rather than using the root account for day-to-day work. Give that user only the privileges it needs on its own database. If you are weighing which engine to standardise on, our comparison of <a href=\"https:\/\/ukspeed.co.uk\/blog\/mariadb-vs-mysql-vs-postgresql-for-wordpress-in-2026-which-database-wins-on-uk-hosting\/\">MariaDB vs MySQL vs PostgreSQL for WordPress<\/a> explains where each one shines on UK hosting. For most LEMP builds, stock MySQL is a dependable, well-supported default.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-6\">Step 3: Install PHP-FPM and Connect It to Nginx<\/h2>\n\n\n<figure class=\"wp-block-image size-large uks-ill\"><img decoding=\"async\" src=\"https:\/\/ukspeed.co.uk\/blog\/wp-content\/uploads\/2026\/10\/lemp-request-flow.svg\" alt=\"How a request flows through a LEMP stack\" width=\"860\" height=\"320\" loading=\"lazy\" \/><\/figure>\n\n\n\n\n<p>PHP is the component that turns database content into the pages your visitors see. Because Nginx has no built-in PHP module, you install the FastCGI Process Manager and the MySQL driver together with <code>sudo apt install php-fpm php-mysql<\/code>. This gives you a standalone PHP-FPM service that listens on a local socket and waits for Nginx to pass it requests.<\/p>\n\n\n\n<p>The connection works like this: Nginx receives the request, sees that the file ends in <code>.php<\/code>, and forwards it over FastCGI to the PHP-FPM socket. PHP-FPM executes the script, talks to MySQL if needed, and returns the finished HTML for Nginx to send back to the browser. You define that hand-off inside your server block with a <code>location<\/code> directive that points at the PHP-FPM socket \u2014 note the exact socket path, as it includes your installed PHP version. Getting the number of worker processes right matters a great deal on a VPS; our <a href=\"https:\/\/ukspeed.co.uk\/blog\/php-fpm-tuning-guide-how-to-configure-pm-max_children-for-maximum-wordpress-performance-in-2026\/\">PHP-FPM tuning guide<\/a> walks through sizing <code>pm.max_children<\/code> to your available memory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-7\">Step 4: Create a Server Block and Test PHP Processing<\/h2>\n\n\n\n<p>A server block is Nginx&#8217;s equivalent of an Apache virtual host: it tells the server which domain to answer for, where the site files live, and how to handle PHP. Create a new file for your domain inside <code>\/etc\/nginx\/sites-available<\/code>, set its <code>root<\/code> to your web directory such as <code>\/var\/www\/yourdomain<\/code>, list <code>index.php<\/code> in the index line, and add the PHP <code>location<\/code> block that forwards requests to PHP-FPM. Then enable the site by linking it into <code>\/etc\/nginx\/sites-enabled<\/code>.<\/p>\n\n\n\n<p>Validate the configuration with <code>sudo nginx -t<\/code> and, if it reports success, apply it with <code>sudo systemctl reload nginx<\/code>. To prove PHP is being processed rather than downloaded, drop a small <code>info.php<\/code> file containing a single PHP function into your web root and load it in the browser; you should see the PHP information page rendered as HTML. Delete that test file immediately afterwards, because it exposes details about your server that attackers find useful. At this point the whole stack \u2014 Nginx, MySQL and PHP \u2014 is talking end to end.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-8\">Securing and Tuning Your LEMP Stack<\/h2>\n\n\n\n<p>A working LEMP server is only half the job; a production server also has to be safe and fast. Before you point real traffic at it, enable a firewall and move the site onto HTTPS. You can issue a free certificate in minutes \u2014 follow our walkthrough on <a href=\"https:\/\/ukspeed.co.uk\/blog\/how-to-install-free-ssl-with-lets-encrypt-step-by-step-guide-for-2026\/\">installing free SSL with Let&#8217;s Encrypt<\/a> and redirect all plain HTTP on port <code>80<\/code> to encrypted traffic on port <code>443<\/code>. Work through the following checklist:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Enable a firewall (such as <code>ufw<\/code>) and allow only SSH and web ports.<\/li><li>Install a valid TLS certificate and force HTTPS site-wide before going live.<\/li><li>Keep packages patched with regular <code>sudo apt update<\/code> and upgrades.<\/li><li>Run PHP-FPM and MySQL under their own limited users, never as root.<\/li><li>Hide version banners and remove any leftover test or info files.<\/li><li>Tune <code>worker_processes<\/code> in Nginx and PHP-FPM pool settings to your RAM.<\/li><li>Enable Gzip or Brotli compression and sensible static-asset caching.<\/li><\/ul>\n\n\n\n<p>For tuning, match your resources to your workload: set Nginx worker processes to the number of CPU cores, size the PHP-FPM pool so it never exhausts memory, and adjust MySQL&#8217;s buffer settings for the data your application actually uses. Small, measured changes here deliver far more real-world speed than any single &#8220;magic&#8221; setting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sec-9\">Conclusion<\/h2>\n\n\n\n<p>Building a LEMP stack on a UK VPS gives you a fast, flexible and fully owned hosting platform for WordPress and custom PHP apps alike. With Nginx handling connections, MySQL storing your data and PHP-FPM generating pages over FastCGI, you have a lean server you can grow and tune on your own terms. The build itself is straightforward once you understand how the pieces connect, and the habits of testing with <code>sudo nginx -t<\/code> and securing each layer will serve you for years. If you would like us to run this stack for you, see the current options on our official VPS plans page.<\/p>\n\n\n\n<p>What to do next:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Provision a clean Ubuntu or Debian UK VPS and create a sudo user.<\/li><li>Install Nginx, MySQL and PHP-FPM, then wire them together with a server block.<\/li><li>Enable your firewall and install a free Let&#8217;s Encrypt certificate for HTTPS.<\/li><li>Tune PHP-FPM and Nginx worker settings to match your VPS resources.<\/li><li>Deploy your site, remove any test files, and monitor performance.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-group uks-cta-box has-border-color\" style=\"border-color:#bfdbfe;border-width:1px;border-radius:14px;background-color:#eff6ff;padding:28px\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h3 class=\"has-text-color wp-block-heading\" style=\"color:#0f172a\">Ready to run your LEMP stack on a British VPS?<\/h3>\n\n\n<p class=\"has-text-color\" style=\"color:#334155\">UK Speed VPS plans run on AMD EPYC processors and NVMe storage in a UK data center, with full root access, dedicated resources, 24\/7 support, and flexible payment \u2014 the ideal home for your Nginx, MySQL and PHP stack.<\/p>\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-text-color has-background\" href=\"https:\/\/ukspeed.co.uk\/vps-nvme\" style=\"border-radius:10px;background-color:#2563eb;color:#ffffff\">See UK Speed VPS Plans<\/a><\/div>\n<\/div>\n<\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Table of Contents LEMP Stack Explained: What It Is and Why Run It on a VPS LEMP vs LAMP: Why Nginx Instead of Apache\u2026<\/p>\n","protected":false},"author":3,"featured_media":3071,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[33,105],"tags":[143,148,61,146,113,144,141,136,140,139],"class_list":["post-3063","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps-hosting","category-tutorials","tag-database","tag-dns","tag-hosting","tag-linux","tag-performance","tag-php","tag-security","tag-ssl","tag-vps","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/posts\/3063","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=3063"}],"version-history":[{"count":2,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/posts\/3063\/revisions"}],"predecessor-version":[{"id":3078,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/posts\/3063\/revisions\/3078"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/media\/3071"}],"wp:attachment":[{"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=3063"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=3063"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ukspeed.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=3063"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}