What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A LEMP stack on a fresh Linux VPS consists of Linux, Nginx, a MySQL-compatible database such as MariaDB or MySQL, and PHP running through PHP-FPM. The reliable setup sequence is: prepare a non-root account and DNS, update the server, install the packages supplied by your distribution, verify the exact PHP-FPM socket, configure an Nginx server block, harden the database and firewall, then add HTTPS and test every layer.

What a LEMP stack does

LEMP is the common name for a web stack built from Linux, Nginx, a MySQL-compatible database, and PHP. Nginx handles incoming HTTP requests and serves static files such as HTML, CSS, JavaScript, and images. Requests for PHP files are passed to PHP-FPM through FastCGI. PHP-FPM executes the application code, while MariaDB or MySQL stores application data. A browser therefore follows a path such as browser to Nginx to PHP-FPM to the database and back.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Nginx does not use Apache-style .htaccess files. Its site configuration is held in server blocks, the Nginx equivalent of virtual hosts. Each server block can map a domain name to a document root, define URL handling, and select a PHP-FPM socket. A single VPS can run one site or many sites by giving each domain its own server block.

Prerequisites before you install anything

Start with a fresh Ubuntu or Debian VPS and console or SSH access. The following conditions prevent the most common setup failures:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
  • An SSH key is installed for your account, and you can log in without using a shared password.
  • You have a non-root user with sudo privileges. Keep the root account for emergency administration only.
  • Your domain or fully qualified domain name points to the VPS public IPv4 address. Add an IPv6 record only when the VPS is configured to serve IPv6 correctly.
  • You know which ports the provider-level firewall exposes. The provider firewall and the VPS firewall must both allow the traffic you need.
  • You have enough disk space for the operating system, logs, database, backups, and application files.

Package names, service names, PHP versions, and socket paths depend on the release. Examples in published guides range from Ubuntu 18.04-era instructions and Debian 10 or Ubuntu 20.04 tutorials to an Ubuntu 26.04 walkthrough. Treat version-specific strings as examples, not values to copy blindly.

Choose the distribution and database

Ubuntu and Debian both provide Nginx, PHP-FPM, MariaDB or MySQL, and UFW-compatible firewall tooling. Ubuntu releases often make newer application packages available sooner, while Debian emphasizes a conservative package set and a longer stability window. Whichever you choose, use its current repositories and security-update policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision Option What changes for your setup
Operating system Ubuntu Commands use Ubuntu package metadata and the service names supplied by that release; the exact PHP version still varies.
Operating system Debian Commands are similar, but package versions, enabled modules, and default configuration paths can differ.
Database MariaDB MySQL-compatible server commonly available from distribution repositories; use the service and hardening command supplied by the package.
Database MySQL Use the vendor package or distribution package that matches your support requirements and verify its service name before scripting administration.
Package source Distribution repositories Usually the simplest route for security updates and dependency integration.
Package source Official Nginx repository Can provide a different Nginx release cadence, but introduces another repository and its signing and update policy.

For a first VPS, distribution packages are usually easier to maintain. Choose an alternative repository only when you have a specific feature or release requirement and a plan to track its updates.

Connect, update, and install the stack

1. Open an SSH session

Replace the example address and account with your own values:

ssh admin@example-vps-ip

Confirm that the account has administrative access before changing firewall rules:

sudo -v

2. Update package metadata and installed packages

sudo apt update
sudo apt upgrade -y

Reboot if the upgrade installs a new kernel or the provider indicates that a restart is required. Reconnect over SSH after the reboot.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

3. Install Nginx, the database, PHP-FPM, and UFW

A common Debian or Ubuntu package set is:

sudo apt install -y ufw nginx mariadb-server php-fpm php-mysql

If you choose MySQL instead of MariaDB, install the MySQL server package provided for your release. The unversioned php-fpm package deliberately follows the distribution default. The php-mysql extension lets PHP applications use either MySQL-compatible server. Add application-specific PHP extensions only when the application requires them.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth

Start services and find the real PHP-FPM socket

Some packages start automatically; explicitly enabling the services makes them start after a reboot. Service names vary, so inspect the installed units rather than assuming a historical version string.

sudo systemctl enable --now nginx
sudo systemctl enable --now mariadb
systemctl list-units --type=service | grep -E 'php.*fpm'

Check each service:

sudo systemctl status nginx --no-pager
sudo systemctl status mariadb --no-pager
sudo systemctl status php8.3-fpm --no-pager

Replace php8.3-fpm with the PHP-FPM unit actually installed. You can list candidate units with:

systemctl list-unit-files | grep fpm

Locate the Unix socket

Never copy an old path such as /run/php/php7.2-fpm.sock into a current configuration without checking the server. List the runtime directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ls -l /run/php/

