Thursday, June 29, 2023

miscellaneous Wordpress fixes

Since I'm new to administering Wordpress, I'm listing below some solutions to some of the issues fixed on some of our servers.

Exporting and importing the database - 

https://ubuntu.com/tutorials/install-and-configure-wordpress#5-configure-database

Initially I had set up a wordpress site with WP-CLI since auto updates and installing of plugins were not working via the web console. Later, the web-based administration was fixed by changing ownership of the files to the webserver,
sudo chown the-wp-directory www-data:www-data

The site did not need 777 permissions, 744 seemed to be working.

But here are some of the useful WP-CLI commands.

cd the-wp-directory
wp plugin update --all

wp plugin search recaptcha
wp plugin install advanced-google-recaptcha
 
A migrated site would not open the web admin console - the error seen in /var/log/apache2/error.log seemed to be related to yoast plugin, not compatible with php 8.1. So, it needed to be disabled before I could open the web console. To do that,
https://kinsta.com/knowledgebase/disable-wordpress-plugins/
Rename public/wp-content/plugins folder to plugins_old, log in, then rename it back to plugins.
 
One of our sites was showing 404 errors for all pages other than the home page. The simple fixes at https://www.cloudways.com/blog/wordpress-404-error/ did not work. Digging in a bit, if I re-wrote the url as
domain.tld/?postname
it would work. So, it was some issue with the Permalinks setting. Though I checked that the .httpdocs was writable and so on, the wordpress url-rewrite was not working. So, had to manually copy-paste the following code to the end of the .htaccess file in the root directory, as per the advice at this page
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
 
Also for w3 total cache plugin, mod_expires was needed.
enabling mod_expires with
https://unix.stackexchange.com/questions/694530/enable-mod-expires-on-apache
sudoa2enmod expires headers

https://lindevs.com/install-tidy-on-ubuntu gave the method for installing tidy.
But for tidy, we need the php extension and not above. 
sudo apt install php-tidy
https://linuxhint.com/install-latest-php-ubuntu22-04/

For testing the sites, I had edited the hosts file to point the browser to the new server -
sudo nano /etc/hosts on Linux

On Windows, you would do this by going to the start menu, and start typing notepad.exe, right click on Notepad, choose Run as Administrator, and open the file
C:\Windows\System32\drivers\etc\hosts
(since it is just hosts and not hosts.txt, when using File->open to find it, you must choose the drop-down "All files *. *" option.)
 
One of the migrated sites on a "multi-site network" wordpress instance did not allow logging in to the admin console with sitename/wp-admin - "An error occurred".
AFTER chown www-data for all files under wp directory, deleting inactive plugins from the Network admin web console solved the issue.

Resetting a password when a wordpress site is not configured for sending emails - via https://wordpress.org/documentation/article/reset-your-password/
- create MD5 hash of desired pw from http://www.miraclesalad.com/webtools/md5.php and put it in the user_pass field of the prefix_users table. If not using dbeaver, from the wp documentation above:
  1. “mysql -u root -p” (log in to MySQL)
  2. enter your mysql password
  3. “use (name-of-database)” (select WordPress database)
  4. “show tables;” (you’re looking for a table name with “users” at the end)
  5. “SELECT ID, user_login, user_pass FROM (name-of-table-you-found);” (this gives you an idea of what’s going on inside)
  6. “UPDATE (name-of-table-you-found) SET user_pass=”(MD5-string-you-made)” WHERE ID = (id#-of-account-you-are-reseting-password-for);” (actually changes the password)
  7. “SELECT ID, user_login, user_pass FROM (name-of-table-you-found);” (confirm that it was changed)
  8. (type Control-D to exit mysql client)

Edit: A list of items to secure a wordpress site - https://www.hostinger.in/tutorials/how-to-secure-wordpress

No comments:

Post a Comment