Home/Server & Website Managed Operations/Migrating from Virtual Hosting to Cloud Servers: Handling Paths, Rewrites, and Environment Differences
Server & Website Managed Operations

Migrating from Virtual Hosting to Cloud Servers: Handling Paths, Rewrites, and Environment Differences

Migrating from virtual hosting to a cloud server is less about “moving files” and more about the fundamental differences in how they operate: virtual hosting environments are pre-configured by the provider, whereas cloud servers require manual configuration. Many features that “just work” on virtual hosts must be explicitly configured on a cloud server.

Key Differences

Item Virtual Hosting Cloud Server
Web Root Directory Fixed (e.g., /htdocs, public_html) Defined by you
URL Rewrites (Pseudo-static) Enabled via panel or auto-applied via .htaccess Must be configured manually
PHP Version Selected via control panel Installed manually
Database Provided by host, usually co-located Installed manually, can be independent
Absolute Paths Assigned by host May change
Permissions Pre-configured Ownership must be verified manually

Difference 1: Absolute Paths Change

This is the most common pitfall. Your application code may have hardcoded old paths:

# Search for hardcoded old paths in your code
grep -rn '/home/wwwroot|/htdocs|/public_html|/var/www' 
  /var/www/html --include='*.php' | head -20

# Check database as well (e.g., WordPress options or plugin configs)
mysql -e "SELECT option_name FROM wp_options
          WHERE option_value LIKE '%old_path%';" dbname

Commonly affected areas include:

  • Path constants in configuration files
  • Absolute path settings for upload directories
  • Cache and log directory configurations

Difference 2: URL Rewrites Must Be Reconfigured

On virtual hosts, .htaccess rules are automatically applied. Nginx does not read .htaccess. If your new server uses Nginx, you must translate these rules into Nginx configuration format.

# Original .htaccess (Apache syntax)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# Equivalent Nginx configuration
location / {
    try_files $uri $uri/ /index.php?$args;
}

If using Apache, ensure AllowOverride is set to All; otherwise, .htaccess files will be ignored:

grep -i 'AllowOverride' /etc/httpd/conf/httpd.conf

If the homepage loads but internal pages return 404, it is almost certainly due to missing rewrite rules.

Difference 3: PHP Versions and Extensions

# Record the version and extensions of the old environment
php -v
php -m | tr 'n' ' '
php -i | grep -iE 'upload_max_filesize|post_max_size|memory_limit'

# Verify against the new environment (install missing components)
php -v
php -m | tr 'n' ' '

Virtual hosts typically come with a full suite of pre-installed extensions. Minimalist cloud server installations often lack several of these. The most commonly missing extensions are image processing libraries like gd or imagick.

Difference 4: File Ownership and Permissions

# Identify the user running the web service
ps aux | grep '[n]ginx|[p]hp-fpm|[h]ttpd' | awk '{print $1}' | sort -u

# Correct file ownership
chown -R www:www /var/www/html

# Standard permission baseline
find /var/www/html -type d -exec chmod 755 {} ;
find /var/www/html -type f -exec chmod 644 {} ;

Files downloaded from a virtual host and re-uploaded to a cloud server often have incorrect ownership, resulting in upload failures or write errors.

Migration Steps

# ① Document old environment info (as much as possible from the virtual host)
php -v; php -m; cat .htaccess

# ② Archive and download files
tar -czf site.tar.gz .     # Or use the panel's file manager/FTP

# ③ Export the database
mysqldump -u username -p --default-character-set=utf8mb4 
  --single-transaction dbname > db.sql

# ④ Deploy environment on new server and extract files
tar -xzf site.tar.gz -C /var/www/html/

# ⑤ Fix ownership and permissions
chown -R www:www /var/www/html

# ⑥ Configure URL rewrites (Critical Step)
# ⑦ Import the database
# ⑧ Update database connection details in config files
# ⑨ Verify using hosts file or temporary DNS
# ⑩ Switch DNS resolution

Verification Phase (Do Not Skip)

# Modify local hosts file to point to the new server for testing
# Windows: C:WindowsSystem32driversetchosts
NewServerIP   example.com

# Perform itemized checks
curl -I https://example.com/                    # Homepage
curl -I https://example.com/some-inner-page      # Inner page (verify rewrites)
curl -I https://example.com/wp-content/uploads/x.jpg   # Images
curl -I https://example.com/wp-admin/           # Admin backend
# Confirm inner pages are not returning 404 (verify rewrites are active)
curl -o /dev/null -s -w '%{http_code}n' https://example.com/about/

