Monthly Archives: April 2012

Why doesn’t my cron job run?

Possible reasons your cron job won’t execute:

  • Check your script
  • Type the exact content of your script in your terminal window and verify that is is working manually. Then, if your server supports it, check if it works when you execute manually from web interface.
  • Use full paths
  • Many servers will run scripts without full paths both from the command line and in the web interface; however, they may not run on schedule.
  • If you are using:
  • * * * * * cd /users/home/username/domains/mydomain.tld/web/public/folder; php -f cron.php > /dev/null 2>&1
  • Try this, with full paths:
  • * * * * *cd /users/home/username/domains/mydomain.tld/web/public/folder; /usr/local/bin/php -f cron.php > /dev/null 2>&1
  • The time is not set correctly
  • The time is usually GMT/UTC on your server. Don’t look at your system clock. Click here for instructions to see the date/time on your server. Also, verify that the correct minutes, hours, days, months, and weekdays are active.
  • Reference files have been moved or deleted
  • Check any files used in your script and make sure they are in the location referenced by your script.
  • Your cron job is not active
  • Make sure your cron job is marked active (not disabled)

Display date and time via unix command line

To display the date and time, enter the following in your terminal:
# date
Sample output:

[myserver:~] username$ date
Sunday, April 22, 2012  8:29:14 AM GMT

What version of Apache am I running?

Httpd is the Apache HyperText Transfer Protocol (HTTP) server program. To display the current apache version, type the following in your terminal window:
# httpd -v
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45

Output list of modules compiled into the server:

# httpd -l
This will not list dynamically loaded modules included using the LoadModule directive. To dump a list of loaded Static and Shared Modules:
# httpd -M
Sample output:

Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_file_module (shared)
 authn_alias_module (shared)
 authn_anon_module (shared)
 authn_dbm_module (shared)
 authn_default_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 authz_owner_module (shared)
 authz_groupfile_module (shared)
 authz_dbm_module (shared)
 authz_default_module (shared)
 ldap_module (shared)
 authnz_ldap_module (shared)
 include_module (shared)
 log_config_module (shared)
 logio_module (shared)
 env_module (shared)
 ext_filter_module (shared)
 mime_magic_module (shared)
 expires_module (shared)
 deflate_module (shared)
 headers_module (shared)
 usertrack_module (shared)
 setenvif_module (shared)
 mime_module (shared)
 dav_module (shared)
 status_module (shared)
 autoindex_module (shared)
 info_module (shared)
 dav_fs_module (shared)
 vhost_alias_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 actions_module (shared)
 speling_module (shared)
 userdir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_connect_module (shared)
 cache_module (shared)
 suexec_module (shared)
 disk_cache_module (shared)
 file_cache_module (shared)
 mem_cache_module (shared)
 cgi_module (shared)
 version_module (shared)
 chroot_module (shared)
 perl_module (shared)
 php5_module (shared)
 proxy_ajp_module (shared)
 python_module (shared)
Syntax OK

Print the version and build parameters of httpd, and then exit

Type the command:
# httpd -V
Sample output:

Server version: Apache/2.2.3
Server built:   Oct 28 2008 07:22:45
Server's Module Magic Number: 20051115:3
Server loaded:  APR 1.2.7, APR-Util 1.2.7
Compiled using: APR 1.2.7, APR-Util 1.2.7
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

To view other configuration settings open httpd.conf file (usually located in /etc/httpd directory).Red hat, CentOS and Fedora stores httpd at the following location:
# vi /etc/httpd/conf/httpd.conf
Debian and Ubuntu stores httpd.conf in apache2.conf file at the following location:
# vi /etc/apache2/apache2.conf
FreeBSD stores apache2.2 configuration at the following location:
# vi /usr/local/etc/apache22/httpd.conf
If you made any changes to httpd.conf, check httpd syntax for error using the -t option:
# httpd -t

Rename folder cp via unix command line

To rename a file or folder, enter the following in your terminal:
# cp oldfilename newfilename
# cp oldfoldername/ newfoldername/

Using SSI (Server Side Includes) with domain aliases

I had several domain aliases and wanted to show a different html page based on the domain visited. Since these sites are all very similar, I wanted to share images and other content between them. I also wanted to be able to update the content in only one location. After some research, I determined that SSI could do exactly what I needed.

Add lines to your .htaccess file

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .html .shtml
DirectoryIndex index.shtml index.html index.php

Enter the following in your index.html file

<!–#if expr='”$HTTP_HOST” = “domain1.tld” || “$HTTP_HOST” = “www.domain1.tld”‘–>
<!–#include virtual=”domain1.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain2.tld” || “$HTTP_HOST” = “www.domain2.tld”‘–>
<!–#include virtual=”domain2.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain3.tld” || “$HTTP_HOST” = “www.domain3.tld”‘–>
<!–#include virtual=”domain3.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain4.tld” || “$HTTP_HOST” = “www.domain4.tld”‘–>
<!–#include virtual=”domain4.html” –>
<!–#else–>
<!–#include virtual=”NoneOfThese.html” –>
<!–#endif–>

