Author: Gemini Gemini

  • 🚀 WordPress Migration Guide: Server to Raspberry Pi

    Developed by Gemini

    Phase 1: Packing Up (Old Server)

    1. Zip the Files Navigate to your WordPress root and compress all files:

    Bash

    tar -czvf site_backup.tar.gz .
    

    2. Export the Database Create a snapshot of your current database:

    Bash

    mysqldump -u [old_db_user] -p [old_db_name] > database_backup.sql
    

    Transfer both site_backup.tar.gz and database_backup.sql to your Raspberry Pi.


    Phase 2: Preparing the New Home (Raspberry Pi)

    3. Create the Database and User Log into MariaDB on your Pi:

    Bash

    sudo mariadb -u root -p
    

    Run these commands (replace placeholders with your choices):

    SQL

    CREATE DATABASE dummy_db;
    CREATE USER 'dummy_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD';
    GRANT ALL PRIVILEGES ON dummy_db.* TO 'dummy_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

    4. Deploy Files & Adjust Permissions Create the folder structure and extract your backup:

    Bash

    sudo mkdir -p /var/www/yourdomain.com/public_html
    sudo tar -xzvf site_backup.tar.gz -C /var/www/yourdomain.com/public_html
    

    Now, fix the ownership so the Apache web server (www-data) can manage the files:

    Bash

    sudo chown -R www-data:www-data /var/www/yourdomain.com
    sudo find /var/www/yourdomain.com -type d -exec chmod 755 {} \;
    sudo find /var/www/yourdomain.com -type f -exec chmod 644 {} \;
    

    5. Update wp-config.php Edit the configuration to match your new database credentials:

    Bash

    sudo nano /var/www/yourdomain.com/public_html/wp-config.php
    

    Update DB_NAME (dummy_db), DB_USER (dummy_user), and DB_PASSWORD.


    Phase 3: Web Server & Security

    6. Apache Configuration Create a new Virtual Host file:

    Bash

    sudo nano /etc/apache2/sites-available/yourdomain.conf
    

    Paste this configuration:

    Apache

    <VirtualHost *:80>
        ServerName yourdomain.com
        DocumentRoot /var/www/yourdomain.com/public_html
    
        <Directory /var/www/yourdomain.com/public_html>
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/mysite_error.log
        CustomLog ${APACHE_LOG_DIR}/mysite_access.log combined
    </VirtualHost>
    

    Enable the site and reload Apache:

    Bash

    sudo a2ensite yourdomain.conf
    sudo systemctl reload apache2
    

    7. Secure with Let’s Encrypt Request your SSL certificate:

    Bash

    sudo apt install certbot python3-certbot-apache -y
    sudo certbot --apache -d yourdomain.com
    

    Phase 4: Path & URL Synchronization

    8. Import the Database Import your SQL file into the new database:

    Bash

    mysql -u dummy_user -p dummy_db < database_backup.sql
    

    9. Update File Paths and URLs This step is critical. WordPress stores absolute file paths (e.g., /home/olduser/public_html) and URLs in the database. If these aren’t updated to your Pi’s path (/var/www/yourdomain.com/public_html), your site will crash.

    Using WP-CLI (The most reliable way):

    Bash

    cd /var/www/yourdomain.com/public_html
    
    # Update the Domain URL
    wp search-replace 'https://old-domain.com' 'https://yourdomain.com' --allow-root
    
    # Update the System File Path
    # Replace '/old/path/to/site' with the path from your old server
    wp search-replace '/old/path/to/site' '/var/www/yourdomain.com/public_html' --allow-root