Troubleshooting Decision Tree

Virtual Host → Cloud Server
├─ Homepage OK, Inner Pages 404
│  └─ Missing rewrites → Use try_files for Nginx; Ensure AllowOverride All for Apache
├─ White Screen
│  ├─ Enable debug mode to view errors
│  └─ Missing extensions (esp. image libs) → Compare with old env via php -m
├─ Images Not Displaying / Upload Fails
│  ├─ Incorrect ownership → chown
│  ├─ Incorrect permissions → 755/644
│  └─ Hardcoded paths still pointing to old location → Update config
├─ Database Connection Failed
│  └─ Credentials in wp-config.php still reference old environment
└─ Garbled Text
   └─ Character set mismatch → Ensure utf8mb4

Scenario Walkthrough: Moving a Site to Cloud Server Results in All Inner Pages Returning 404

Symptom: A site originally hosted on a virtual server is moved to a cloud server. The homepage loads correctly, but all inner pages return 404 errors. Files and database migration are confirmed complete.

  1. Narrow down the scope using “Homepage OK, Inner Pages 404” → This indicates the root directory, default document, and port are correct. The issue lies in how other paths are handled.
  2. Check if address rewriting rules were carried over → Virtual host rewrite rules are usually managed by the provider and do not migrate with the files. This is the most common omission in such migrations.
  3. Add the rules and reload the service → Ensure requests for unknown paths are forwarded to the application entry point.
  4. Verify path differences → Virtual host directory structures often have an extra layer. After migration, absolute paths may differ from the original.
  5. Check directory permissions and ownership → The process user on the cloud server differs from the virtual host. Incorrect permissions can prevent resource access.
  6. Verify step-by-step and maintain rollback capability → Keep the original environment accessible until the new one is stable.
# ① Rewrite Rules
nginx -T 2>/dev/null | grep -n 'try_files|rewrite' | head
apachectl -M 2>/dev/null | grep rewrite
grep -rn 'AllowOverride' /ApacheConfig/ 2>/dev/null | head

# ② Compare Status Codes: Homepage vs Inner Page
curl -sS -o /dev/null -w 'home=%{http_code}n' https://example.com/
curl -sS -o /dev/null -w 'post=%{http_code}n' https://example.com/known-path/

# ③ Path Differences: Check Web Root Configuration
nginx -T 2>/dev/null | grep -n 'root ' | head

# ④ Permissions and Ownership
ps -eo user,cmd | grep -E 'nginx|httpd|php-fpm' | head -3
ls -ld /web/dir; ls -l /web/dir | head -5

Root Cause: Address rewriting rules on virtual hosts are managed by the provider and do not migrate with the files. Without these rules, requests are treated as static file lookups, causing the homepage to load (as it matches the root) while inner pages fail with 404s.

Two Key Takeaways:

  • “Homepage OK + Inner Pages 404” strongly points to missing rewrite rules. This symptom is highly specific and should not be confused with permission issues or missing files.
  • When migrating, separately verify configurations provided by the host, as they are not portable files. Rewrite rules, pseudo-static configurations, and directory mappings fall into this category.

8 Common Pitfalls

  1. Assuming .htaccess will continue to work: Nginx does not read it.
  2. Failing to save old environment rules: You won’t have a reference to translate after moving.
  3. Hardcoded paths not updated: Absolute paths change during migration.
  4. Missing extensions: Minimal installs often lack image processing libraries.
  5. Incorrect file ownership: Leads to upload and write failures.
  6. PHP version incompatibility: Older applications may not support newer PHP versions.
  7. Switching DNS before verification: Exposes errors directly to users.
  8. Disabling the old environment immediately: Leaves no fallback option if issues arise.

Real Customer Feedback (From Cloud Marketplace Reviews and Inquiries)

The following excerpts are taken from real buyer reviews and inquiries for similar operations services on Alibaba Cloud, Tencent Cloud, and Huawei Cloud marketplaces (including our store and competitors). These are provided for reference only and do not represent fabricated tickets from our site:

10***31 2022-11-17 5.0 Timely Delivery | Prompt Response | Affordable Price System migration successful 10***31 2022-11-17 5.0 Skilled Technician | Secure & Reliable | Affordable Price Migration successful

1****n Rating: 5.0 Points 2018-01-04 18:04

45***76 2021-04-14 5.0 Timely Delivery Excellent

FREE CHECKUP

Free server checkup

We will send a problem checklist and remediation advice within one business day — no obligation to engage.

135 410 16684
Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
Call now
CONTACT

Contact Us

How can we help?

* Required