Step-by-Step Guide to Building a LAMP Stack with Nginx, MySQL, and PHP on Linux
This tutorial walks you through preparing required packages, compiling and installing MySQL 5.5.3, PHP (with FastCGI and extensions), and Nginx on a Linux server, then configuring php‑fpm, fastcgi parameters, virtual hosts, log rotation, and load‑balancing features.
1. Preparation
Gather the RPM package for the required PHP functions, download the source code packages for LNMP components, and obtain the supporting libraries such as libiconv and libmcrypt.
After installing the libraries, edit /etc/ld.so.conf to add a new line and run ldconfig to refresh the linker cache.
2. Install MySQL
Compile and install MySQL 5.5.3‑m3 from source.
3. Install PHP
Compile PHP in FastCGI mode to improve parsing speed.
Prepare and compile additional PHP extensions, modify php.ini to enable them, and configure eAccelerator for acceleration.
Create the php‑fpm.conf configuration file and start the php‑cgi (FastCGI) process listening on 127.0.0.1:9000 with an appropriate number of worker processes.
4. Install Nginx
Install the PCRE library required by Nginx, then compile and install Nginx itself.
Modify the Nginx configuration files, create a fastcgi_params file (or place the parameters directly in nginx.conf) to correctly set SCRIPT_FILENAME for PHP scripts.
Configure automatic start‑up for Nginx, php‑fpm, MySQL and set system limits (ulimit) in /etc/rc.local and /etc/profile.
5. Nginx Management and Advanced Features
Check configuration syntax, perform graceful reloads, and set up daily log rotation scripts via cron.
Define virtual hosts, adjust fastcgi parameters for different document roots, and resolve common “No input file specified” errors.
Enable Nginx status monitoring, configure rewrite rules with appropriate flags (last, break, redirect, permanent), and set up reverse‑proxy load balancing.
Finally, adjust core module settings such as worker processes, connection limits, keepalive timeout, sendfile, and access/error logs to optimize performance and security.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
