Architect, Developer, Web Geek!

April 11, 2014
by daharveyjr


How to Setup the Magento Cron Job

I’ve encountered way too many Magento installations that were never configured to execute the Magento cron job, ultimately causing confusion and problems. This post is meant to be a tutorial to help people enable and setup the cron job to execute as required by Magento, as well as answer some questions as to why the Magento cron job should be enabled.

What Is a Cron Job?

A cron job is an automated event that is triggered by the server. Cron jobs are used to run periodic maintenance or scheduled activities.

What Does Magento Use Its Cron Job For?

By default, the cron job in Magento is used to handle activities that require a script to be run periodically. These activities include, but are not limited to:

  • Catalog Price Rules
  • Sending Newsletters
  • Generating Google Sitemaps
  • Customer Alerts/Notifications
  • Updating Currency Rates
  • Scheduled Log Cleanup

Cron Job Configuration Methods

There are several different ways to configure the Magento cron job to execute, and a quick Google search will show a plethora of different methods. I’ve shown two below that work on the majority of Linux/Unix-based web hosts I have encountered.

Configuration 1. A Magento Cron Job Using WGET

*/15 * * * * wget -q http://www.mydomainname.com/cron.php

Configuration 2. A Magento Cron Job Using Command Line PHP

*/15 * * * * /local/path/to/php -f /local/path/to/magento/cron.php

I generally recommend that most installations setup the Magento cron job to utilize the wget method, due to its simplicity; however, either method works and is generally accepted as correct.

Creating the Cron Job Configuration

You can configure either method above to execute using the crontab or control panel of your favorite web host (i.e. cPanel). The instructions necessary to bring up the crontab and/or edit the crontab through cPanel are shown below.

Method 1. Using Crontab

First, you will need to open the crontab editor, which is used to maintain and edit your cron job entries.

To open the cron tab as the user you are currently logged in as type:

crontab -e

Or, if you wish to open the crontab editor as a specific user, you’ll need to type the following command, replacing username with the specific username you wish to use:

crontab -u username -e

Once the crontab editor is open, you’ll simply type out (or copy and paste) one of commands above, leveraging either the wget or command line PHP method. Save the file and exit to complete your cron job configuration. Note: Each cron job entry needs to occupy its own line within the crontab file. Failure to do so will result in less than desirable results, and a multitude of failures!

Method 2. Using cPanel

Step 1. Under the “Advanced” section of your cPanel control panel, you’ll find the “Cron jobs” item. Click on this to enter the cron job configuration screens.


Step 2. Find the form section named “Add New Cron Job”, and fill out the necessary settings for the Magento cron job.

I recommend the following configuration, which is configured to run every 15 minutes, every day. I see a lot of configurations out there that recommend running the cron job every 5 minutes; however, I’ve found that 15 tends to be a little less resource intensive for those that are running on shared hosting platforms. If you have a dedicated server, feel free to configure it to run every 5 minutes.

  • Minute: */15 (Every 15 minutes)
  • Hour: * (Every hour)
  • Day: * (Every day)
  • Month: * (Every month)
  • Weekday: * (Every weekday)
  • Command: wget -q http://www.mydomainname.com/cron.php

Your screen should look similar to the following when completed:


Step 3. Click “Add New Cron Job” to save the cron job configuration.

NOTE: More information on the jobs that are configured to run in Magento by default can be found on the Magento Wiki, found here).

February 25, 2014
by daharveyjr


MySQL Client Debugging Using the General Query Log

I was recently working on a project at work and needed to do some debugging on a local environment of the queries being executed against a MySQL database from the application I was working on. To accomplish this, I used the MySQL general query log, and wanted to share how to enable and configure the general query log.

For those that don’t know, the general query log is a general record of what MySQL is doing. The server writes information to this log when clients connect and disconnect, and it logs each SQL statement that is received from a connected client. The general query log can be very useful when you suspect an error and want to know exactly what queries that the client is sending to MySQL.

Note: MySQL writes SQL statements to the general query log in the order that it receives them, not necessarily the order in which they are executed.

To view information about the general_log, its location and whether or not its enabled, the following statements can be used:

To view the general query log configuration, issue the following SQL statement:

SHOW VARIABLES LIKE 'general_log%';

To enable the general query log, execute the following SQL statement:

SET GLOBAL general_log = 'ON';

To disable the general query log, execute the following SQL statement:

SET GLOBAL general_log = 'OFF';

Note: The previous statements are used to enable and disable the general query log at runtime, if you wish to enable the general query log upon startup of mysql, you’ll want to use the –log or -l options, as shown below, replacing [file_name] with a file name desired for logging.

mysqld --log=[file_name]

February 5, 2014
by daharveyjr


Enable Shortcodes in WordPress Text Widgets

Have you ever wanted to use a shortcode in a text widget, or have you ever attempted to do so with undesired results? I have, and wanted to re-share a common little code snippet that allows a shortcode from your theme within a text widget!

To enable shortcodes in a text widget on your website add the do_shortcode filter call to the widget_text hook within into your theme’s function.php file, as shown below:

add_filter('widget_text', 'do_shortcode');

Note: The only widget that calls the widget_text hook, is the text widget. This code snippet will not affect any other widgets in your library, only the WordPress Text widget.

February 4, 2014
by daharveyjr

Portfolio Project: Tactile Mom

Tactile Mom (1279x1032)

About the Project

I recently completed work on Tactile Mom, a project started by my wife, Brynn. Tactile Mom describes the experiences, struggles, and highlights of a mother who raises a tactile defensive child. For those that know my family, my son Damian has a condition called tactile defensiveness and this blog is meant to document my wife’s experiences working with our son, Damian.

View Portfolio Page | Visit Tactile Mom

January 31, 2014
by daharveyjr


Transfer Files between Linux Servers Using scp

When transferring a complete website or a group of files from one from server to another, the scp command can be used perform the transfer when working between Linux servers.

The scp command copies files between hosts on a network and uses the ssh protocol for data transfer, as well as the same authentication as the ssh protocol and provides the same security as ssh.

File names may contain a user and host specification to indicate that the file is to be copied to and/or from a specific hosts. Local file names can be made explicit using absolute or relative pathnames.

When copying a source file to a target file which already exists, scp will replace the contents of the target file. If the target file does not yet exist, an empty file with the target file name is created and then filled with the source file contents.

The following options can be very helpful when using scp:

  • r : Recursively copy the files and subdirectories.
  • C : Enables compression for the data transfer activities.
  • p : Preserves file access, modification times, and modes from the original file.

scp Command Examples

To transfer a specific file from a local directory to specific location on a remote server, with compression and preserving file access, modification times, and modes the following command can be used:

scp -Cp /localpath1/to/file.ext user1@server1:/remotepath1/to/file.ext

To transfer all files and subdirectories from a remote server recursively to a local directory, with compression and preserving file access, modification times, and modes the following command can be used:

scp -rCp user1@server1:/remotepath1/to/dir/ /localpath2/to/dir/

To transfer all files and directories from a remote server recursively to another remote server, with compression and preserving file access, modification times, and modes the following command can be used:

scp -rCp user1@server1:/remotepath1/to/dir/ user2@server2:/remotepath2/to/dir/