How to install Forge to a existing vanilla server?

If you want to install forge, then I'm assuming it is so you can install one or more mods.From a technical perspective, there are a ton of things that can go wrong. What you are asking seems simple enough from a user perspective but is super complex under the hood.

This is a bad idea. Mods change block/dimension/item IDs and will very likely corrupt your world. If you try this, make backups before starting. Below are instructions to test the mods to see if they will corrupt stuff by changing IDs. This test is not perfect, but will get most cases.

  1. Backup your entire vanilla server Really really dont skip this. Don't backup just the world folder, backup the whole server folder.
  2. Download the version of forge that matches your existing server's Minecraft version
  3. Setup forge in a NEW folder (not covered here there are many tutorials online)
  4. Start up your forge server and log in to it to verify it works (and generate a default world) - Go to the end and nether to generate them.
  5. Log out and shutdown forge server
  6. Add any mods (this is the only time you should add mods... choose carefully the more you add, the more risk that this will fail)
  7. Start up your forge server and log in. Try out blocks from the mods, go to their dimensions, etc... test the mods, and visit all vanilla places that you went to previously. In particular travel and look for chunk generation errors between chunks generated in step 4, and new chunks.
  8. If the world is corrupted, then the one of the mods you added will broke the forge world. If a forge world can't survive this, then there is no way that your vanilla world will... stop here, what you are wanting to do won't work.
  9. If the world seems ok, then proceed
  10. Log out and shutdown forge server
  11. On the Forge server Copy(NOT MOVE, NOT RENAME) the world folder to world.forge
  12. Copy(NOT MOVE) the world folder from your vanilla server to your forge server directory. This will collide with the existing world folder in the forge server directory, and you should tell it to overwrite existing files. Overwriting is necessary because many mods write additional files into the world folder, and your vanilla world won't have them. Sometimes the mods will regenerate them, sometimes not. (remember when I said this was a bad idea? this is why. This is messing with the internals of a database. You are effectively changing its schema after it has data in it...)
  13. Startup your forge server and test the same ways you did in step 7.
  14. If it is corrupted, you can also try to delete the world folder in the forge server directory and then copy. This will work if the mod devs for your mods took steps to make them resilient to data issues.

Whether or not this works is highly dependent on the version of minecraft that your vanilla world starts at, the version of forge that you pick, what mods you select, what they do to the world and your IT skills.