Category Archives: Tutorials

How to install Apache HTTP Server service script

Recently, after some software and hardware changes, I was forced to rebuild a CentOS 6.5-based virtual machine.  Because the CentOS repository does not include Apache HTTP Server 2.4, and I’m not a big fan of third-party repositories, I decided to compile httpd from source.  When compiling the HTTP server from source, the system administrator is not provided with any service management script; thus, I began my search.

I found a simple service script in an archived version of an old Red Hat user guide, which made things a little easier.

#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve 
#	       HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
start)
echo -n "Starting httpd: "
daemon httpd -DSSL
echo
touch /var/lock/subsys/httpd
;;
stop)
echo -n "Shutting down httpd: "
killproc httpd
echo
rm -f /var/lock/subsys/httpd
rm -f /var/run/httpd.pid
;;
status)
status httpd
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reloading httpd: "
killproc httpd -HUP
echo
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit 0

To create the service script file, follow these directions:

# Create httpd script
touch /etc/init.d/httpd

# Upload, or copy and paste the script contents
nano /etc/init.d/httpd

# Set desired permissions
chmod 0755 /etc/init.d/httpd

# Start httpd on boot, if desired
chkconfig --add httpd
chkconfig httpd on

Upon careful review, you’ll notice the service script assumes that the httpd binary is globally accessible.  Under my minimal CentOS installation, httpd was installed in /usr/local/apache2. While there are more than a few methods for accomplishing this goal, we’ll use a symbolic link.

# Create symbolic link to apachectl
ln -s /usr/local/apache2/bin/apachectl /usr/sbin/httpd

After that, I executed the script which caused a “bad interpreter” error.

[root@localhost]# /etc/init.d/httpd
-bash: ./httpd: /bin/sh^M: bad interpreter: No such file or directory

This error occurs when a file contains CRLF-style line endings (Windows) instead of the LF-style line endings required by Unix-based systems. Luckily, someone invented a utility that fixes this problem quickly and painlessly.

# Install dos2unix
yum install dos2unix

# Fix "bad interpreter" error
dos2unix /etc/init.d/httpd

After that, I could start, stop, and restart the httpd server without any problems. On the other hand, when I tried to retrieve the status directly from the httpd binary (apachectl), I encountered another problem. Luckily, this problem was also easily solvable.

httpd status
# Output: /usr/sbin/httpd: line 95: lynx: command not found

# Install Lynx browser
yum install lynx

And… that’s it!

Using Gmail for Spiceworks’ Help Desk

Spiceworks LogoIn case you haven’t heard, Spiceworks is a free “network management & monitoring, help desk, PC inventory & software reporting solution to manage everything IT.”  I must admin, I was skeptical at first, but I ending up being very impressed with this software.  The only downside I’ve found so far is the presence of ads within the software; however, you’ll soon see it is still well worth it.  This software also requires Windows XP or higher, and will not run on Linux.  On the other hand, Spiceworks will detect and properly monitor any Linux-based PC on the network.  Below are some of the advantages of using Spiceworks:

  • 100% free
  • Can be used as portal, and help desk (includes full ticketing system)
  • Works with Active Directory
  • Will monitor software, DNS settings, disk space, etc., on all computers within network
  • Network map
  • Will monitor ink and toner levels in compatible printers/copiers
  • E-mail alerts can be configured to send in the event printer ink dips below a certain threshold
  • Compatible with Windows Server 2008 R2
  • …and much more!

Now, onto configuring Spiceworks to work with Gmail:

Within Gmail settings, make sure that IMAP is enabled.

Login to your Spiceworks installation.

Continue reading Using Gmail for Spiceworks’ Help Desk

Generate HTML drop downs from arrays & ranges with a PHP class

There comes a time (or a multitude of times) where a developer finds him- or herself rewriting the same code over and over again. Eventually, we get tired of it and need to find a solution. Recently, I frequently found myself writing code to generate HTML drop downs.  This became tedious, and I started to think it was unnecessary. But wait!  There must be a better way!  I didn’t want to use Zend_Form or any other 3rd party solution; I wanted to create my own class to help take care of this problem.  Below is the code/examples for the class, then a description of some of the methods, and lastly a link to download the source code.  As you can see, there are some nice features, and the class is easy to use and extend. Continue reading Generate HTML drop downs from arrays & ranges with a PHP class

Using PHPass password hasher with Zend Framework

In this tutorial, we will learn how to use PHPass, a portable PHP password hashing component, with the “glue”-based Zend Framework.  The popular PHP-based blogging platform WordPress utilizes PHPass to hash user passwords.  Using this library adds an extra level of security over a normal MD5-protected password. Continue reading Using PHPass password hasher with Zend Framework

