Establish your website with a credible and unique web address. Domains serve as an online address for your business to be found online. Let your business and passion reach its full potential by registering the best domain name with us.
Power your website with reliable and secured Web Hosting that comes with 24/7 SuperSupport.
Experience lightning-fast website and application hosting with unbeatable performance. Select the perfect server to take your digital journey to the next level.
Reach local and global customers with a robust website.
Drive customers to your site with our full suite of online marketing solutions.
Protect your online assets from day-to-day security challenges with our feature-packed web security solutions.
Gain customers’ trust with a professional email address powered by the latest email server technology for fast delivery and spam-free inboxes.
Equip your business with all the essential tools you need to get online and save big by purchasing any of our all-in-one customisable packages today.
Fast sites win wallets, rankings, and development time. A tuned LEMP stack trims latency, keeps PHP logic separate from static delivery, and scales cleanly as your traffic grows. For SMEs, agencies, and in-house engineers, that means predictable costs and fewer 3 a.m. outages.
This guide walks through a repeatable, production-ready install of Nginx, PHP-FPM, and MariaDB on a VPS, covering Nginx FastCGI mapping, PHP pools, and sensible MariaDB tuning.
Before touching a terminal, check your foundation. A small but realistic starting point is 2 vCPUs and 2 GB of RAM; anything lighter leaves no headroom once traffic spikes.
Debian and Ubuntu derivatives work best because of their well-maintained apt repositories, but the concepts map to any modern Linux. You’ll need SSH with sudo or root, basic shell tools, and your DNS already pointing at the VPS. Confirm ports 22, 80, and 443 are open and time synchronisation is enabled.
For deeper detail, consult the official Nginx, PHP, and MariaDB docs.
Nginx is lean and sits front-of-house, so install it first via your package manager, verifying the version is LTS-grade (currently 1.24+ on Debian/Ubuntu LTS).
Once installed, disable the default site to stop it from hijacking requests:
Place the file in /etc/nginx/sites-available/example.com and symlink to sites-enabled.
Bridge to PHP-FPM with FastCGI by adding:
Match the socket path to your PHP pool (we’ll create it shortly). Ensure the Nginx worker user, usually www-data, can read the web root and talk to the socket; mismatches here drive most 502 errors.
Common pitfalls include forgetting to remove the default server block or pointing root to a folder that PHP-FPM cannot access.
PHP-FPM runs PHP code as a standalone service, removing the web-server bottleneck that Apache’s mod_php can create. Because PHP-FPM keeps its own worker pool, it can process scripts concurrently and let Nginx focus on serving static assets.
Whatever you pick (the path or host) port must exactly match the fastcgi_pass line in Nginx.
Pool hints:
Restart PHP-FPM after edits and verify sockets exist:
sudo systemctl restart php8.3-fpm sudo ls -l /run/php/
If sockets are missing or owned by the wrong group, Nginx will respond with “502 Bad Gateway”.
Back in your server block, confirm the FastCGI mapping lines:
The included snippet sets SCRIPT_FILENAME, QUERY_STRING, and friends. Keep timeout values conservative until real traffic data tells you otherwise.
When you see 502 or 504 errors:
Sockets edge out TCP for raw speed on one host; TCP wins when PHP runs elsewhere because you avoid permission juggling at the cost of small network overhead.
Install MariaDB from your distro’s repo and run the secure install helper to set a root password, drop anonymous users and disable remote root login. Newer releases default to unix_socket authentication for root; switch to password auth only if your workflow demands it.
Query cache is off by default in modern MariaDB and should stay that way. Focus on proper indexing instead.
Apply changes in /etc/mysql/mariadb.conf.d/50-server.cnf, restart MariaDB, then monitor memory and swap usage with htop.
MariaDB tuning is iterative. Change one parameter, watch metrics, repeat.
View Nginx, PHP-FPM and MariaDB as one organism. Oversizing any single component only shifts the bottleneck.
Encrypt everything with Let’s Encrypt via Certbot; prefer HTTP-01 validation unless DNS-based challenges are required by your provider. Store certificates in /etc/letsencrypt/live/.
Use least-privilege:
Deploy UFW or iptables to allow 22, 80, and 443, then run fail2ban to throttle brute-force attempts. Stage everything first, then use rolling restarts (nginx -s reload, systemctl reload php8.3-fpm) to avoid downtime.
Replicate issues on staging before touching production.
For the first 72 hours post-deployment, watch PHP-FPM children, Nginx active connections, DB slow queries, and disk IO. Schedule nightly database dumps and compress the web root. Test restores monthly.
Automate logrotate, certificate renewal, and security updates. Even a lightweight Prometheus node exporter or a Bash script emailing metrics is better than blind hope.
Getting a LEMP stack singing on a VPS hinges on three disciplines: map Nginx to PHP-FPM with precision, size your PHP pools to match traffic and memory, and practise deliberate MariaDB tuning. Start with conservative defaults, monitor real-world metrics, and iterate; that rhythm turns good setups into great ones.
Ready to simplify your journey? Vodien’s managed VPS plans bundle domain management and automated SSL, freeing you to focus on code. Book a quick consultation to see how easily your stack can move from staging to high-performance production.
Your email address will not be published. Required fields are marked *