Hello V,
Placing a php.ini file in the public folder can be a security risk because it might expose sensitive information about your server configuration to the public if it's not properly protected. It's generally not recommended to place configuration files within the publicly accessible directory.
However, if your shared hosting provider's documentation specifically instructs you to place the php.ini file in the public folder, and you have no other option, you should ensure that direct access to the php.ini file is restricted. You can do this by adding a rule in your .htaccess file to deny access to the php.ini file.
Here's how you can do it:
<Files "php.ini">
Order Allow,Deny
Deny from all
</Files>
Add this snippet to your .htaccess file in the public folder. This will prevent external access to the php.ini file while still allowing PHP to read the configuration settings.
Regarding setting the upload_max_filesize directive in .htaccess, this is possible if your server runs PHP as an Apache module. The directive would look something like this:
php_value upload_max_filesize 20M
If you're getting an error when trying to set this in .htaccess, it's possible that your hosting provider does not allow these overrides or PHP is not running as an Apache module. In that case, you would need to use the php.ini method.
Remember to check with your hosting provider's support if you're unsure about the best approach, as they may have specific guidelines or alternative methods for setting PHP directives on their servers.
Always ensure that you're following best practices for security, especially on a shared hosting environment.