Ancient Egyptians and Mesopotamians came up with “administrative” calendars of 30 days, that were easier to calculate than “real” lunar months of sometimes 29, sometimes 30 days. At the end of the 12 months, they added five days of religious observances, sometimes positive, sometimes negative.
When Julius Caesar conquered Egypt, he knew about the very regular Egyptian calendar and appointed his mathematicians and astronomers (if we can really call them that, as Roman science wasn’t very developed) to discuss with their Egyptian peers and devise a better calendar for the Roman Republic (reminder that Caesar was not the Emperor; the first one was Augustus, his [adoptive] son, and not right away).
Eventually, it was decided in Rome that, in order to follow with the seasons, the already-existing Republican Roman calendar was to be modified. It contained 10 months of 29 and 30 days plus a “winter” of 59 days, which became divided in January and February. As Julius Caesar was the one who brought this change, he was “honored” by having a month renamed from Quintilis (“Fifth”) to Julius (our July)—and that month was given 31 days, as well as a few others. Also, the beginning of the year was shifted (at this point or later; it’s not clear) to January, making the “numbered months” off with their new rank—e.g. “October” is not eighth (“octo”) anymore.
Caesar’s reform was not well applied, and eventually, Augustus had to enforce the new calendar, and he was also “honored” with a 31-day month, right after Julius’, so that’s how Sextilis (“Sixth”; and it had 30 days) became Augustus (with 31 days).
The rest is basically adjusting here and there to make it a total of 365 days at the end of the year, someone sometime having the “brilliant” idea of alternating 30- and 31-day months (a little like nature “alternates” between 29- and 30-day lunar months).
Side note… In some languages, the word for Moon and the word for month is the same—it’s already quite similar in English! For example, Romanian has “Luna” for both, and Korean has ”dal.”