Complete LNMP Guide: Deploy WordPress and Forums Step‑by‑Step
This guide walks you through installing a full LNMP stack on CentOS or Ubuntu, configuring Nginx, MySQL, and PHP, deploying WordPress with essential plugins and security hardening, and setting up popular forums such as phpBB, Flarum, and Discourse, followed by performance tuning tips.
What is LNMP?
LNMP = Linux + Nginx + MySQL + PHP. Compared with LAMP (Apache), Nginx uses an event‑driven architecture, delivering 2‑3× higher throughput, >50% lower memory usage, native reverse‑proxy and load‑balancing, and faster static‑file handling.
System preparation
CPU: 2 cores (4 cores recommended)
Memory: 2 GB (4 GB recommended)
Disk: 40 GB SSD
OS: CentOS 7/8/9 or Ubuntu 20.04/22.04
yum update -y</code>
<code>apt update && apt upgrade -y</code>
<code>setenforce 0</code>
<code>sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config</code>
<code>firewall-cmd --zone=public --add-service=http --permanent</code>
<code>firewall-cmd --zone=public --add-service=https --permanent</code>
<code>firewall-cmd --reloadInstall Nginx
CentOS
yum install epel-release -y</code>
<code>yum install nginx -y</code>
<code>systemctl start nginx</code>
<code>systemctl enable nginx</code>
<code>nginx -vUbuntu
apt install nginx -y</code>
<code>systemctl start nginx</code>
<code>systemctl enable nginx</code>
<code>nginx -vVisit the server IP; the Nginx welcome page confirms a successful install.
Install MySQL
CentOS (MySQL 8.0)
wget https://dev.mysql.com/get/mysql80-community-release-el9-3.noarch.rpm</code>
<code>rpm -ivh mysql80-community-release-el9-3.noarch.rpm</code>
<code>yum install mysql-community-server -y</code>
<code>systemctl start mysqld</code>
<code>systemctl enable mysqldUbuntu
apt install mysql-server -y</code>
<code>systemctl start mysql</code>
<code>systemctl enable mysqlRun mysql_secure_installation to set the root password, remove anonymous users, disable remote root login, delete the test database and reload privileges.
Install PHP (WordPress‑compatible)
CentOS (PHP 8.2)
yum install https://rpms.remirepo.net/enterprise/remi-release-9.rpm -y</code>
<code>yum module enable php:remi-8.2 -y</code>
<code>yum install php php-fpm php-mysqlnd php-gd php-xml php-mbstring php-json php-zip php-curl php-intl php-bcmath php-opcache -y</code>
<code>systemctl start php-fpm</code>
<code>systemctl enable php-fpm</code>
<code>php -vUbuntu (PHP 8.2)
add-apt-repository ppa:ondrej/php -y</code>
<code>apt update</code>
<code>apt install php8.2 php8.2-fpm php8.2-mysql php8.2-gd php8.2-xml php8.2-mbstring php8.2-zip php8.2-curl php8.2-intl php8.2-bcmath -y</code>
<code>systemctl start php8.2-fpm</code>
<code>systemctl enable php8.2-fpmConfigure Nginx to serve PHP
vim /etc/nginx/conf.d/default.conf</code>
<code>server {</code>
<code> listen 80;</code>
<code> server_name localhost;</code>
<code> root /usr/share/nginx/html;</code>
<code> index index.php index.html index.htm;</code>
<code> location / {</code>
<code> try_files $uri $uri/ /index.php?$args;</code>
<code> }</code>
<code> location ~ \.php$ {</code>
<code> fastcgi_pass unix:/var/run/php-fpm/www.sock; # CentOS</code>
<code> # fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Ubuntu</code>
<code> fastcgi_index index.php;</code>
<code> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</code>
<code> include fastcgi_params;</code>
<code> }</code>
<code>}</code>
<code>nginx -t</code>
<code>systemctl reload nginxTest PHP
echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/phpinfo.php</code>
<code># Browse to http://<em>server_ip</em>/phpinfo.phpIf the PHP information page appears, PHP‑FPM is correctly configured.
WordPress installation
Create database and user
mysql -u root -p</code>
<code>CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;</code>
<code>CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_strong_password';</code>
<code>GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';</code>
<code>FLUSH PRIVILEGES;</code>
<code>EXIT;Download and deploy WordPress
wget https://cn.wordpress.org/latest-zh_CN.tar.gz</code>
<code>tar xzf latest-zh_CN.tar.gz</code>
<code>mv wordpress/* /usr/share/nginx/html/</code>
<code>chown -R nginx:nginx /usr/share/nginx/html/ # CentOS</code>
<code># chown -R www-data:www-data /usr/share/nginx/html/ # Ubuntu</code>
<code>chmod -R 755 /usr/share/nginx/html/</code>
<code>chmod -R 644 /usr/share/nginx/html/wp-content/Configure wp-config.php
cd /usr/share/nginx/html/</code>
<code>cp wp-config-sample.php wp-config.php</code>
<code>vim wp-config.php</code>
<code>define('DB_NAME', 'wordpress');</code>
<code>define('DB_USER', 'wpuser');</code>
<code>define('DB_PASSWORD', 'your_strong_password');</code>
<code>define('DB_HOST', 'localhost');</code>
<code>define('DB_CHARSET', 'utf8mb4');</code>
<code># Replace SALT placeholders with values from https://api.wordpress.org/secret-key/1.1/salt/Complete the web‑based wizard at http://your_domain_or_ip to set site title, admin credentials, etc.
WordPress plugin installation (WP‑CLI)
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar</code>
<code>chmod +x wp-cli.phar</code>
<code>mv wp-cli.phar /usr/local/bin/wp</code>
<code>cd /usr/share/nginx/html/</code>
<code>sudo -u nginx wp plugin install wordfence --activate</code>
<code>sudo -u nginx wp plugin install seo-by-rank-math --activate</code>
<code>sudo -u nginx wp plugin install wp-super-cache --activate</code>
<code>sudo -u nginx wp plugin install updraftplus --activate</code>
<code>sudo -u nginx wp plugin install wp-smushit --activate</code>
<code>sudo -u nginx wp plugin install contact-form-7 --activate</code>
<code>sudo -u nginx wp plugin install classic-editor --activateWordPress security hardening
Hide WordPress version
# Add to theme's functions.php</code>
<code>remove_action('wp_head', 'wp_generator');Protect wp-config.php
chmod 600 wp-config.php</code>
<code># Nginx block</code>
<code>location = /wp-config.php { deny all; }Disable directory listing
autoindex off;Block XML‑RPC
location = /xmlrpc.php { deny all; access_log off; log_not_found off; }Enable HTTPS
Obtain a Let’s Encrypt certificate and configure SSL in Nginx.
Forum systems deployment
phpBB (classic PHP forum)
# Database</code>
<code>mysql -u root -p</code>
<code>CREATE DATABASE phpbb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;</code>
<code>CREATE USER 'phpbbuser'@'localhost' IDENTIFIED BY 'your_password';</code>
<code>GRANT ALL PRIVILEGES ON phpbb.* TO 'phpbbuser'@'localhost';</code>
<code>FLUSH PRIVILEGES;</code>
<code>EXIT;</code>
<code># Download and extract</code>
<code>wget https://download.phpbb.com/pub/release/3.3/3.3.11/phpBB-3.3.11.zip</code>
<code>unzip phpBB-3.3.11.zip</code>
<code>mv phpBB3 /usr/share/nginx/html/phpbb</code>
<code>chown -R nginx:nginx /usr/share/nginx/html/phpbb/</code>
<code>chmod 755 /usr/share/nginx/html/phpbb/cache/</code>
<code># Access http://your_domain/phpbb/install to finish setup (1 CPU + 2 GB RAM sufficient)Flarum (modern lightweight forum)
# Install Composer</code>
<code>php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"</code>
<code>php composer-setup.php</code>
<code>mv composer.phar /usr/local/bin/composer</code>
<code># Create directory and install</code>
<code>mkdir -p /usr/share/nginx/html/forum</code>
<code>cd /usr/share/nginx/html/forum</code>
<code>composer create-project flarum/flarum . --stability=beta</code>
<code>chown -R nginx:nginx /usr/share/nginx/html/forum/</code>
<code>chmod -R 755 /usr/share/nginx/html/forum/</code>
<code># Nginx URL rewrite (add to server block)</code>
<code>location / { try_files $uri $uri/ /index.php?$query_string; }</code>
<code># Visit http://your_domain/forum to complete installation (ensure php‑fileinfo extension is present)Discourse (resource‑heavy Ruby on Rails forum, Docker‑based)
# Install Docker</code>
<code>curl -fsSL https://get.docker.com -o get-docker.sh</code>
<code>sh get-docker.sh</code>
<code>systemctl start docker && systemctl enable docker</code>
<code># Install Git</code>
<code>yum install git -y # CentOS</code>
<code>apt install git -y # Ubuntu</code>
<code># Clone Discourse Docker repo</code>
<code>mkdir -p /var/discourse</code>
<code>git clone https://github.com/discourse/discourse_docker.git /var/discourse</code>
<code>cd /var/discourse</code>
<code># Run setup wizard</code>
<code>./discourse-setup</code>
<code># Provide domain, admin email, SMTP, and Let’s Encrypt details as prompted</code>
<code># Installation takes 10‑30 minutes depending on hardwareSelection guidance
Limited budget, few users, stability needed → phpBB
Modern UI, moderate traffic → Flarum
Ample budget, large community, best experience → Discourse
Performance tuning
PHP tuning (php.ini)
memory_limit = 256M</code>
<code>upload_max_filesize = 64M</code>
<code>post_max_size = 64M</code>
<code>max_execution_time = 180</code>
<code>max_input_time = 180</code>
<code>opcache.enable = 1</code>
<code>opcache.memory_consumption = 128</code>
<code>opcache.interned_strings_buffer = 8</code>
<code>opcache.max_accelerated_files = 10000</code>
<code>opcache.revalidate_freq = 2Nginx tuning (nginx.conf)
worker_processes auto;</code>
<code>events { worker_connections 10240; use epoll; multi_accept on; }</code>
<code>gzip on;</code>
<code>gzip_vary on;</code>
<code>gzip_min_length 1024;</code>
<code>gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss;</code>
<code>location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 30d; add_header Cache-Control "public, immutable"; }MySQL tuning (my.cnf or mysqld.cnf)
[mysqld]</code>
<code>innodb_buffer_pool_size = 1G # 50‑70% of RAM</code>
<code>innodb_log_file_size = 256M</code>
<code>innodb_flush_log_at_trx_commit = 2</code>
<code>query_cache_size = 64M</code>
<code>query_cache_limit = 2M</code>
<code>max_connections = 200</code>
<code>key_buffer_size = 64MSigned-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.
AI Agent Super App
AI agent applications, installation, large-model testing, computer fundamentals, IT operations and maintenance exchange, network technology exchange, Linux learning
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.