Turning off Instant Search enable dialog in Outlook 2007

About two months ago, I began using Microsoft Office Outlook 2007, which I absolutely love. Microsoft has really done great things with this program over the years, although I must admit there are a few things I would change if I could. I also use Google Desktop, which enables me to index and search my entire computer, including e-mails, PDF files, and many other previously search-obscure file types. This is not unlike Microsoft’s solution which is called Instant Search. Microsoft Instant Search indexes files in a similar way, but I find that it hogs more resources and is generally not as good as Google Desktop.

Microsoft Office Outlook 2007 - Instant Search
Microsoft Office Outlook 2007 - Instant Search

Continue reading Turning off Instant Search enable dialog in Outlook 2007

Setting up virtual hosts with Apache on Windows XP

In this tutorial, we will discuss how to setup virtual hosts for your development environment (or production, if you wish) on Windows XP.  This will allow you to use URLs such as http://mywebsite/ instead of http://localhost/mywebsite/, which is much more realistic. Continue reading Setting up virtual hosts with Apache on Windows XP

Adding default database table prefixes in Zend Framework 1.9.x

Recently, I began working with Zend Framework 1.9.2 to restructure one of my web sites.  I learned how to create an extension of the Zend_Db_Table_Abstract from a great “Getting Started” tutorial, but I found myself rewriting the table prefix with each and every new table.  Below I explain one solution to this problem, but I am new to Zend Framework, so please feel free to recommend a better, more integrated way of doing this, if you know of anything.

Step 1:  application.ini

Place the following code in your /application/configs/application.ini file:

[production]
table_prefix = "webjawns_"

Step 2:  TPC_DB_Table_Abstract class

Create a new class in the library directory. For this example, we’ll use TPC_DB_Table_Abstract as the name, which will be stored in /library/TPC/DB/Table/Abstract.php.

<?php
class TPC_DB_Table_Abstract extends Zend_Db_Table_Abstract {
	protected function _setupTableName() {
		global $application;

		parent::_setupTableName();
		$prefix = $application->getOption('table_prefix');

		$this->_name = $prefix . $this->_name;
	}
}

Step 3:  /application/Bootstrap.php

After that, you’ll want to make sure that the new Abstract.php file is referenced in your /application/Bootstrap.php file.

protected function _initAutoload() {
	$moduleLoader = new Zend_Application_Module_Autoloader( array(
		'namespace' => '',
		'basePath' => APPLICATION_PATH ) );
	$moduleLoader->addResourceType('', '../library/TPC', 'TPC');
	return $moduleLoader;
}

Step 4:  /application/models/DbTable/NewTable.php

To use the table prefix, we will basically be substituting Zend_Db_Table_Abstract with TPC_DB_Table_Abstract.  See the example below:

class Model_DbTable_NewTable extends TPC_DB_Table_Abstract {
	// Database name will be $prefix + $_name
	protected $_name = 'newtable';
}

This is just one way to create default table prefixes for each of your tables. I’m sure this isn’t the only way, and there may even be better, easier ways to do this. As an added bonus, we use the TPC_DB_Table_Abstract class to extend the Zend database functionality even further. If anyone else has any ideas about how to use default table prefixes (other than using a constant), please feel free to share them so we can all benefit.

Create a slide down menu with toggle button using jQuery

Recently, I have come to find myself recreating the same code over and over again for jQuery slide down menus equipped with one button to toggle display. There’s nothing complex about this code, but it will give beginners the gist of how to do accomplish the task. For this example, we will use jQuery 1.3.2, delivered from Google’s CDN.

On a side note, using a CDN like Google’s can lessen the load on your server, and will actually help reduce overall bandwidth usage on the web as whole. If a visitor has already downloaded the jQuery library from Google’s CDN, the majority of the time they won’t need to do it a second time if you implement this strategy.

The Google CDN address for jQuery 1.3.2 can be implemented using the following code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

HTML:

<input type="button" id="hidden_menu_button" value="Toggle Menu" />
<div id="hidden_menu" style="display: none;">
	<label><input type="checkbox" />Checkbox #1</label>
	<label><input type="checkbox" />Checkbox #2</label>
</div>

JavaScript:

<script type="text/javascript">
(function($) {
	$("#hidden_menu_button").click(function() {
		if ( $("#hidden_menu").is(":hidden") ) {
			$("#hidden_menu").slideDown("normal");
		} else {
			$("#hidden_menu").slideUp("normal");
		}
	});
})(jQuery);
</script>

View Demo