Are there any best practices for setting folder permissions in PHP to avoid permission denied errors?

When setting folder permissions in PHP, it is important to ensure that the web server has the necessary permissions to read, write, and execute files within the folder. To avoid permission denied errors, it is recommended to set the folder permissions to 755, which allows the owner to read, write, and execute files, and others to only read and execute files.

// Set folder permissions to 755
$folder = '/path/to/folder';
chmod($folder, 0755);