Redirecting a subdirectory to another domain: Apache

This can be done by including the following directives:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

ProxyPass /mail http://apollo.drjoel.info/mail
ProxyPassreverse / http://apollo.drjoel.info/

These should be included in the file:

/etc/apache2/httpd.conf if you have a single site on the server

/etc/apache2/sites-enabled/site.com.conf if you host it on i-mscp

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Deny website to certain ips

Add the following to your .htaccess:

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 10.5.3.33

This will block the ip from accessing the site.

To block a range 10.5.3.3-10.5.3.40:

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 10.5.3.3/32
deny from 10.5.3.4/30
deny from 10.5.3.8/29
deny from 10.5.3.16/28
deny from 10.5.3.32/29
deny from 10.5.3.40/32

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Image has failed to upload due to an error – Missing a temporary folder

This error might have occured on WordPress for you: “Image has failed to upload due to an error – Missing a temporary folder”.

Reason?

  • It may be a permission issue for the php temporary folder
  • The php temp folder may not exist.

Solution?

  • Find the php.ini file for your webhost. 
  • Locate the temp folder
  • Create the temp folder if it does not exist
  • Give it proper permissions

In my case, I had transferred my site transhost, and hence this folder was actually missing.

My php.ini file (generated by i-mscp) was at this location: /var/www/fcgi/mysite/php5/php.ini

Once php.ini file was located, I needed to find the temp folder used by php:

#grep -in 'upload_tmp_dir' /var/www/fcgi/mydomain/php5/php.ini
875:upload_tmp_dir = "/var/www/virtual/mydomain//phptmp/"

Since this folder was missing, I created it and provided proper permissions and then restarted apache2:

#mkdir "/var/www/virtual/joel.co.in/phptmp/"
#chmod 755 "/var/www/virtual/joel.co.in/phptmp/"
#chown -R vu2003.www-data "/var/www/virtual/joel.co.in/phptmp/"
#service apache2 restart

Now, I could upload media files again.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Redirect one site to another with .htaccess

Add the following to your .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^droidzone\.asia$ [OR]
RewriteCond %{HTTP_HOST} ^www\.droidzone\.asia$
RewriteRule ^(.*)$ "http\:\/\/droidzone\.in\/$1" [R=301,L]

This redirects droidzone.asia to droidzone.com, when residing in the public html folder of droidzone.asia


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Promoting affordable VPS

There was a time when I was developing Android roms, I longed to have my own VPS. Those initial two to three years found me hosting all my work and my personal sites on c0urier’s personal server. Make no mistake, I am extremely greateful to him and his company Kazi networks for providing free use of their space for my roms. But there comes a time when just having ftp space becomes unwieldy, especially when you have to move around huge files and need to write php scripts to make your site more interactive.

After nearly a year of languishing in the darkness, I found Low end box, better known in hosting circles as LEB. LEB is a site build on WordPress, dedicated to low end VPS hosting services. Their motto is to popularize VPS hosting solutions under $7 a month. A most just and exemplary concept. It gets tens of hundreds of VPS offers a month, and subscribers (free) of course get to see offers from a lot of mainstream VPS providers, all of which are below the $7 a month range.

I myself have gobbled up decent boxes from LEB. My most popular boxes are from MyRSK, Servermania, and Wills hosting. All three of these providers provide fairly decent boxes.

My MyRSK box provides 2GB RAM, 200GB HDD space, 100Mbit port and 1 ip at $7 a month. Servermania’s offering was a 1GB RAM + 1GB Vswap with 75 GB disk space, 100Mbit port. My present favorite box is a 512 MB RAM + 512 MB Vswap, 60GB hard disk space and 1Gbit port from Will’s hosting. I used to heavily use XDA and Goo build servers for hosting, but though they’re good for hosting, they had limitations. The XDA SSH buildbot had and still has issues with menuconfig.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Reverting from wordpress development version to mainstream version

You need to do a manual update as follows:

Backup both files and database of your site, to offline location.

Now, delete wp-admin and wp-includes from old location

Copy over wp-admin and wp-includes from new location

Copy (without subdirectories) all files from root of wordpress zip(tar) file.

More detailed instructions are here.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Disable updraft plus ads and multisite warning

I hate advertisements. Whatever the reason, like using a free plugin, or visiting a website, I think forcing advertisements is a bad idea. Hence, having an advertisement at the top of every page on my dashboard, and others on a plugin settings page particularly made me irritated.

The plugin which is the subject for this is “Updraft Plus” backup plugin for wordpress blogs.

On top of displaying a banner stating that the plugin is incompatible with WordPress multisite installations, it also places advertisements in the plugin settings page.