Then inspect the pool configuration for its listening value:

grep -R '^listen' /etc/php/*/fpm/pool.d/

You are looking for a line such as listen = /run/php/php8.3-fpm.sock. Record the exact path; the Nginx fastcgi_pass directive must match it character for character. A TCP listener is possible, but a local Unix socket is the normal single-VPS arrangement.

Configure the firewall without locking yourself out

Allow SSH before enabling UFW. If you enable the firewall first, your current session may remain open while every new administrative connection is blocked.

sudo ufw allow 'OpenSSH'
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo ufw enable
sudo ufw status verbose

The HTTPS rule can be added immediately even if the certificate is not installed yet. Do not expose the database port publicly for a normal web application. Keep MariaDB or MySQL listening on localhost unless remote access is an explicit architectural requirement, and then restrict it to known source addresses at both firewall layers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Also check the VPS provider’s network firewall. A host rule for port 443 cannot help if the provider firewall drops that port before traffic reaches the machine.

Harden MariaDB or MySQL

Run the vendor hardening assistant

Run the hardening utility supplied by your database package:

sudo mysql_secure_installation

Use it to remove anonymous accounts, disallow unnecessary remote administrative access, remove test data, and apply the authentication choices appropriate to your release. The exact prompts differ between MariaDB and MySQL versions, so read each prompt instead of accepting a historical answer sequence automatically.

Create an application database and least-privilege user

Do not put the database administrator credentials in a web application’s configuration. Create a separate database and account:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mariadb
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Use a generated password stored in your application’s secret-management method, not in a public repository. Grant only the privileges the application needs. If your package uses the mysql client command rather than mariadb, use that client while keeping the SQL the same.

Create the website directory and permissions

Use a directory named for the domain. The example below keeps the document root at /var/www/example.com/public, which lets you keep deployment files outside the web-accessible directory.

sudo mkdir -p /var/www/example.com/public
sudo chown -R $USER:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} ;
sudo find /var/www/example.com -type f -exec chmod 644 {} ;

Applications that need to write uploads, caches, or compiled templates require a deliberate writable directory. Do not make the entire document root writable by the web process. Set ownership and permissions for only those directories and document why they are writable.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Write an Nginx server block for PHP

Create the configuration

Create /etc/nginx/sites-available/example.com and adjust the domain, root, and socket path:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    root /var/www/example.com/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    location ~ /.ht {
        deny all;
    }
}

Replace php8.3-fpm.sock with the socket you found locally. The distribution’s snippets/fastcgi-php.conf file supplies the standard FastCGI parameters and protects against common path mistakes. On a distribution that stores the snippet elsewhere, locate the equivalent package-provided FastCGI include rather than inventing a path.

The try_files rule serves existing files and directories and returns a 404 for anything else. Frameworks that use a front controller need a framework-specific fallback, often pointing to index.php; use the framework’s documented Nginx configuration instead of changing this rule generically.

Enable the site

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

Removing the default site is appropriate when it would answer requests intended for your domain. If you host several sites, keep the default only when its behavior is intentional. Run nginx -t before every reload or restart; it catches syntax errors without interrupting the currently running configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify static files, PHP, and the database

Test the HTTP listener

Create a small static page:

printf '%sn' 'LEMP is responding' | sudo tee /var/www/example.com/public/index.html

From the VPS or another machine, inspect the response:

curl -I http://example.com

You should receive an HTTP status and Nginx response headers. A timeout usually means DNS, the provider firewall, UFW, or a network route is wrong; it is not normally a PHP problem.

Test PHP-FPM temporarily

sudo tee /var/www/example.com/public/info.php > /dev/null <<'PHP'
<?php
phpinfo();
PHP

Open http://example.com/info.php. A PHP information page confirms that Nginx passed the request to PHP-FPM and that the socket is usable. Delete it immediately afterward because it reveals PHP versions, loaded modules, filesystem paths, and environment details:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
sudo rm /var/www/example.com/public/info.php

Test an application database connection

Use a small application script or the application’s own setup command to connect with appuser to appdb over localhost. Confirm that the connection succeeds, a simple query runs, and the application can write only where intended. Remove any diagnostic script when finished.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Add HTTPS after DNS works

Obtain a certificate only after the domain resolves to this VPS and port 80 is reachable. A certificate-authority client such as Certbot can request a Let’s Encrypt certificate and update the Nginx configuration. On systems that package the Nginx integration, the workflow is commonly:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Package names and plugin availability vary by release, so follow the package instructions for your distribution. Allow HTTPS at both firewall layers, select the option to redirect HTTP to HTTPS when the client offers it, and inspect the resulting server blocks with sudo nginx -t.

Check renewal rather than assuming it works:

sudo certbot renew --dry-run

Keep the HTTP listener available for certificate validation and redirecting clients unless your certificate workflow uses another challenge method. Verify the site from an external network, test both the bare domain and any www name, and confirm that application-generated links use HTTPS.

Production checks after the first successful request

  • Apply operating-system and package security updates on a planned schedule.
  • Use SSH keys, disable password authentication when you have verified key access, and keep a tested recovery path through the provider console.
  • Back up the database and application files separately. Test restoring a backup; a backup that has never been restored is only an assumption.
  • Review Nginx access and error logs, PHP-FPM logs, and database logs. Configure rotation so logs cannot consume the disk.
  • Monitor disk space, memory, load, and inode usage. A full disk can stop PHP sessions, database writes, and certificate renewal.
  • Restrict writable directories and secrets. Keep environment files outside the public document root whenever the application permits.
  • Decide whether IPv6 is required. If the DNS has an AAAA record, verify that Nginx, UFW, and the provider firewall all permit IPv6 traffic.
  • Tune PHP-FPM worker counts, database buffers, and caching only after measuring the actual workload. There is no universal throughput or worker value for every VPS and application.

Single site or multiple sites?

For one domain, one server block and one document root keep the configuration easy to audit. For multiple domains, create a separate file in /etc/nginx/sites-available for each site, link each file into sites-enabled, and give each site its own root, logs, PHP settings, and deployment permissions. Every server block should list its intended names explicitly. Test after adding or changing one site so a syntax error does not obscure which change caused the failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Shared PHP-FPM pools are simple, but separate pools can provide stronger resource and permission isolation when sites have different owners or trust levels. That design adds operational work; choose it because you need isolation, not as a default performance claim.

Troubleshoot the failures that matter most

Symptom Likely cause Checks and fix
Nginx returns 502 Bad Gateway PHP-FPM is stopped, failed, or the socket path is wrong. Run systemctl status for the installed PHP-FPM unit, inspect /run/php, compare the result with fastcgi_pass, run nginx -t, then reload Nginx.
PHP downloads as plain text The PHP location block or FastCGI include is missing or not selected. Confirm that the request matches location ~ .php$, that the distribution FastCGI snippet is included, and that PHP-FPM is running. Never leave source code downloadable.
The domain times out DNS, the provider firewall, UFW, routing, or an incorrect address record. Check the domain’s A and AAAA records, provider rules, sudo ufw status, and local listeners with ss -ltnp.
Nginx will not start or reload Syntax error, duplicate directive, or another service already owns port 80 or 443. Run sudo nginx -t, inspect the error output, and check listeners with sudo ss -ltnp | grep -E ':80|:443'. Stop or reconfigure an unintended Apache or other web service.
The wrong site appears The default server block is still enabled or the Host name does not match. Review links in /etc/nginx/sites-enabled, confirm server_name, remove an unwanted default site, test, and reload.
Database connection is refused The database service is stopped, credentials are wrong, or the application uses the wrong host or socket. Check systemctl status mariadb or the MySQL unit, test the credentials from the VPS, and confirm the application uses the local database endpoint and intended database name.

Operational choices and trade-offs

A managed VPS can reduce the work of backups, firewall administration, monitoring, and recovery, but it may limit low-level configuration and add recurring service cost. A self-managed VPS gives you control over Nginx, PHP-FPM, and database settings while making patching, backups, incident response, and capacity planning your responsibility.

For database access, local-only listening is the safest default for a web and database server on one machine. Remote database access is justified when the database is on a separate private network or managed service; then use private addressing, source restrictions, encrypted connections where supported, and a documented rotation process for credentials.

For certificates, automated renewal removes a recurring manual task, but it still needs monitoring. For firewalls, provider controls can block traffic before it reaches UFW, while UFW protects the host after packets arrive; production systems generally need both layers configured consistently.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Final validation checklist

  1. DNS A and any AAAA records resolve to the intended VPS.
  2. SSH works with the non-root account and key before UFW is enabled.
  3. Nginx, the database, and the correct PHP-FPM unit are enabled and running.
  4. The PHP-FPM socket in the server block exactly matches the locally installed socket.
  5. The intended server block is enabled, the default conflict is removed, and nginx -t passes.
  6. Static content, a temporary PHP page, and a real application database query have each been tested.
  7. Diagnostic PHP files have been deleted.
  8. SSH, HTTP, and HTTPS are allowed at the required firewall layers; the database is not publicly exposed.
  9. HTTPS redirects correctly, the certificate covers every required hostname, and renewal testing succeeds.
  10. Updates, backups, log review, monitoring, and recovery procedures are documented.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.