Joint device-to-device (D2D) and cellular communication is a promising technology for enhancing the spectral efficiency of future wireless networks. However, the interference management problem is challenging since the operating devices and the cellular users share the same spectrum. The emerging reconfigurable intelligent surfaces (RIS) technology is a potentially ideal solution for this interference problem since RISs can shape the wireless channel in desired ways. This paper considers an RIS-aided joint D2D and cellular communication system where the RIS is exploited to cancel interference to the D2D links and maximize the minimum signal-to-interference plus noise (SINR) of the device pairs and cellular users. First, we adopt a popular alternating optimization (AO) approach to solve the minimum SINR maximization problem. Then, we propose an interference cancellation (IC)-based approach whose complexity is much lower than that of the AO algorithm. We derive a representation for the RIS phase shift vector which cancels the interference to the D2D links. Based on this representation, the RIS phase shift optimization problem is transformed into an effective D2D channel optimization. We show that the AO approach can converge faster and can even give better performance when it is initialized by the proposed IC solution. We also show that for the case of a single D2D pair, the proposed IC approach can be implemented with limited feedback from the single receive device.