A phase-only spatial light modulator (SLM) is a device that is commonly used in various optical applications. Generally, SLM offers great advantages such as low power consumption and compact design. However, due to the manufacturing process, the main drawbacks of the SLM are surface non-uniformity and cross-talk between adjacent pixels, which add undesirable phase modulation. As a result, the SLM's functionality is impacted, leading to image quality degradation, in terms of the signal-to-noise ratio (SNR), of optical reconstruction in holographic projection, for instance. Therefore, the aim of the current study is to measure and compensate for the surface non-uniformities of the SLM and improve its phase modulation. To achieve this, Shack-Hartmann wavefront sensor (SHWFS) is utilized. At first, a flat constant phase pattern is displayed on the SLM, and its surface phase shape is measured using a plane wave illumination. The reflected wavefront from the SLM is measured using SHWFS and then its phase information has been calculated. Hence, the calculated phase values are converted into a phase-only computer-generated hologram (CGH). The calculated CGH is displayed on the phase-only SLM to compensate for the phase errors of the SLM. The reflected wavefront has been measured after displaying the CGH to evaluate the compensation process. The experimental results reveal that the SHWFS provides high accuracy in the measurement of the phase distortion introduced by the surface of SLM. The SHWFS method is simple, robust, offers real-time performance, and is vibration-insensitive when compared with interferometric approaches.