The 500 Internal Server Error is expected with those snippets.
The second one cannot be used in a .htaccess file because DirectoryMatch and AllowOverride are only valid in the Apache server or VirtualHost configuration. Apache will therefore return a 500 error.
The first snippet also shouldn't be added to Joomla's root .htaccess, as it would block the execution of all PHP files, including index.php, effectively breaking both the frontend and backend.
If your goal is to prevent PHP execution in writable directories (images, media, tmp, cache, etc.), the rules must be applied only to those directories, or configured centrally in the Apache configuration.
For an easier setup, you could use Admin Tools Pro's .htaccess Maker or my free HTProtect extension. Both deploy the appropriate protection rules with just one or two clicks, eliminating the need to edit .htaccess files manually or risk breaking your site.