Run Shell Script From Your Website

Here’s how to run a shell script from your website. You’ll need 2 files.

Here’s the contents of foo.php. Wrap your output with ‘pre’ for better formatting.

<?php
$output = shell_exec('/var/www/html/bar.sh 2>&1');
echo "$output";

Here’s the content of bar.sh. Output will be displayed on web page.

#!/bin/bash
now="$(date +'%y%m%d')"
echo $now
aws s3 ls

Phpinfo Blank Page

Here’s how to fix when phpinfo is displaying a blank page. The install is missing this php module.

apt install php libapache2-mod-php

Restart after install.

service apache2 restart

WordPress Numeric Pagination

Here’s how to add numeric pagination on your WordPress pages.

Add this code to functions.php.

function pagination($pages = '', $range = 4) {
	$showitems = ($range * 2)+1;
	global $paged;
	if(empty($paged)) $paged = 1;
	if($pages == '') {
		global $wp_query;
		$pages = $wp_query->max_num_pages;
		if(!$pages) {
			$pages = 1;
		}
	}
	if(1 != $pages) {
		echo '<p><div class="pagination"><span>Page' . $paged . ' of  ' . $pages . '</span>   ';
		if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo '<a href="' . get_pagenum_link(1) . '"><< First</a>';
		if($paged > 1 && $showitems < $pages) echo '<a href="'.get_pagenum_link($paged - 1).'">< Previous</a>';
		for ($i=1; $i <= $pages; $i++) {
			if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
				echo ($paged == $i)? '<span class="current">' . $i . '</span>' : '<a href="' . get_pagenum_link($i) . '"class="inactive">' . $i . '</a>';
			}
		}
		if ($paged < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($paged + 1) . '">Next ></a>';
		if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo '<a href="' . get_pagenum_link($pages) . '">Last >></a>';
		echo '</div></p>';
	}
}

To display, comment out ‘the_post_navigation’ function and add the ‘pagination’ function instead in your template files.

//the_posts_navigation();
pagination();

Code courtesy of webdesignsun.

PHP vs Node.js

If you would like to launch a new career as a front-end developer, which programming language would you choose? You have multiple options, but nothing could be as popular as PHP and Node.js. An article from ComputerWorld examines the strengths and weaknesses of both languages. Each language has their own pluses and minuses. PHP is simpler, with a deeper code base, easy access to databases, and it’s boosted by HHVM and the Hack language. Node.js is based on Javascript with thinner service calls. It works with JSON, and raw speed is unparalleled. Both languages has it’s own MVC frameworks. Perhaps, a hybrid solution of PHP and Node.js might be the best approach on some projects. It really depends on what you’re trying to achieve. If you want to code fast, you may choose PHP. If application raw speed is in order, then you may want to consider using Node.js.