@Gabriel ...
From the 'clues shared' ... ~/public_html/... it appears it's Linux and on a shared system. Thus some php commands might be in a 'jail' or behind some other php protections on the server so that customers who share the machine can't harm/do stuff to other customers sites/databases.
The script reads the config.php file of the site for the DB host, the DB name, and the DB user. That DB user in config.php might not have access rights enough to change configuration of tables. The fact you get an error 500 from Apache means the apache server is called (it's not supposed to be ... just php talking to the DB host) and not allowing command line php.
You can test this a little further ... the following commands do work on a NON-shared server and as root user (in your case, the DB user seen in the config.php file of your site). I actually expect they will fail on your system.
mysql -u [DBusernamefoundinMdlConfig] -p[DBPasswordfoundinMdlConfig]
Do you get a mysql> prompt?
If so, at that mysql> prompt type: show databases;
Be sure to include the ';' at the end.
See your DB name as it is in config.php of your site?
At the mysql> prompt type:
mysql> show grants for '[yourDBuser]'@'[yourDBhost]';
Include the single quotes as in the command above but substitute your info and replace the []'d items - including the ['s.
Does your shared system provide any control panel for customer use that can interact with DB's (not phpmyadmin)?
Remotely hosted shared systems normally have a client/customer FAQ of some sort. You might need to seek that out or even contact your providers helpdesk to inquire.
As far as documenting this for all possible providers, that's pretty much 'mission impossible', am afraid. But, that's what community sharing is about ... folks who run on Bluehost, GoDaddy, etc. come back to these forums and share back what they had to do to get xyz to work for others who might follow.
'spirit of sharing', Ken