AI and upgrading WordPress–part 2 – wishfull thinking and wordpress in WSL

So I have a backup of blog WordPress ( posts and comments ) and all I want is to upgrade to latest WordPress, keeping the posts and comments ( and none of customizations, users and others)

I figure out that I have WSL under Windows – and WordPress is PHP, so it should work .

Wishful thinking

So the first prompt was pretty simple

I have a site on WordPress 4. I have a backup in zip format . I want to make an fresh new site using WSL to ensure that all works, and then transfer via FTP . I need some code in PowerShell to do those tasks

The problem is that he was generating a VERY BIG PowerShell file , that did not run flawlessly first time , and gives many errors. Obviously , my wish was like for a genie – not for an AI .

Look at what he has created in one PowerShell file:

I’ve created a comprehensive PowerShell script that handles the entire process. Here’s what it does:

Key Features:

  1. Extracts your WordPress backup from the zip file
  2. Sets up a complete LAMP stack in WSL (Apache, MySQL, PHP)
  3. Restores your WordPress site from the backup
  4. Configures the database with new credentials
  5. Tests the installation locally
  6. Creates an FTP upload script for transferring to your live server

To use this script:

  1. Update the parameters at the top of the script:
    • $BackupZipPath: Path to your WordPress backup zip
    • $FTPServer, $FTPUsername, $FTPPassword: Your FTP credentials
    • $FTPRemotePath: Remote directory (usually /public_html/)
    • Database credentials for the local setup
  2. Run the script in PowerShell as Administrator:

    <?XML:NAMESPACE PREFIX = “[default] http://www.w3.org/2000/svg” NS = “http://www.w3.org/2000/svg” />

    powershell

    .\wordpress-setup.ps1

What happens:

  • Installs Apache, MySQL, and PHP in your WSL environment
  • Creates a new database for WordPress
  • Restores your WordPress files and database from the backup
  • Updates wp-config.php with new database settings
  • Tests the local installation
  • Creates an FTP script for uploading to your live server

Additional notes:

  • The script assumes you have WSL with Ubuntu installed
  • It will prompt you before uploading via FTP
  • Your local WordPress will be accessible at the WSL IP address
  • The FTP upload uses lftp for efficient mirroring

Make sure to test your WordPress site locally before uploading to ensure everything works correctly with the restored backup!

No, this would not work – and indeed, running the PowerShell give me more errors

Craft prompt

Now the prompt was to create powershell scripts for each step –  and he realized it – those are the steps:

Step10_PrepareAlpine.ps1
Step20_SetupMariaDB.ps1
Step30_ConfigureNginx.ps1
Step35_ConfigurePHP.ps1
Step40_DownloadWordPress.ps1
Step41_SetupWordPressDatabase.ps1
Step45_DownloadWordPress.ps1
Step50_CompleteWordPressInstall.ps1
Step60_ConfigureWpConfig.ps1

Step70_AccessSite
Step80_importdatabase

Some observations :

  1. Making steps allows me to run steps one by one and come back to the fresh clean installation ( using WSL meant delete the distro)
  2. He suggested using Ubuntu – but the download was to heavy . I did prefer alpine  – but it was a PIA for running MariaDB and wordpress
  3. I run to problems – Maria DB is not connecting to port ….
  4. For each step I requested testing the completeness of the script. However, this is difficult – for Step60 , ConfigureWpConfig with database info, the best solution was to add code to type to the output the contents in order for the AI to know what is wrong

Now, I thing that maybe making Ubuntu was a better idea – just copy the fresh installation to a new file and restore each time, instead of downloading.

However, the Step80, import database, was unsuccessful – the insert into posts table have the wrong number of columns ( WordPress database being modified between versions)

How I solved – in the next blog post.


Posted

in

,

by

Tags: