Tady, nice writing!
Though good practice is that you don’t change the permissions for a file just because you want to edit it.
Instead of your line sudo chmod 777 php.ini, USE sudo vi php.ini. That way you’ll leave the permission as they were intended to be.
good luck!