To reach the altar, you have to go through the Vast Poni Canyon and battle your way through the trainers there.
Vast Poni Canyon
Go north, and Hapu asks you to battle her. You can ask to prepare first.
Island Kahuna Hapu has a level 47 Dugtrio, a level 48 Mudsdale, a level 47 Flygon, and a level 47 Gastrodon. You get 7680 Pokédollars for winning.
Afterward, you get Groundium Z and a new stamp in your Trainer Passport, which causes all pokémon up to level 80 to obey you.
Before you talk to Lillie, go to the left and check under the branch to the left of her, and you will crawl through. Get the Max Potion that you find there.
Now go back and talk to Lillie. She gives you a Max Revive. She heals up your pokémon.
Then go into the cave.
To the right, you must battle Veteran Harry. He has a level 46 Torkoal and a level 46 Arcanine. You get 4048 Pokédollars for winning.
Go east and you can battle Backpacker Perdy. She has a level 44 Whimsicott. You get 1056 Pokédollars for winning.
Break through the rocks to the left of the Backpacker and check on the hole to go through. There is an Elixir there.
Go to the left and jump down the ledge, then go south up the ramp. Near the top of the ramp, there is a hidden Nugget.
To the right, break through the boulders to get the Max Potion.
To the left, you can battle Ace Duo Kent and Aimee (or you can break the boulders south of them if you would rather avoid them). They have a level 46 Alolan Ninetales and a level 46 Alolan Sandslash. You get 6256 Pokédollars for winning.
Go west from the Ace Trainers and break the boulder in the path, then go south to go outside.
Go southeast through the grass to find a Revive.
Then follow the path west to reach another cave area.
Near the entrance of this cave area, there is a green sparkle for the Zygarde Cube.
To the left, if you ride over the rocks with Mudsdale, you can avoid a battle up ahead.
To the left you can battle Hiker Zachary. He has a level 44 Archeops and a level 44 Rampardos. You get 1408 Pokédollars for winning.
Go to the left of the Hiker, then go south to exit the cave.
Go to the right and crawl into the hole. To the right, you can battle Veteran Lynn. She has a level 46 Starmie, a level 46 Shiinotic, and a level 46 Talonflame. You get 4048 Pokédollars for winning.
North of the Veteran, there is an Escape Rope.
Southeast of the rocky ground, you can battle Ace Trainer Junko. She has a level 45 Lilligant and a level 46 Weavile. You get 3128 Pokédollars for winning.
Check on the hole south of the Ace Trainer to go outside. You find TM99 Dazzling Gleam.
There is a hidden X Sp. Atk on the right side of the rock to the right.
Now go back the way you came and approach the bridge on the left. After a cut scene, Lillie wll heal your pokemon. Afterward, you can go back onto the bridge to find a Poké Finder spot.
Go north into the cave next to Lillie.
Go down the ramp to the left. There is a green sparkle between some pokémon dens.
Go down the ramp to the right. Go up above the rock and have Machamp push it all the way down until it falls into a hole. There is a Full Restore to the left.
Go down and have Machamp push the rock to the right.
Go southeast to exit the cave. There is a Dusk Ball there.
Go west through the grass to find a green sparkle.
Go back into the cave. Then go up and have Machamp push this rock up. There is a ladder to the right. Check on it to climb up. In this area, you can battle Scientist Ikaika. He has a level 43 Alolan Muk and a level 44 Magnezone. You get 2112 Pokédollars for winning.
Go east to exit the cave. To the right, you can battle Punk Girl Anna. She has a level 44 Alolan Persian, and a level 46 Honchkrow. You get 1408 Pokédollars for winning.
Go east across the bridge. You will get Fairium Z.
On the right side of the bridge, you can battle Punk Guy Adam. He has a level 44 Pangoro. You get 1408 Pokédollars for winning.
Go east across the bridge. There is a hidden PP Max to the right of the bridge.
Go down along the tree branch to reach a grassy area. Go up from there, then go west down the slope. You can go south into the cave and push the boulder to the right to create a shortcut to the exit.
There is a green sparkle near where the boulder was.
Go north to return to the previous area. Go east up the slope. Go southeast past the tree branch. You can go through the grass, or you can go to the left up a slope and jump down a ledge to go southwest and get a Full Heal.
East of the Full Heal, you can battle Black Belt Earl. He has a level 46 Poliwrath. You get 1472 Pokédollars for winning.
Now go northwest, and go west down the slope.
Before you go north to battle the Ace Trainer, check on the branches southwest of him to enter a new area. Go northwest past the grass to enter a cave.
Go north in the water and you can battle Black Belt Terry. He has a level 46 Machamp. You get 1472 Pokédollars for winning.
Go west from there and you will find a Rare Candy.
Go south from there to find TM35 Flamethrower.
Go back the way you came until you see the Ace Trainer to the north. Go north and you have to battle Ace Trainer Hiroshi. He has a level 47 Absol and a level 47 Lapras. You get 3196 Pokédollars for winning.
Go north and you have to battle Veteran Heather. She has a level 47 Stoutland, a level 47 Klefki, and a level 47 Tsareena. You get 4136 Pokédollars for winning.
Go north and you have to battle Veteran Eric. He has a level 47 Granbull, a level 47 Alolan Golem, a level 47 Cloyster, and a level 47 Gengar. You get 4136 Pokédollars for winning.
Go north and Lillie will heal your pokémon.
Go north to enter the cave. You will be asked if you are ready for the trial. You can say No if you want to prepare first.
Go north and you will feel a piercing gaze. Go farther northeast and you must battle a level 40 Jangmo-o.
Afterward, you feel another gaze. Go to the right and enter the small cave to get TM02 Dragon Claw.
Leave the cave and go northwest toward a small rock on the left. You will have to battle a level 40 Hakamo-o.
After that, you feel another gaze. Go north to the pedestal and take the Z-Crystal.
You will have to battle a level 45 Totem Kommo-o. He can call Hakamo-o into battle.
After the battle, you get Dragonium Z.
Go north to reach the Altar of the Sunne/Moone. Lillie will heal your pokémon.
After that, go up the stairs to reach the top.
After a cut scene, go to the side, then up, to stand on the proper spot. When asked if you will blow the flute, say yes.
After the cut scene, go north. After another cut scene, go north again.
Next, you must battle Aether President Lusamine. All of her pokémon have a boosted stat, like a Totem Pokémon. She has a level 50 Clefable, a level 50 Bewear, a level 50 Lilligant, a level 50 Milotic, and a level 50 Mismagius.
After the battle and the cut scene that follows, you will be back at the Altar of the Sunne/Moone. Talk to the Legendary Pokémon to battle and try to catch it. You might NOT want to use your Master Ball, because this pokémon is not that hard to catch, as long as you lower its HP and give it a status condition.
After you catch it, there will be a cut scene.
After that, you can choose to go with Nanu to Mount Lanakila or not. Either way, Mount Lanakila (north of Tapu Village) is where you should go when you are ready to continue.