Soil properties, including soil compaction and the nutrient content, influence the composition and functions of rhizosphere microbial communities. There is limited information on how soil compaction and phosphorus application affect phosphate-solubilizing (PSB) and nitrogen-fixing bacteria (NFB). This study aimed to examine the responses of PSB and NFB in the rhizosphere of peanut (Arachis hypogaea L.) plants under varying soil compaction and phosphorus application levels. To address this, pot experiments were conducted to assess the composition and assembly processes of rhizosphere PSB and NFB in peanut cultivar Hua Yu 22 under two soil compaction levels (T1, 1.25 g/cm3 compaction, and T2, 1.00 g/cm3 compaction) and two phosphorus (P) levels (P0, no P applied, and P1, 1.2 mM P/kg soil applied). The results showed that PSB community shifts were closely correlated with the content of soil available phosphorus, soil acid phosphatase activity, soil nitrogenase activity, and soil compaction. Additionally, the content of soil available phosphorus and soil compaction were correlated with changes in operational taxonomic units of NFB. A network analysis revealed that the complexities of PSB were significantly higher than those of NFB. A stronger negative relationship was identified among NFB communities. The assembly of PSB communities was primarily driven by drift processes, whereas NFB communities were influenced by a combination of homogenizing selection and drift. Both PSB and NFB community compositions were significantly affected by phosphorus limitations and soil compaction. These findings enhance our understanding of the impacts of soil compaction and phosphorus application on PSB and NFB communities, with implications for optimizing peanut crop production. Our results will provide reference for crop cultivation in compacted and low-phosphorus soils. The important phosphate-solubilizing and nitrogen-fixing bacteria screened in the interaction network in this study will become candidate microbial agents for alleviating soil compaction and low phosphorus levels.