Top Nav

MySQL – Run Command On All Tables

Here’s a one-liner to run a SQL command on all tables in a database:

  • Replace “show create table” with the command that you wish to execute.
  • Replace “mydb” with your database name.
  • Replace “root” and “mypassword” with you username and password.
  • Replace “localhost” with your database server hostname or IP address.

 

0

Magento 2 – Add Admin From Command Line

To add an admin user to a Magento 2 site from the command line, SSH to the server and change to the root directory of the Magento 2 install. Then run this command:

On a server with Plesk a few notes:

  • It’s best to run this command as the user that owns the website subscription.
  • You may need to set the path to the correct PHP version with “export PATH=/opt/plesk/php/7.0/bin/php:$PATH”.
  • If you get “PHP Fatal error: Allowed memory size of xxxxxxx bytes exhausted” then edit the php.ini file for the correct PHP version and increase the “memory_limit” setting.

 

0

WordPress Admin Dashboard Slow Due To WordFence

Recently worked a WordPress site where the admin dashboard was taking a minute or more to load. Tracked the problem to the “Updates Needed” section in the “WordFence” block displayed on the dashboard. The Updates Needed section calls the WordPress  “wp_version_check()” function. This function, as part of building the data sent to wordpress.org with the update version check, calls the WordPress “count_users()” function. The “count_users()” function runs a query like this:

The number of “COUNT(NULLIF” columns depends on the number of user groups. For a site with a small number of users and groups this query is not a problem. But for a site with over 100K users this query took over 100 seconds to run.

To fix the problem, we used “wp-cli” to disable the “Updates Needed” section in WordFence:

Now the admin dashboard loads with no delay. This is a great example of the types of problems that come with scaling a WordPress site to large numbers of users.

 

 

 

0

WordFence / CloudFront – Automatically Update Trusted Proxies

If you are using WordPress with CloudFront and WordFence then some extra configuration is required. WordFence does blocking based on IP address but it will fail to determine the correct IP address when you have CloudFront and an Elastic Load Balancer in front of the site. The work around is to setup a cronjob that updates the list of trusted proxies in WordFence.

  1. Login to WordPress admin and to to WordFence -> All Options. Under “How does Wordfence get IPs” select “Use the X-Forwarded-For HTTP header”.  Click “Save Changes”
  2. Add a cronjob using the script shown below to update the list of trusted proxies.

Here’s a simple script for the cronjob:

 

 

 

0

.htaccess – negative file type match

Here’s an example of how to block all files extensions not listed in the regular expression:

 

0