Technology, Tutorial, Ubuntu, Woo Commerce

A ROOKIE UBUNTU ADMIN’S JOURNEY THROUGH A WORDPRESS MIGRATION

What is this?

This is a post for those who have to move a Word Press installation (Specifically) from one ubuntu server to another, including:

1) DNS records
2) files
3) mysql database
4) Let’s Encrypt bonus item

All of these cute little moving cogwheels in the system can muck you up royally and so instead of piece-mealing it together I thought I’d pull the elements together and prioritize the workflow and troubleshooting because God knows well I’ll forget this in 48 hours…

I will put the items in priority order, too, in case you did a flash migration and stuff is broken. If you work through these fundamentals you’ll likely stumble across your problem and resolve it.

We will code name your original server as ‘Server1’ and the target final server as ‘Server2’ because I’m one seriously creative dude.

DNS

For this section, I believe spending a few minutes reading through my post will be all you need to consider. This example deals with Digital Ocean but contains most of the considerations you would need anywhere. The key summary is this:

  • Back up your DNS records from DNS management location
  • Move them to DNS management location 2 (if moving), or, if not moving
  • Update DNS records appropriately in your DNS management tool (ie. IP address of new server)

I put this section first as propagation can take time so you might want to set the propagation into action while everything else is down anyways. Be aware as soon as you do it things might go down for viewers of your site online but no way to really avoid it from my understanding.

The Files

I don’t provide any details about how to actually backup and move your files from the old server to the new server and will assume you have already done this and they are sitting in a standard place like /var/www/html on your server. If you want to go through some of my old posts about doing that, this is an example. And this one-stop dump will be helpful for your Mysql file dump

We assume that you have your mysql and website files now on Server2

The rest is basically walking through this set of ubuntu commands on your server to make sure that your Word Press permissions are correct, as mine were not after migration:

Here is a great permission tool I used that might help you make sure things are good.

I stole this next part from some AI bot which probably stole it from some other blog so I can’t be responsible for anything 😉 I quite liked this way of doing it by searching for files and directories and attacking the key items specifically and accurately. Hence I’m stealing and re-re-blogging it…

All you need to know is /wordpress is the name of the directory where your WordPress installation is. Mine was different so I updated the path location and the directory name to match where my WP directory is on my server.

WordPress File Permissions Ubuntu

To set proper WordPress file permissions on Ubuntu, follow these steps to ensure security and functionality:

  1. Set Ownership: The www-data user and group (the Apache web server user) should own the WordPress files. Replace /var/www/wordpress with your actual WordPress directory path: sudo chown -R www-data:www-data /var/www/wordpress
  2. Set Directory Permissions: All directories should have permissions set to 755, allowing the owner to read, write, and execute, while the group and others can only read and execute. Use the find command: sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
  3. Set File Permissions: All files should have permissions set to 644, allowing the owner to read and write, while the group and others can only read. Use the find command: sudo find /var/www/wordpress -type f -exec chmod 644 {} \;
  4. Set Special File Permissions: The wp-config.php file contains sensitive database information and should have stricter permissions. Set it to 600 (read and write for owner only) or 440 (read for owner and group, no write for group): sudo chmod 600 /var/www/wordpress/wp-config.php
    “`
    or sudo chmod 440 /var/www/wordpress/wp-config.php

(For the records, I selected 600 as I didn’t know what’s best and all seems well…)

  1. Set Uploads Directory Permissions: The wp-content/uploads directory needs to be writable by the web server for file uploads. Set its permissions to 775 to allow the owner and group full access: sudo chmod -R 775 /var/www/wordpress/wp-content/uploads

MYSQL

You can read the majority of the journey in this mysql post I wrote. Read all the way to the bottom, too as I provide a nice little teaching about how MySQL actually works if you didn’t know.

LETS ENCRYPT

This final section got me and has another WordPress-specific angle. I won’t spend any time here about lets encrypt and how to generate your certificates with certbot because you can search my blog for that if you need or online. The key point is that in both the website.conf (port 80) and the website-le.conf (port 443) version of the config files for apache, you really do need this little section. Without it, my WordPress website only loaded the main index.php page. As soon as I added this bit to the config file(s) and did the systemctl reload apache2 command, the site came back.

` <Directory /var/www/html/talash/> Options +FollowSymlinks AllowOverride All Require all granted </Directory>

You can see in my mautic example more clearly where I placed it in the file or search online.

Hope this helps!

Tagged , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *