I have installed magento 2 in my ubuntu and I tried to run magento setup, it print the index.php code.
There are 3 possibilities:
1. You don't have PHP installed. In that case run:
sudo apt-get install php php-mysql
2. You have PHP installed but not enabled. You can try running:
sudo a2enmod php7 sudo service apache2 restart
3. You have PHP installed and enabled but you haven't restarted apache.
sudo service apache2 restart
if you have above answer, depending on which magento 2 version you are trying to install.
for e.g. if you are going with > 2.3 you must be needing php
if that's not the case with you, then coming towards your 500 error. which usually means something is not right with the code. the possible url might not exist.