It turns out that these ads depend on the presence of the definition of a single constant in the php file.

So to remove them, edit your wp-content/plugins/updraftplus/updraftplus.php

Add the following constant:

const UPDRAFTPLUS_PREMIUM='yes';

after the beginning php tag, so it looks like:

<!--?php
/*
Plugin Name: <span class="hiddenSpellError" pre=""-->UpdraftPlus - Backup/Restore
Plugin URI: http://wordpress.org/extend/plugins/updraftplus
Description: Backup and restore: your content and database can be automatically backed up to Amazon S3, Dropbox, Google Drive, FTP or email, on separate schedules.
Author: David Anderson
Version: 1.4.11
Donate link: http://david.dw-perspective.org.uk/donate
License: GPLv3 or later
Author URI: http://wordshell.net
*/
const UPDRAFTPLUS_PREMIUM='yes';
/*
TODO

Wham! All the ads and the big ugly banner is gone!

As of the latest version, the above no longer works. I will leave you to figure out for yourself how to fix the ads and the warning.

Disclaimer: I encourage you to buy Updraft plus to encourage the author’s efforts. The code is well within the realm of GPLv3 and you’re free to make any modifications you want, and distribute it, however.

Update: The following patch has been updated to work with Updraftplus 1.4.14:

--- /root/updraftplus/options.php       2013-02-20 21:23:54.340665318 +0530
+++ ../updraftplus/options.php  2013-02-20 21:33:01.900748290 +0530
@@ -77,7 +77,7 @@ class UpdraftPlus_Options {
        }

        public static function show_admin_warning_multisite() {
-
+       return ;
                global $updraftplus;

                $updraftplus-&gt;show_admin_warning('&lt;strong&gt;UpdraftPlus warning:&lt;/strong&gt; This is a WordPress multi-site (a.k.a. network) installation. &lt;a href="http://updraftplus.com"&gt;WordPress Multisite is supported by UpdraftPlus Premium&lt;/a&gt;. Non-premium UpdraftPlus does not support multi-site installations securely. &lt;strong&gt;Every&lt;/strong&gt; blog admin can both back up (and hence access the data, including passwords, from) and restore (including with customised modifications, e.g. changed passwords) &lt;strong&gt;the entire network&lt;/strong&gt;. Unless you are the only blog admin user across the entire network, you should immediately de-activate UpdraftPlus. (This applies to all WordPress backup plugins unless they have been explicitly coded for multisite compatibility).', "error");
--- /root/updraftplus/updraftplus.php   2013-02-20 21:23:54.339662943 +0530
+++ ../updraftplus/updraftplus.php      2013-02-20 21:31:28.415766309 +0530
@@ -9,7 +9,7 @@ Donate link: http://david.dw-perspective
 License: GPLv3 or later
 Author URI: http://wordshell.net
 */
