A gas of linearly polarizable particles transversely pumped by an off-resonant laser and interacting with the counterpropagating radiation modes of a ring cavity is studied. Depending on the pump intensity and the detunings the gas can form a self-organized density grating that enhances the feeding of the cavity. We investigate the system via a mean-field approach and find the thermodynamic phases of i) uniform distribution, ii) self-organized Bragg lattice, iii) lattice with defects, and iv) instability. The occurrence of these phases as a function of the pump intensity and particle density is fully mapped.