In 1846, he became a professor at Virginia Military Institute, then a recently founded state military college in Lexington, Virginia. During the next five years, he developed VMI's departments of Chemistry and Agriculture, taught infantry tactics and served as the Commandant of Cadets. To lighten the load on Major Gilham, in 1851, VMI hired another professor, Major Thomas Jonathon Jackson, later better known as "Stonewall" Jackson, who was also a graduate of West Point, and a veteran of the conflicts in Florida and Mexico. As a professor, Gilham was interested in geological matters. In 1857, his Report on the Soil of Powhatan County, Virginia was published in Richmond by Ritchie & Dunnavant. A copy of a request he made to the same year for the legislature to fund acquisition of "a complete collection of minerals and fossils for the use of my classes" is in the collection of the Virginia Historical Society in Richmond. Majors Gilham and Jackson taught together at VMI for the rest of the decade. In November 1859, at the request of the Virginia Governor Henry A. Wise, Major Gilham led a contingent of the VMI Cadets Corps to Charles Town to provide an additional military presence for at the execution by hanging on December 2, 1859 of militant abolitionistJohn Brown following his raid on the federal arsenal at Harper's Ferry. Major Jackson was placed in command of the artillery, consisting of two howitzers manned by 21 cadets. In response to the raid on Harper's Ferry, Governor Wise ordered Gilham to write a manual to train volunteers and militia. Finished in the fall of 1860, it was entitled Manual of Instruction for the Volunteers and Militia of the United States and was initially published in Philadelphia.
Family life
According to VMI records, while residing in Lexington, Major Gilham and his wife Cordelia Adelaide Hayden Gilham had 7 children, 3 born after moving to Virginia. Their daughter Emma Hayden Gilham married William Nelson Page, a civil engineer who became co-founder of the Virginian Railway.
In 1861, as the American Civil War broke out, the Confederate Army had a lot of new recruits. Promoted to the rank of colonel, Gilham became the Commandant of Camp Lee, at Richmond, Virginia, the camp of instruction for thousands of Virginians. Gilham's manual proved to be the ideal book for the training of these young men. Col. Gilham briefly commanded a brigade in the field in 1861 and 1862, but returned to teaching at VMI. On May 15, 1864, the VMI cadets participated in the Battle of New Market. Gilham was present, but did not command the young troops during the battle. After Union troops led by Union General David Hunter raided Lexington, and burned buildings at VMI, the VMI cadets were stationed at Richmond for the remainder of the War. Major Gilham's house, a campus landmark, was later rebuilt to original specifications after the War.
Post-war
After the War, VMI had no money to pay its instructors. Gilham went to work in Richmond for Southern Fertilizer Company, which occupied the former Confederate Libby Prison facility near Richmond's Tobacco Row. One of the company's products, Gilham's Tobacco Fertilizer, was manufactured there. William Gilham died in Vermont on November 16, 1872, aged 54, of undisclosed causes. He was interred at Lexington, Virginia's Stonewall Jackson Memorial Cemetery.