I run Apache 2 Magento 2.4.2.p1, and I've installed magento properly, even added a theme without any problems. However, suddenly, I ran into a permission issue when editing my theme's configuration. I googled for solutions, found out that when you import themes through ftp, the permissions have to be set for those new files and ran the commands:
253 sudo find var generated vendor pub/static pub/media app/etc -type f -exec chmod u+w {} + 254 && sudo find var generated vendor pub/static pub/media app/etc -type d -exec chmod u+w {} +
chown -R magento:www-data .
This seems to work as my user "magento" is back to being the owner of the directories and files, however, when I went to my website, it would output a "Error 500" that was not present before running the commands. I searched for a solution to this new problem and found out that you had to run bin/magento setup:upgrade. But, for whatever reason, something is reverting the ownership of the files that are being generated such as the cache to the "root" server user.
TL;DR: magento doesn't have permissions to read files that were imported via ftp --> I try to give it ownership of the files --> get error 500 --> run setup:upgrade to try and fix error 500 --> > files' ownership is set back to the root server user -- error 500 stays
Try to remove the .htaccess file from the Magento root and then try to load the website from your browser.
After that, if it does not give 500 Internal server errors after removing the .htaccess file, then it should be PHP version issues or any server configuration is missing.
To check the PHP version you can use this command.
php -v
Thank you.