Explanation of above:

Options +Includes Turn on includes
AddType text/html .shtml Recognize .shtml file extension
AddHandler server-parsed .html .shtml Process both .html and .shtml for SSI
DirectoryIndex index.shtml index.html index.php Display index pages in this order

You can find many resources online that will explain all the features of SSI. Here, I am only looking to say “if the domain visited is X.com or www.X.com, then show X.html”.

Breakdown of SSI index.html

<!–# … –> Process for SSI
<!–#if expr=’ … ‘–> Start ‘If’ evaluation. If … is true, then execute next action
“$HTTP_HOST” String value for current domain name
“$HTTP_HOST” = “domain1.tld” Value of ‘True’ if current domain is domain1.tld
|| ‘Or’ operation. If either is true, then result is true
include virtual=”domain1.html” Insert content from domain1.html
<!–#elif expr=’ … ‘–> If nothing true yet, then continue checking elseif lines
<!–#else–> If noting was true, then execute next line
<!–#endif–> Stop processing this ‘If’ statement

 

DNS Servers

Here is a list of DNS servers that I commonly use:

OpenDNS 208.67.222.222
208.67.220.220
Google 8.8.8.8
8.8.4.4
Comcast 68.87.66.196 (National Primary)
68.87.64.196 (National Secondary)
68.57.32.5 (Virginia)
68.57.32.6 (Virginia)
216.148.227.68 (Denver, Colorado)
204.127.202.4 (Denver, Colorado)
68.42.244.5 (Taylor, Michigan)
68.42.244.6 (Taylor, Michigan)
68.62.160.5 (Huntsville, Alabama)
68.62.160.6 (Huntsville, Alabama)
68.87.96.3 (Pennsylvania)
68.87.96.4 (Pennsylvania)
Earthlink and Mindspring 207.69.188.185
207.69.188.186
207.69.188.187

Joyent (TextDrive) shared server addresses

Here are important addresses for TextDrive (VCII, VCIII, VCIV, Mixed Grill) and Joyent (Accelerator and Golden Ticket upgraded) shared hosting accounts.

Newer accounts (Joyent):

Virtualmin

https://virtualmin.joyent.us/SERVER/

https://virtualmin.joyent.us/SERVER/password-recovery/

Usermin and Webmail

https://usermin.joyent.us/SERVER/

SSH or SFTP

SERVER.joyent.us

phpMyAdmin

https://SERVER.joyent.us/phpmyadmin/

DNS

  • dns1.joyentdns.com
  • dns2.joyentdns.com
  • dns3.joyentdns.com
  • dns4.joyentdns.com

Older accounts (TextDrive):

Webmin

https://webmin.SERVER.textdrive.com/

Usermin

https://usermin.SERVER.textdrive.com/

SSH or SFTP

SERVER.textdrive.com

phpMyAdmin

https://mysql.SERVER.textdrive.com/

Webmail

https://webmail.textdrivehosting.com/

DNS

  • dns1.textdrive.com
  • dns2.textdrive.com
  • dns3.textdrive.com
  • dns4.textdrive.com

Delete folder and contents with rm via unix command line

To delete a folder and it’s contents, enter the following in your terminal
# rm -dfr foldername
Analysis of the above command

-d remove folders
-f remove the files without prompting for confirmation or error messages
-r remove recursively, folder and its contents

More Examples

rm myfile.jpg Remove the file called myfile.jpg in the current directory.
rm *.jpg Remove all files that end with .jpg.

Zip only some files (jpg) via unix command line

To create a new zip archive ‘filename.zip’ including only select files, you can use an expression argument after the command. Enter the following in your terminal to compress all jpg fies in current directory:
# zip filename.zip *.jpg
If you want to only compress mp4 files with ‘720p’ in the filename, enter the following:
# zip filename.zip *720p*.mp4

htaccess 301 (permanent) Redirect and RedirectMatch

There are many different types of redirects. Here are a few different permanent redirects. All of these can be added to your htaccess file. The directories listed are relative to the htaccess location.

Redirect visitors of a single page to a different page.

# Redirect permanent /directory/index.html http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to a specific page.

# RedirectMatch 301 ^/mydirectory/ http://subdomain.domain.tld/AnotherPage.html

Redirect visitors of any page within a directory to that page in a different location. Notice the missing slash here, compared to above.

# RedirectMatch 301 ^/mydirectory http://subdomain.domain.tld/AnotherPage.html

Redirect your entire website to any other domain or directory

# Redirect 301 / http://domain.tld/

301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the “my-example.com” domain:

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://my-example.com/

302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:

# This allows you to redirect your entire website to any other domain
Redirect 302 / http://my-example.com/

Redirect index.html to a specific subfolder:

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/

Redirect an old file to a new file path:

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

Redirect to a specific index page:

# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html