Maintenance21 min readAugust 3, 2026, 10:45 AM

cPanel to Nginx LEMP Migration: Handling Custom PHP Directives & Apache Modules

MA
Mir Alamin

Principal Web Architect

#cPanel#LEMP Setup#Nginx#PHP Tune#Server Migration

cPanel to Nginx LEMP Migration: Handling Custom PHP Directives & Apache Modules

Author: Mir Alamin (Principal Web Architect) | Published: August 3, 2026 at 10:45 AM | Reading Time: 21 min read | Category: Maintenance | Tags: cPanel, LEMP Setup, Nginx, PHP Tune, Server Migration


Executive Summary

When migrating web applications from cPanel control panel environments to an unmanaged LEMP stack (Nginx, MariaDB, PHP-FPM), system administrators frequently encounter broken application features. This happens because cPanel heavily relies on Apache modules (e.g., mod_rewrite, mod_headers, mod_expires) and inline .htaccess php_value directives that Nginx and PHP-FPM do not natively parse.

This migration guide provides step-by-step instructions for converting cPanel Apache configurations, moving .htaccess php_value settings into PHP-FPM pool files, and mapping Apache environment variables to Nginx fastcgi params.


1. Translating .htaccess php_value and php_flag Directives

In cPanel Apache environments, developers often modify PHP settings directly inside .htaccess:

# Apache .htaccess (Will cause 500 errors if left in Nginx environment)
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_flag display_errors Off

Nginx / PHP-FPM Equivalent:

Move these settings to the site's PHP-FPM pool file in /etc/php/8.3/fpm/pool.d/www.conf or site-specific pool:

; /etc/php/8.3/fpm/pool.d/www.conf
php_admin_value[upload_max_filesize] = 64M
php_admin_value[post_max_size] = 64M
php_flag[display_errors] = off

2. Converting Common Apache Modules to Native Nginx Blocks

Apache mod_headers -> Nginx add_header

# Apache: Header set Access-Control-Allow-Origin "*"
add_header Access-Control-Allow-Origin "*" always;

Apache mod_expires -> Nginx expires

# Apache: ExpiresActive On / ExpiresDefault "access plus 1 month"
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 30d;
    add_header Cache-Control "public, no-transform";
}

3. Zero-Downtime Migration Cutover Protocol

  1. Export cPanel databases using mysqldump and restore into local MariaDB.
  2. Synchronize web assets via rsync.
  3. Configure Nginx virtual hosts and PHP-FPM pools.
  4. Test locally using /etc/hosts domain mapping.
  5. Update DNS A-records for seamless zero-downtime cutover.

For professional migration assistance from cPanel to LEMP:


4. Frequently Asked Questions (FAQ)

Q1: What happens if an .htaccess file is left on an Nginx server?

Nginx completely ignores .htaccess files. While it won't break Nginx directly, any rewrite or security rules inside .htaccess will not be processed unless manually converted to Nginx server blocks.

Q2: How do I handle cPanel MultiPHP settings on LEMP?

On LEMP, you can run multiple PHP-FPM versions simultaneously (e.g., PHP 7.4, 8.1, 8.3) listening on different sockets, mapping each site's Nginx fastcgi_pass to its required PHP socket.


© 2026 WebCare Pro. Authored by Mir Alamin.

Was this engineering analysis helpful?

Leave feedback to help us refine our technical content.

Share with fellow developers

Found value in this guide? Share it across your network.

MA

Written by Mir Alamin

Principal Web Architect at WebCare Pro. Specializing in Next.js speed optimizations, high-score Core Web Vitals, Cloudflare Workers static edge hosting, and continuous website maintenance.

Explore WebCare Pro Services