How to repair a crashed WordPress database table

If you have root access on the host (e.g., VPS) where a MySQL sever is running, you can try command-line interface to fix the crashed database table.

For a MyISAM-type database, you can fix a crashed table with a command-line utility called myisamchk. This utility comes with MySQL server installation.

First, stop MySQL server.

$ sudo service mysql stop (Debian/Ubuntu)
$ sudo service mysqld stop (CentOS/RHEL)
$ sudo systemctl stop mysqld.service (Fedora)

Then use this command to fix a particular table.

$ cd /var/lib/
$ sudo myisamchk -r -v -f mysql/<database_name>/<table_name>

Finally, start MySQL server again.

Restore InnoDB Functionality

/etc/init.d/mysql stop

cp /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile0.bak
cp /var/lib/mysql/ib_logfile1 /var/lib/mysql/ib_logfile1.bak

Add the following line into /etc/my.cnf
    innodb_force_recovery = 4

/etc/init.d/mysql start
Comment out innodb_force_recovery in /etc/my.cnf
Restart mysqld

Codeigniter LIKE Query

$CI->db->like('office_name', 'Abbot', 'none');
$query = $CI->db->get();

How to set up Virtual Hosts in Apache on Mac OSX 10.11 El Capitan

he process of setting up Virtual Hosts is done easier in the Terminal either using nano or viwith sudo or as a root user,  or you can you a GUI visual editor like Text Wrangler which allows access to the /private/etc directory by clicking ‘Show Everything” in the open dialog box.

Allow the vhosts configuration from the Apache configuration file httpd.conf

Open the httpd.conf

sudo nano /etc/apache2/httpd.conf

Search for ‘vhosts‘ and uncomment the include line

# Virtual hosts

Include /private/etc/apache2/extra/httpd-vhosts.conf

Also allow another module to run by uncommenting:

LoadModule vhost_alias_module libexec/apache2/


Edit the vhosts.conf file

Open this file to add in the virtual host.

sudo nano /etc/apache2/extra/httpd-vhosts.conf

An example domain in the file is given of the format required to add in additional domains, just follow this to create your new virtual host:

<VirtualHost *:80>
DocumentRoot "/usr/docs/"
ErrorLog "/private/var/log/apache2/"
CustomLog "/private/var/log/apache2/" common

We can take this example and extend on it, if you wanted a domain named for example, you can copy the existing text block and edit to suit:

<VirtualHost *:80>
DocumentRoot "/Users/USERNAME/Sites/apple"
ErrorLog "/private/var/log/apache2/"
CustomLog "/private/var/log/apache2/" common

So in the example above a vhost for is created and the document root is in the Sites folder, in the text block above I have also added in some log files, what you need to change is the document root location username and domain name to suit your needs. Finish and save the file.

Now also you need to map the IP address to be the localhost.


Map Your IP address to localhost

sudo nano /etc/hosts

Add the Domain and ‘www‘ alias to resolve to the localhost address


Restart Apache

sudo apachectl restart

Check out your local vhost domain in the browser


Losing Localhost

One caveat to note about virtual hosts is that once set up you lose your older document root previously at /LIbrary/WebServer/Documents or accessed in the browser athttp://localhost what happens is that you get a 403 Forbidden Error. But the ~/username document root is still compatible.

To get around this, you need to add in a vhost for localhost and declare this vhost before any of the others, in the same file:

sudo nano /etc/apache2/extra/httpd-vhosts.conf

Add in:

<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/

Restart Apache

sudo apachectl restart

Changing the WebServer Default User

One of the frustrations of using the Users/username/Sites folder for vhosts is the permissions issues with things like updates and authentication.


This is because the default webserver user which runs httpd is known as _www, which will not be the user in your local account. If your machine is only in use by you and the webserver will run only under your account then you can change the user.

Find Your User and Group

In the Terminal use the id command to see your username and group


You will get a bunch of user groups, you need your primary user uid and group gid names

uid=502(your_user_name) gid=20(staff)

Change this back in /etc/apache2/httpd.conf

# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#User _www
#Group _www

User your_user_name
Group staff

Restart Apache

sudo apachectl restart

Restart Apache and now you are running httpd as your local account.

