Extra Password protection for wordpress

In cPanel, there is an option to lock the folders with a password. In normal case, it wont work with WordPress. In my case, below steps worked fine.

1. Add password authentication for the folder with wordpress files from cPanel
2. Create the user and password

3. Add following lines to the .htaccess file in the wordpress root directory

ErrorDocument 401 ./error.html
ErrorDocument 403 ./error.html

 

4. Final .htaccess will look as below:

#next two lines allow password protected directories with 404 errors
ErrorDocument 401 ./error.html
ErrorDocument 403 ./error.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /dev/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dev/index.php [L]
</IfModule>

# END WordPress
#-- Following lines are added for password authentication in the site
AuthUserFile "/home/user_name/.htpasswds/public_html/sub_domain/passwd"
AuthName "dev"
AuthType Basic
require valid-user

 

 

Enjoy 🙂

Bash script to take Mysqldump hourly and daily

Create a script as below and make it executable:

#!/bin/bash
Now_hourly=$(date +%d-%b-%H_%M)
Now_daily=$(date +%d-%b-daily)
if [ "$1" == "hourly" ]; then
/usr/bin/mysqldump --all-databases | gzip -c | cat > /Backup_location/mysql_dump_all$Now_hourly.sql.gz
elif [ "$1" == "daily" ]; then
/usr/bin/mysqldump --all-databases | gzip -c | cat > /Backup_location/mysql_dump_all$Now_daily.sql.gz
else
echo "Error. Enter hourly or daily";
fi

Now add the script in crontab for the hours it should run.

15,30 1,3 * * * script_name hourly
10,20 2,4 * * * script_name daily

Hourly backup will run at 01:15,01:30,03:15 and 03:30

Daily backup will run at 02:10,02:20,04:10 and 04:20 (since name would be same, it will replace each daily backup before)

webmail or cpanel shows internal server error

I got internal server error while accessing the below links:

domain.com/webmail

or

domain.com/cpanel

But the links are working fine while using the corresponding ports 2095 and 2082.

1. Check the apache error log:

/usr/local/apache/logs/error_log

In my case,

[Thu Dec 15 13:17:20.428541 2013] [cgi:error] [pid 15708] [client IP:21587] AH01215: suexec policy violation: see suexec log for more details
[Thu Dec 15 13:17:20.428591 2013] [cgi:error] [pid 15708] [clientIP:21587] End of script output before headers: redirect.cgi

The apache error log referred to suexec restrictions causing the 500 error. I checked the suexec log and found the following error.

/usr/local/apache/logs/suexec_log
[2013-12-15 13:18:24]: invalid target user id: (710)
[2013-12-15 13:18:26]: invalid target user id: (710)

I checked /etc/password and the user does exist.

grep 710 /etc/passwd
sasdfadfox:x:709:710::/home/sasdfadfox:/usr/local/cpanel/bin/noshell

Seeing that the problem was not with the user and more likely a configuration issue with the httpd.conf

Rebuild the apache configuration using the below script :

/scripts/rebuildhttpdconf

Enjoy !!! 🙂

Mount a LVM from additional harddisk

On period you may have to mount a lvm from an additional hard disk which was using as primary before. You can’t mount the lvm partition directly in the new machine. You can use the below commands to mount it successfully.

1. First, List all the disk partitions :

fdisk -l

2. Scan all the volume groups available :

vgscan

You can see all the volume groups available.

3. Note down the volume group name of the additional hard disk you have connected. Run the below command to activate it:

vgchange  'volume_group_name' -a -y

eg :  vgchange VolGroup80 -a -y

4. Now mount the partition:

mount lvm_name mount_point

Eg : mount /dev/VolGroup80/ROOT /mnt/

Enjoy !!! 🙂