Manually Adding an Admin User to a WP Database

Lost your admin password? Need in to the WP admin but client hasn’t given you access? If you can access the database directly–easiest using a tool like PHPmyAdmin–you can give yourself whatever access you need.  ((Big hugs and kisses out to DNA Web Agency for this uber-helpful information lifted for this tutorial.))

Locate the right database–if you have FTP, looking at the wp-config.php file at the root of your WP installation is the fastest route. Otherwise, if you have multiple WP installs, check out the options table to match urls and make sure you’re looking in the right database.

In your wp_users table, you insert a new record:

  1. user_login –username to access WordPress
  2. user_pass – password – be certain to select MD5 from the phpMyAdmin Function dropdown menu; it’s stored encrypted)
  3. user_nicename – how you’d like to refer to yourself, not login
  4. user_email – email for this user
  5. user_url – optional
  6. user_registered –  just select a date
  7. user_activation_key – leave this blank
  8. user_status – leave this set to 0
  9. display_name – what displays, can be same as nicename

Note the user ID, as you’ll need it for the next steps.

To give yourself access permissions, head on over to insert a record into the wp_usersmeta table.

  1. umeta_id – automatically generated
  2. user_id – ID of the user you just created
  3. meta_key –  wp_capabilities
  4. meta_value copy and paste this:

[code]a:1:{s:13:”administrator”;b:1;}[/code]

Insert another row, with this information:

  1. umeta_id – automatically generated
  2. user_id – use the ID you created
  3. meta_key – insert wp_user_level
  4. meta_value – insert 10

Save your work and go log in!

Share Button

Parking a Domain on top of An Addon Domain (cPanel)

Parking a domain on top of an addon domain in cPanel can be a quick, easy way to change the domain on a site without mussing with files or database connections and the like. If you’re using a database-driven site, however, be sure to make the relevant changes to the database.  ((Thanks to Hostgator Support for this helpful info.))

  1. Login to cPanel and click Addon Domains–and not parked domains.
  2. In the field to the right of “New Domain Name,” type the domain name you wish to park on top of your addon domain
  3. Click outside the text box and your other settings will populate.
  4. Under “Document Root:” remove everything except “public_html”
  5. Look down to your current addon domain and its “Document Root” – normally a folder named after the original domain.
  6. Take the “Document Root” and insert it in the field to the right of “Document Root:” at the top.
  7. Insert any password in the password field. (You won’t need to remember this password, so just use the Generate Password button.)
  8. Click Add Domain
Share Button

Releasing Items from Mailscanner Que

The easiest is to have your mailscanner configured to quarantine Whole Message as Queue files; from Chirpy with instructions for this and more, here.

Quarantine Whole Message = yes
Quarantine Whole Messages As Queue Files = yes

then to requeue the email to be delivered, you need to go to the indicated directory within:
/var/spool/MailScanner/quarantine/<date>/<message-id>/

Then you need to:
cp -av *-H /var/spool/exim/input/ ; cp -av *-D /var/spool/exim/input/
one done you’ll have to wait for the next exim mail queue run, or run it yourself from WHM > Manage Queue > <message-id> > Deliver Now

Share Button

Hosting Subdomain on a Different Server than Main Domain

There may be times where you want to host a subdomain on a different server than the main domain. To accomplish this, you need an A record, added either at the domain registrar if possible, or the server that hosts mydomain.com.

sub.mydomain.com. 14400 IN  A  XXX.XXX.XXX

The X’s should be replaced by the target server’s IP address. I prefer changing this info at the domain record level, since that doesn’t require cooperation of the main domain’s host, and thus can be changed by the domain owner in the event the target server’s IP changes.

For this to work, the subdomain MUST be added to the target server. A very simple way to do this is to add the main domain as an Addon in cPanel, and then set up the subdomain which will add all the relevant DNS entries (even though the main domain is not actually hosted on the target server). ((Caveat – I’ve found you may see occasional weirdness, though, with the approach described, such as a WordPress installation that requires uploads to go straight to the upload folder to work, instead of month and year-based folder settings. Would probably be better to add the subdomain to your server configuration directly for long-term robustness.))

Share Button

Restarting dbus via Command Line

As a companion to our “Restarting Haldaemon from the Command Line” piece (coming in handy after software update where you get those annoying ConfigServer firewall warnings “Suspicious process running under user dbus”), here’s what you need to do to restart dbus from the command line:

/etc/init.d/messagebus restart

Note: Your server configuration may vary.

Share Button

Disabling WordPress Plugins When You Cannot Access Admin Area

When you cannot access the admin of a WordPress installation because of a plugin issue, you can delete the plugins directly from a database management tool like PHPmyAdmin. (And if you can’t access the WP backend, there’s a good chance it is because of a plugin issue.)

This helpful tidbit comes from the WP FAQ

  • In the table wp_options, under the option_name column (field) find the active_plugins row
  • Change the option_value field to: a:0:{}

If you have FTP access, you can also rename your original plugin folder (/wp-contents/plugins) and and add an empty plugin folder. After you sign on to your WP admin area, you can delete the dummy folder and rename the plugin folder back to “plugins,” as it will have deactivated all  your plugins when you signed on with the empty folder.

Happy WordPressing!

Share Button

Eliminating Page Shift

Having done a few designs where I ended up pounding my head against the wall trying to figure out what was causing page shift–where the content seems to jump to the left or right on certain pages–I understand this can drive a poor designer insane.

It’s caused by inconsistencies between how browsers handle the vertical scroll bar combined with centered content. Some browsers, like Internet Explorer, display scrollbars on all pages, while others, like Firefox, do not.

Adding this code to your stylesheet will correct the issue. ((The “-moz-scrollbars” declaration takes care of this issue in Firefox 3.5+))

html { min-height: 100%; margin-bottom: 1px; overflow: -moz-scrollbars-vertical !important;}
Share Button

PHP Snippet: Display Last X Characters of a URL

Had a request to return the last 23 characters of a url. I am WAY not a coder, but was able to help modify this function to work. Of course, you probably won’t just want to echo the output, but use it as a variable for something else.

<?php function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
 }
 echo substr(curpageURL(),-23);?>
Share Button

SQL: Closing Comments on WordPress Installation

During domain propagation when changing hosts for a WordPress blog, you may want to close comments to keep from losing anything. While you can certainly use the WP comment template technique, this is an especially convenient way of turning off comments en masse on a WP installation.

After transferring the blog databases to the new host, access PHPmyAdmin on the old host with this bit of SQL; if you have a different prefix to your table that “wp_” you’ll need to adjust the command accordingly.

UPDATE wp_posts p SET comment_status = 'closed', ping_status = 'closed' WHERE comment_status = 'open'

This approach also makes it very easy for a client to check domain propagation. If the comments are closed, the site is being served from the old host. If comments are open, it’s being  served from the new host. Easy!

Share Button

Transferring Databases via SSH Command Line

Command Line Fu has a solution for those who have SSH access and need to move a database:

To create a new database with a different name:

ssh -C user@newhost "mysql -uUSER -pPASS -e 'create database NEW_DB_NAME;'" && mysqldump --force --log-error=mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@remotehost "mysql -uUSER -pPASS NEW_DB_NAME"

To use the same database name for target as the source:

mysqldump --databases --force --log-error=/root/mysql_error.log -uUSER -pPASS OLD_DB_NAME | ssh -C user@newhost "mysql -uUSER -pPASS"

If you’re using SSH on a non-standard port (recommended), you’ll need to add a parameter for it in your code after the ssh command, such as -p XXX, where “XXX” is replaced by your port number.

Share Button