What are some best practices for setting file permissions (CHMOD) on directories in PHP?

When setting file permissions (CHMOD) on directories in PHP, it is important to follow best practices to ensure security and proper functionality of your application. One common practice is to set directories to 755, which allows the owner to read, write, and execute, while others can only read and execute. This helps prevent unauthorized users from making changes to the directory.

// Set file permissions on a directory to 755
$dir = '/path/to/directory';
chmod($dir, 0755);