[] FAILED: tailwatchd (

If you are receiving a notification from cPanel like as below. 

The service “tailwatchd” appears to be down.
Primary IP Address104.131.85.212
Service Nametailwatchd
Service Statusfailed 
NotificationThe service “tailwatchd” appears to be down.
Service Check Raw Output
The “tailwatchd” service is down.
Startup Log
[Thu Jun 25 00:34:19 2015] Starting /usr/local/cpanel/libexec/tailwatch/tailwatchd daemon
Log is at /usr/local/cpanel/logs/tailwatchd_log
tailwatchd is already running. at /usr/local/cpanel/Cpanel/ line 532.
Memory Information
Used695 MB
Available3.19 GB
Installed3.87 GB
Load Information0.46 0.34 0.14
IOStat Information
avg-cpu:%user %nice %system %iowait%steal %idle 97.96
Device:tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
vda 4.41 279.65 136.95 3138086548 1536825192

Don't worry this is just a notification from cPanel server, now login to your server via ssh and check if tailwatchd service is running or not by running following command:

#/usr/local/cpanel/libexec/tailwatchd --status

And follow the instructions from TAILWATCHD:


Cpanel::TailWatch::Eximstats appears to have unprocessed SQL in /var/cpanel/sql/eximstats.sql.

When mysql is unable to execute a query they are logged for processing later.

Eventually these SQL files may be handled automatically and this message will not appear.

In the meantime you can execute the queries as root with something like this:

mv /var/cpanel/sql/eximstats.sql /var/cpanel/sql/eximstats.sql.tmp_working_copy


mysql eximstats < /var/cpanel/sql/eximstats.sql.tmp_working_copy

Once you are sure all is well you can remove /var/cpanel/sql/eximstats.sql.tmp_working_copy



tailwatchd is enabled

Running, PID 28932

Driver (Active: 1) Cpanel::TailWatch::cPBandwd

Driver (Active: 0) Cpanel::TailWatch::JailManager

Driver (Active: 1) Cpanel::TailWatch::Eximstats

Driver (Active: 1) Cpanel::TailWatch::ChkServd

Driver (Active: 0) Cpanel::TailWatch::Antirelayd

Driver (Active: 1) Cpanel::TailWatch::ModSecLog

Cpanel update failure in upcp -- Digital Ocean VPS

Running `/usr/local/cpanel/scripts/updatenow --upcp --log=/var/cpanel/updatelogs/update.1434828883.log` failed, exited with code 12 (signal = 0)

The fix for this error was to temporarily upgrade from the base Digital Ocean tier ($5/mo - 512MBMemory - 1 CoreProcessor - 20GBSSD Disk - 1TBTransfer) to the $10 plan. Apparently the WHM/cPanel 11.50.0 upgrade could not complete on the base specs.

Magic Mouse Lag / Stuttering OS X Yosemite 10.10

Small fix so that I don't have to restart my computer every time it starts lagging:

ALT + Shift  + click on bluetooth icon in menubar > Create Diagnostics Report on Desktop

After that the mouse lag should stop after a few seconds.

Grocery CRUD simple DUPLICATE row method

public function manage()
$crud = new grocery_CRUD();
$crud->add_action('DUPLICATE', '', 'cms/offices/duplicate','ui-icon-plus');
$output = $crud->render();
$this->load->view('cms/office_view.php', $output); 

}catch(Exception $e){
show_error($e->getMessage().' --- '.$e->getTraceAsString());

function duplicate($primary_key, $row)
$query = $this->db->get_where('office', array('office_id' => $primary_key));
if ($query->num_rows() > 0)
$res = $query->result();
$row = $res[0];
$data = array(
'ordinal_number' => $row->ordinal_number+1,
'ordinal_text' => $row->ordinal_text,
'office_name' => $row->office_name,
'TBRC_P_ID' => $row->TBRC_P_ID,
'start_date' => $row->start_date,
'end_date' => $row->end_date,
'community_TBRC_ID' => $row->community_TBRC_ID,
'tradition' => $row->tradition,
'office_TBRC_R_ID' => $row->office_TBRC_R_ID,
'description' => $row->description

 $this->db->insert('office', $data); 


PHP strip certain tags with strip_tags

You cannot strip a certain list of tags with PHP’s strip_tags() function, you can only strip ‘all but’ tags.

So in order to do so, you’ll need to use regular expressions to do it swiftly:

$strip_list = array('strong', 'p', 'div');
foreach ($strip_list as $tag)
$string = preg_replace('/<\/?' . $tag . '(.|\s)*?>/', '', $html);

OS X Yosemite 10.10 Fixes

Wi-Fi Issues

In Yosemite, Macs are using Bonjour over Apple Wireless Direct Link (AWDL) to discover devices to connect to for AirDrop, AirPlay, and other services. AWDL is a low-latency, high-throughput, peer-to-peer connection that runs over Wi-Fi but has its own dedicated network interface (much like general Wi-Fi or Ethernet). In the past, Bonjour was used only over standard Wi-Fi networks or Bluetooth. But when it works over AWDL, it appears to strain the hardware, hurting performance.

Fortunately, it’s easy to disable AWDL, but the fix also disables AirDrop and requires working at the command line. Copy the line below and, at the command line in Terminal, paste it, press Return, and enter your password. (Unfortunately, it doesn’t persist between reboots, so you’ll have to apply the fix every time you reboot your Mac.)

sudo ifconfig awdl0 down

If you see the error message “ifconfig: interface awdl0 does not exist,” you have older hardware that doesn’t support AWDL.

You can re-enable AWDL and AirDrop without rebooting by entering this line in the Terminal.

sudo ifconfig awdl0 up

Save Dialogs Expand Offscreen

Have you ever tried to save a document, only to find that you can’t see the Save button because it’s off the screen? A bug in Yosemite can apparently make Save dialogs grow in height by 22 pixels each time one is opened.

Hold the Shift key down, hover over the left or right edge of the dialog until the cursor becomes opposing arrows, and then drag inward to shrink the Save dialog.

ConfigServer Security & Firewall Installation

Installation is quite straightforward:

rm -fv csf.tgz
tar -xzf csf.tgz
cd csf

Next, test whether you have the required iptables modules:

perl /usr/local/csf/bin/

Don't worry if you cannot run all the features, so long as the script doesn't report any FATAL errors

You should not run any other iptables firewall configuration script. For example, if you previously used APF+BFD you can remove the combination (which
you will need to do if you have them installed otherwise they will conflict):

sh /usr/local/csf/bin/

That's it. You can then configure csf and lfd by reading the documentation and configuration files in /etc/csf/csf.conf and /etc/csf/readme.txt directly or
through the csf User Interface.

csf installation for cPanel and DirectAdmin is preconfigured to work on those servers with all the standard ports open.

csf auto-configures your SSH port on installation where it's running on a non- standard port.

csf auto-whitelists your connected IP address where possible on installation.

You should ensure that kernel logging daemon (klogd) is enabled. Typically, VPS servers running RedHat/CentOS v5 have this disabled and you should check /etc/init.d/syslog and make sure that any klogd lines are not commented out. If you change the file, remember to restart syslog.

See the csf.conf and readme.txt files for more information.

Extract sql.gz file on command line

If you want to extract the sql.gz backup file using the terminal command, here is the command to run

 gzip -d backup-20100910164109.sql.gz

This will create the .sql file for you. For more options, hit man gzip on your terminal.

Transferring files over SSH

If copying to/from your desktop machine, use WinSCP, or if on Linux, Nautilus supports SCP via the Connect To Server option.

scp can only copy files to a machine running sshd, hence you need to run the client software on the remote machine from the one you are running scp on.

If copying on the command line, use:

# copy from local machine to remote machine
scp localfile user@host:/path/to/whereyouwant/thefile


# copy from remote machine to local machine
scp user@host:/path/to/remotefile localfile

How to Install Oracle Java 8 (JDK 8u25) on CentOS

After a long wait, finally Java SE Development Kit 8 is available to download. JDK 8 has been released on Mar,18 2014 for general availability with the many featured enhancements. You can find all the enhancements in JDK 8 here.

This article will help you to Install JAVA 8 (JDK 8u25) or update on your system. Read instruction carefully for downloading java from Linux command line. To Install Java 8 in Ubuntu and LinuxMint read This Article.

Step 1: Download JAVA Archive

Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from shell.

For 64Bit

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

# tar xzf jdk-8u25-linux-x64.tar.gz

For 32Bit

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

# tar jdk-8u25-linux-i586.tar.gz

Note: If Above wget command doesn’t not worked for you watch this screencast to download JDK from terminal.

Step 2: Install JAVA using Alternatives

After extracting archive file use alternatives command to install it. alternatives command is available in chkconfig package.

# cd /opt/jdk1.8.0_25/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_25/bin/java 2
# alternatives --config java

There are 3 programs which provide 'java'.

*1 /opt/jdk1.8.0/bin/java
 + 2 /opt/jdk1.7.0_55/bin/java
 3 /opt/jdk1.8.0_25/bin/java

Enter to keep the current selection[+], or type selection number: 3

At this point JAVA 8 has been successfully installed on your system. We also recommend to setup javac and jar commands path using alternatives

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_25/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_25/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_25/bin/jar
# alternatives --set javac /opt/jdk1.8.0_25/bin/javac 

Step 3: Check Version of JAVA .

Check the installed version of java using following command.

# java -version 

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Step 4: Setup Environment Variables

Most of java based application’s uses environment variables to work. Set the java environment variables using following commands

# export JAVA_HOME=/opt/jdk1.8.0_25
# export JRE_HOME=/opt/jdk1.8.0_25/jre
# export PATH=$PATH:/opt/jdk1.8.0_25/bin:/opt/jdk1.8.0_25/jre/bin
  • Setup JAVA_HOME Variable
  • Setup JRE_HOME Variable
  • Setup PATH Variable

Apache Benchmarking (ab) on CentOS

Apache Benchmark location on CentOS servers:

  1. # /usr/local/apache/bin/ab

Apache Benchmarking is a great tool for testing Apache performance on web servers, for example running the following bash command:

  1. # /usr/local/apache/bin/ab -n 100 -c 5

This will test 100 connections (-n), limited to 5 concurrent connections (-c) on the website

You can also run Apache Benchmarking straight from Mac terminal using:

  1. # ab -n 100 -c 5

Tip: make sure you end the url to test with a trailing slash or filename or the command won't work