In this work, we present an exact interior solution to a physically acceptable Einstein–Maxwell equation system, assuming a static and spherically symmetric spacetime with a distribution of matter from a perfect charged fluid to represent a generalization of a model for a perfect chargeless fluid. The charge parameter modifies the mass function, its compactness rate and the comportment of the speed of sound. The behavior analysis of the functions of density, pressure and charge shows that the solution is applicable for the description of relativistic compact stars. In particular, we analyze the behavior of these functions for the values of observed mass M∈[0.95,1.13]M⊙M∈[0.95,1.13]M⊙ and the theoretical radius interval estimated previously R∈[8.101,8.501]km from the star LMC X-4. Thus, the biggest charge value of maximum charge Q=1.73×1020C occurs for the maximum compactness u=0.2059.