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.

# 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/
# config: /etc/httpd/conf/httpd.conf

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

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

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!

TPC! Memory Usage 0.9.1 released

After receiving countless emails from supportive users (some nice, some not so nice!), I put the TPC! Memory Usage project back on my ticker.  Despite the vast number of updates to WordPress since December 2010, the Memory Usage plugin has retained the top spot in its niche.  To this day, TPC! Memory Usage is used regularly with only one noticeable problem—a missing bar graph background in the dashboard widget.  As of release 0.9.1, the background has been fixed, and the compatibility data updated for WordPress 3.8.

So… what’s in store for the future?  First, I need to refactor the code to take care of a few notices outputted in debug mode.  In addition, some of the Zend Framework dependencies may be updated, or even eliminated.  Lastly, I’ll put my ear back to the community.  In other words, tell me what you want, and we’ll see what we can do to reach that goal!

Download TPC! Memory Usage 0.9.1 for WordPress