-
+const UPDRAFTPLUS_PREMIUM='yes';
 /*
 TODO
 //Put in old-WP-version warning, and point them to where they can get help

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Disable updraft plus multisite notice

Updraft plus is an awesome plugin. Very useful for backing up one’s site. However the author of this free plugin has chosen to display a huge ugly red banner warning an administrator that a premium is better suited for a mu installation of WordPress. He has not provided a way to disable it via options. So if this bothers you, patch your file:

--- up2/updraftplus/options.php 2013-02-14 20:39:08.000000000 +0400
+++ /root/domains/joel.co.in/droidzone.in/htdocs/wp-content/plugins/updraftplus/options.php     2013-02-16 10:58:01.610660848 +0400
@@ -67,7 +67,7 @@ class UpdraftPlus_Options {
                register_setting('updraft-options-group', 'updraft_include_others_exclude' );

                if (is_multisite()) {
-                       add_action('admin_notices', array('UpdraftPlus_Options', 'show_admin_warning_multisite') );
+                       //add_action('admin_notices', array('UpdraftPlus_Options', 'show_admin_warning_multisite') );
                }

        }

Disclaimer: I encourage you to buy Updraft plus to encourage the author’s efforts. The code is well within the realm of GPLv3 and you’re free to make any modifications you want, and distribute it, however.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Wrap a php parser file in WordPress theme

I created a form parser for a WordPress site that would parse the contents of a posted form, and display a success page. I used pure php instead of trying to use a WordPress template or theme. As a downside, the displayed page would not show any WordPress theme.

So I found a solution to import the theme for the php, and this is by including the theme’s header and footer in the php file.

The complete form parser is included below:

<?php

// If title is not displayed before loading the header, WordPress displays "Page not found" as the title

echo "<head>
<title>Your form has been submitted</title>
</head>";

// Include the Main WordPress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";

// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/studiopress/genesis/header.php";

// Your custom code STARTS here

// My code includes two functions. 
// The first part is the background activity which parses the form, checks for errors and then mails it if there arent any errors
// The second part is html code that is displayed to the user to inform them that the form has been submitted.

if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Someone has submitted feedback on your website";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers

$headers = 'From: [email protected]'."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<?php
// Second part starts.
// This part is displayed.

echo "
<h2>
Your form has been submitted
</h2>";

echo "<h4>Dear $first_name,</h4>
<p>Your feedback has been received by us and will be forwarded to the site administrator. You will receive your login details or a response soon.</p>";

echo "<br /><br /><br /><br /><br /><br /><br />
Click <a href=\"http://www.site.com\">here</a> to return to the site.";
// END of custom code

?> 

<?php
}
include $_SERVER['DOCUMENT_ROOT']."/wp-content/themes/studiopress/genesis/footer.php";
?>[/code]
The following is the actual form:
You can use the following form to contact the administrator of this site:

<form action="../phpscripts/send_form_email1.php" method="post" name="contactform">Note: If you're requesting login rights, please add information on how you're related to the family.&nbsp;
<table width="450px">
<tbody>
<tr>
<td valign="top"><label for="first_name">First Name *</label></td>
<td valign="top"><input type="text" maxlength="50" name="first_name" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name *</label></td>
<td valign="top"><input type="text" maxlength="50" name="last_name" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" maxlength="80" name="email" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" maxlength="30" name="telephone" size="30" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments *</label></td>
<td valign="top"><textarea cols="30" maxlength="1000" name="comments" rows="6"></textarea></td>
</tr>
<tr>
<td></td>
<td style="text-align: left;" colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form>[/code]
Version 0.2

I made it generic and detect the proper active theme:
&lt;?php

// If title is not displayed before loading the header, WordPress displays "Page not found" as the title

echo "&lt;head&gt;
&lt;title&gt;Your feedback has been submitted&lt;/title&gt;
&lt;/head&gt;";

// Include the Main WordPress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";

//bloginfo(‘template_url’);
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "&lt;br/&gt;The relative path to the currently active theme is ".$newss;

// Include the specific theme header you need
//echo "Full path to header is ".$_SERVER['DOCUMENT_ROOT'].$newss."/header.php";
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";

// Your custom code STARTS here

// My code includes two functions. 
// The first part is the background activity which parses the form, checks for errors and then mails it if there arent any errors
// The second part is html code that is displayed to the user to inform them that the form has been submitted.

if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "Someone has submitted feedback on your website";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.&lt;br /&gt;&lt;br /&gt;";
        echo $error."&lt;br /&gt;&lt;br /&gt;";
        echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.&lt;br /&gt;';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.&lt;br /&gt;';
  }
  if(strlen($comments) &lt; 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.&lt;br /&gt;';
  }
  if(strlen($error_message) &gt; 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers

$headers = 'From: [email protected]'."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?&gt;

&lt;?php
// Second part starts.
// This part is displayed.

echo "
&lt;h2&gt;
Your feedback/request has been submitted
&lt;/h2&gt;";

echo "&lt;h4&gt;Dear $first_name,&lt;/h4&gt;
&lt;p&gt;Your feedback has been received by us and will be forwarded to the site administrator. 
&lt;br/&gt;
You will receive your login details or a response soon.&lt;/p&gt;";

echo "&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
Click &lt;a href=\"http://www.vettathu.com\"&gt;here&lt;/a&gt; to return to the site.";
// END of custom code

//Useful wordpress functions
/*
echo "The current theme name is".get_current_theme()."&lt;br/&gt;";

echo "&lt;br/&gt;";
echo "The dir is ".$ddir."&lt;br/&gt;";

echo "The home url is".$homeurl."&lt;br/&gt;";
*/
//$newdirst=str_replace($homeurl,".",$temp_ddir);

/*
echo "Length of whole is ".strlen($ddir);
echo "Length of substring is ".strlen($homeurl);

*/

?&gt; 

&lt;?php
}
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";

?&gt;

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.

Mirror an entire site via ftp, on the bash shell

Use the following command to mirror an entire site via wget and ftp:

wget -m [email protected] --password=mypassword ftp://ftp.droidzone.in/*

 

Here,

Host: ftp.droidzone.in

Username: username

Password: mypassword

This format of wget takes care of extraneous characters like the @ symbol and any colons in the username or password.

The -m option mirrors the site. This is useful if your site doesnt have rsync/ssh access.


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.